1use crate::{IDENTITY_PATH, K8S_SA_TOKENFILE_PATH, LOCAL_CA_CERT_PATH};
2
3#[derive(thiserror::Error, Debug)]
5#[non_exhaustive]
6pub enum Error {
7 #[error("private key gen error")]
9 PrivateKeyGen,
10
11 #[error("Authly CA does not exist at {LOCAL_CA_CERT_PATH}")]
13 AuthlyCAmissingInEtc,
14
15 #[error("Authly CA error: {0}")]
17 AuthlyCA(&'static str),
18
19 #[error("identity error: {0}")]
21 Identity(&'static str),
22
23 #[error("tls problem: {0}")]
25 Tls(&'static str),
26
27 #[error(
29 "environment not inferrable: Neither {IDENTITY_PATH} or {K8S_SA_TOKENFILE_PATH} exists"
30 )]
31 EnvironmentNotInferrable,
32
33 #[error("invalid X509 alt names")]
35 InvalidAltNames,
36
37 #[error("unauthorized: {0}")]
39 Unauthorized(anyhow::Error),
40
41 #[error("network error: {0}")]
43 Network(anyhow::Error),
44
45 #[error("invalid access token: {0}")]
47 InvalidAccessToken(anyhow::Error),
48
49 #[error("encoding error: {0}")]
51 Codec(anyhow::Error),
52
53 #[error("invalid namespace/property/attribute label")]
55 InvalidPropertyAttributeLabel,
56
57 #[error("access denied")]
59 AccessDenied,
60
61 #[error("unclassified error: {0}")]
63 Unclassified(anyhow::Error),
64}
65
66pub(crate) fn unclassified(err: impl std::error::Error + Send + Sync + 'static) -> Error {
67 Error::Unclassified(anyhow::Error::from(err))
68}
69
70pub(crate) fn tonic(err: tonic::Status) -> Error {
71 match err.code() {
72 tonic::Code::Unauthenticated => Error::Unauthorized(err.into()),
73 tonic::Code::PermissionDenied => Error::Unauthorized(err.into()),
74 _ => Error::Network(err.into()),
75 }
76}
77
78pub(crate) fn network(err: impl std::error::Error + Send + Sync + 'static) -> Error {
79 Error::Unauthorized(anyhow::Error::from(err))
80}
81
82pub(crate) fn unauthorized(err: impl std::error::Error + Send + Sync + 'static) -> Error {
83 Error::Unauthorized(anyhow::Error::from(err))
84}