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
use aws_credential_types::provider::error::CredentialsError;
use aws_sdk_sts::operation::get_caller_identity::GetCallerIdentityError;
use aws_sdk_sts::operation::get_session_token::GetSessionTokenError;
use aws_smithy_runtime_api::client::orchestrator::HttpResponse;
use aws_smithy_runtime_api::client::result::SdkError;
use std::env::VarError;
use std::io;
use std::num::ParseIntError;
use thiserror::Error;
use time::error::ComponentRange;

#[derive(Error, Debug)]
pub enum Error {
    #[error("failed to get caller identity")]
    GetCallerIdentityError(#[source] SdkError<GetCallerIdentityError, HttpResponse>),

    #[error("failed to get session token")]
    GetSessionTokenError(#[source] SdkError<GetSessionTokenError, HttpResponse>),

    #[error("failed to provide credentials")]
    ProvideCredentialsError(#[source] CredentialsError),

    #[error("could not read credentials file `{path:?}`")]
    ReadCredentialsFileError { path: String, source: io::Error },

    #[error("could not write in credentials file `{path:?}`")]
    WriteCredentialsFileError { path: String, source: io::Error },

    #[error("failed to get environment variable `{var:?}`")]
    GetEnvVariableError { var: String, source: VarError },

    #[error("missing field `{0}` in session token")]
    InvalidSession(String),

    #[error("missing field `{0}` in session credentials")]
    InvalidCredentials(String),

    #[error("missing field `{0}` in caller identity")]
    InvalidIdentity(String),

    #[error("failed to parse session timestamp")]
    ParseSessionTimestampError(#[source] ParseIntError),

    #[error("failed to convert session timestamp to datetime")]
    ConvertSessionTimestampError(#[source] ComponentRange),

    #[error(transparent)]
    Other(#[from] anyhow::Error),
}