wasmcloud_secrets_types/
errors.rs

1use bytes::Bytes;
2use serde::{Deserialize, Serialize};
3use thiserror::Error;
4
5use crate::SecretResponse;
6
7#[derive(Error, Debug, Serialize, Deserialize)]
8pub enum ContextValidationError {
9    #[error("Invalid Component JWT: {0}")]
10    InvalidComponentJWT(String),
11    #[error("Invalid Provider JWT: {0}")]
12    InvalidProviderJWT(String),
13    #[error("Invalid Host JWT: {0}")]
14    InvalidHostJWT(String),
15}
16
17#[derive(Error, Debug, Serialize, Deserialize)]
18pub enum GetSecretError {
19    #[error("Invalid Entity JWT: {0}")]
20    InvalidEntityJWT(String),
21    #[error("Invalid Host JWT: {0}")]
22    InvalidHostJWT(String),
23    #[error("Secret not found")]
24    SecretNotFound,
25    #[error("Invalid XKey")]
26    InvalidXKey,
27    #[error("Error encrypting secret")]
28    EncryptionError,
29    #[error("Error decrypting secret")]
30    DecryptionError,
31    #[error("Error fetching secret: {0}")]
32    UpstreamError(String),
33    #[error("Error fetching secret: unauthorized")]
34    Unauthorized,
35    #[error("Invalid request")]
36    InvalidRequest,
37    #[error("Invalid payload")]
38    InvalidPayload,
39    #[error("Invalid headers")]
40    InvalidHeaders,
41    #[error("Error processing policies: ${0}")]
42    PolicyError(String),
43    #[error("Encountered an unknown error fetching secret: {0}")]
44    Other(String),
45}
46
47impl From<GetSecretError> for SecretResponse {
48    fn from(e: GetSecretError) -> Self {
49        SecretResponse {
50            error: Some(e),
51            ..Default::default()
52        }
53    }
54}
55
56impl From<SecretResponse> for Bytes {
57    fn from(resp: SecretResponse) -> Self {
58        let encoded = serde_json::to_vec(&resp).unwrap();
59        Bytes::from(encoded)
60    }
61}