use reqwest;
use serde_json;
use std::env;
use std::io;
use std::path::PathBuf;
use std::result;
pub type Result<T> = result::Result<T, Error>;
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[non_exhaustive]
#[error("can't access secure credential '{name}': {cause}")]
Credential {
name: String,
cause: Box<Error>,
},
#[non_exhaustive]
#[error("problem reading file {}: {cause}", path.display())]
FileRead {
path: PathBuf,
cause: Box<Error>,
},
#[non_exhaustive]
#[error("invalid URL {url:?}")]
InvalidUrl {
url: String,
},
#[non_exhaustive]
#[error("I/O error: {0}")]
Io(#[source] io::Error),
#[non_exhaustive]
#[error("could not parse JSON: {0}")]
Json(#[source] serde_json::Error),
#[non_exhaustive]
#[error("no entry for '{name}' in Secretfile")]
MissingEntry {
name: String,
},
#[non_exhaustive]
#[error("the path '{path}' is missing a ':key' component")]
MissingKeyInPath {
path: String,
},
#[non_exhaustive]
#[error("the secret '{secret}' does not have a value for the key '{key}'")]
MissingKeyInSecret {
secret: String,
key: String,
},
#[error("VAULT_ADDR not specified")]
MissingVaultAddr,
#[error("cannot get VAULT_TOKEN, Kubernetes Vault token or ~/.vault_token: {0}")]
MissingVaultToken(Box<Error>),
#[error("no credentials backend available")]
NoBackend,
#[error("can't find home directory")]
NoHomeDirectory,
#[error("path '{path:?}' cannot be represented as Unicode")]
#[non_exhaustive]
NonUnicodePath {
path: PathBuf,
},
#[error("could not parse {input:?}")]
#[non_exhaustive]
Parse {
input: String,
},
#[error("{0}")]
Other(Box<dyn std::error::Error + Send + Sync + 'static>),
#[non_exhaustive]
#[error("can't read Secretfile: {0}")]
Secretfile(Box<Error>),
#[non_exhaustive]
#[error("undefined environment variable {name:?}: {cause}")]
UndefinedEnvironmentVariable {
name: String,
#[source]
cause: env::VarError,
},
#[non_exhaustive]
#[error("unexpected HTTP status: {status} ({body})")]
UnexpectedHttpStatus {
status: reqwest::StatusCode,
body: String,
},
#[error("could not parse URL: {0}")]
UnparseableUrl(#[source] reqwest::UrlError),
#[non_exhaustive]
#[error("could not access URL '{url}': {cause}")]
Url {
url: reqwest::Url,
cause: Box<Error>,
},
#[doc(hidden)]
#[error("this error should never occur (nonexclusive)")]
__Nonexclusive,
}
impl From<io::Error> for Error {
fn from(err: io::Error) -> Self {
Error::Io(err)
}
}
impl From<serde_json::Error> for Error {
fn from(err: serde_json::Error) -> Self {
Error::Json(err)
}
}
impl From<reqwest::UrlError> for Error {
fn from(err: reqwest::UrlError) -> Self {
Error::UnparseableUrl(err)
}
}