support_kit/
errors.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
use std::{io::Error, net::AddrParseError};
use thiserror::Error;

/// The auth token failed to verify.
#[derive(thiserror::Error, Debug)]
#[error("Token verification failed: {0}")]
pub struct AuthTokenVerificationFailure(#[from] jsonwebtoken::errors::Error);

/// We couldn't make an auth token.
#[derive(thiserror::Error, Debug)]
#[error("Unable to generate auth token: {0}")]
pub struct AuthTokenGenerationFailure(#[from] jsonwebtoken::errors::Error);

/// Something went wrong with our session token.
#[derive(thiserror::Error, Debug)]
#[error(transparent)]
pub enum TokenError {
    /// An ID parse error means the ID in the token is not a valid uuid.
    InvalidUuid(#[from] uuid::Error),
    /// We couldn't verify the token.
    VerificationFailed(#[from] AuthTokenVerificationFailure),
    /// We couldn't make the token.
    TokenGenerationFailure(#[from] AuthTokenGenerationFailure),
}

#[derive(Debug, thiserror::Error)]
pub enum PasswordError {
    #[error("Failed to hash password: {0}")]
    HashError(argon2::password_hash::Error),
}

impl From<argon2::password_hash::Error> for PasswordError {
    fn from(err: argon2::password_hash::Error) -> Self {
        PasswordError::HashError(err)
    }
}

#[derive(Debug, thiserror::Error)]
pub enum BoilerplateError {
    #[error("problem with template: {0}")]
    TemplateError(#[from] minijinja::Error),
    #[error("template persistence error: {0}")]
    IoError(#[from] std::io::Error),
}

#[derive(Debug, thiserror::Error)]
pub enum ShellCommandError {
    #[error("unable to execute command: {0}")]
    ExecError(#[from] std::io::Error),
    #[error("malformed command, unable to parse: {0}")]
    MalformedError(String),
}

#[derive(Debug, thiserror::Error)]
#[error("network init error: {0}")]
pub struct NetworkInitError(#[from] AddrParseError);

#[derive(Debug, thiserror::Error)]
#[error("invalid service label: {0}")]
pub struct InvalidServiceLabelError(#[from] std::io::Error);

#[derive(Debug, thiserror::Error)]
pub enum ServiceControlError {
    #[error("Failed to initialize service control")]
    InitializationError(#[from] Error),

    #[error("invalid service label: {0}")]
    InvalidServiceLabelError(#[from] InvalidServiceLabelError),
}

#[derive(Debug, thiserror::Error)]
pub enum SshError {
    #[error("connection error: {0}")]
    SshError(#[from] russh::Error),

    #[error("key error: {0}")]
    SshKeyError(#[from] russh::keys::Error),

    #[error("channel write error: {0}")]
    SshIoError(#[from] std::io::Error),

    #[error("authentication failed")]
    AuthenticationFailed,
    #[error("invalid path: {0}")]
    InvalidPath(String),
}

#[derive(Debug, thiserror::Error)]
pub enum MissingDirError {
    #[error("missing home directory")]
    HomeDir,
    #[error("missing config directory")]
    ConfigDir,
}

#[derive(Debug, Error)]
pub enum SupportKitError {
    #[error("service control error: {0}")]
    ServiceControlError(#[from] ServiceControlError),

    #[error("problem finding directory: {0}")]
    MissingDirError(#[from] MissingDirError),

    #[error("problem building config: {0}")]
    ConfigBuildError(#[from] figment::Error),

    #[error("problem initializing network: {0}")]
    NetworkInitError(#[from] NetworkInitError),

    #[error("ssh error: {0}")]
    SshError(#[from] SshError),

    #[error("serde error: {0}")]
    SerdeError(#[from] serde_json::Error),

    #[error("ops process error: {0}")]
    OpsProcessError(#[from] ShellCommandError),

    #[error("boilerplate error: {0}")]
    BoilerplateError(#[from] BoilerplateError),

    #[error("token error: {0}")]
    TokenError(#[from] TokenError),

    #[error("password error: {0}")]
    PasswordError(#[from] PasswordError),
}