2022-03-26 09:42:19 +00:00
use serde ::{ Deserialize , Serialize } ;
2020-07-07 22:45:32 +00:00
use std ::collections ::HashMap ;
2019-11-02 11:08:54 +00:00
2022-03-26 09:42:19 +00:00
#[ derive(Clone, Deserialize, Serialize) ]
2022-09-09 12:59:38 +00:00
#[ cfg_attr(
feature = " config-schema " ,
derive ( schemars ::JsonSchema ) ,
schemars ( deny_unknown_fields )
) ]
2022-03-26 09:42:19 +00:00
#[ serde(default) ]
2022-04-01 15:14:05 +00:00
/// ## AWS
///
2022-06-12 11:27:19 +00:00
/// The `aws` module shows the current AWS region and profile and an expiration timer when using temporary credentials.
/// The output of the module uses the `AWS_REGION`, `AWS_DEFAULT_REGION`, and `AWS_PROFILE` env vars and the `~/.aws/config` and `~/.aws/credentials` files as required.
2022-04-01 15:14:05 +00:00
///
2022-06-12 11:27:19 +00:00
/// The module will display a profile only if its credentials are present in `~/.aws/credentials` or if a `credential_process` or `sso_start_url` are defined in `~/.aws/config`. Alternatively, having any of the `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, or `AWS_SESSION_TOKEN` env vars defined will also suffice.
/// If the option `force_display` is set to `true`, all available information will be displayed even if no credentials per the conditions above are detected.
2022-04-01 15:14:05 +00:00
///
/// When using [aws-vault](https://github.com/99designs/aws-vault) the profile
/// is read from the `AWS_VAULT` env var and the credentials expiration date
2023-03-20 20:56:12 +00:00
/// is read from the `AWS_SESSION_EXPIRATION` or `AWS_CREDENTIAL_EXPIRATION`
/// var.
2022-04-01 15:14:05 +00:00
///
/// When using [awsu](https://github.com/kreuzwerker/awsu) the profile
/// is read from the `AWSU_PROFILE` env var.
///
2022-11-05 11:40:46 +00:00
/// When using [`AWSume`](https://awsu.me) the profile
2022-04-01 15:14:05 +00:00
/// is read from the `AWSUME_PROFILE` env var and the credentials expiration
/// date is read from the `AWSUME_EXPIRATION` env var.
2019-10-04 12:42:33 +00:00
pub struct AwsConfig < ' a > {
2022-04-01 15:14:05 +00:00
/// The format for the module.
2020-07-07 22:45:32 +00:00
pub format : & ' a str ,
2022-04-01 15:14:05 +00:00
/// The symbol used before displaying the current AWS profile.
2020-07-07 22:45:32 +00:00
pub symbol : & ' a str ,
2022-04-01 15:14:05 +00:00
/// The style for the module.
2020-07-07 22:45:32 +00:00
pub style : & ' a str ,
2022-04-01 15:14:05 +00:00
/// Disables the AWS module.
2019-10-04 12:42:33 +00:00
pub disabled : bool ,
2022-04-01 15:14:05 +00:00
/// Table of region aliases to display in addition to the AWS name.
2019-12-20 17:30:47 +00:00
pub region_aliases : HashMap < String , & ' a str > ,
2022-04-01 15:14:05 +00:00
/// Table of profile aliases to display in addition to the AWS name.
2022-03-12 11:08:33 +00:00
pub profile_aliases : HashMap < String , & ' a str > ,
2022-04-01 15:14:05 +00:00
/// The symbol displayed when the temporary credentials have expired.
2021-05-13 00:43:46 +00:00
pub expiration_symbol : & ' a str ,
2022-04-01 15:14:05 +00:00
/// If true displays info even if `credentials`, `credential_process` or `sso_start_url` have not been setup.
2022-03-25 21:30:36 +00:00
pub force_display : bool ,
2019-10-04 12:42:33 +00:00
}
2021-03-15 10:40:52 +00:00
impl < ' a > Default for AwsConfig < ' a > {
fn default ( ) -> Self {
2019-10-04 12:42:33 +00:00
AwsConfig {
2022-04-21 18:58:06 +00:00
format : " on [$symbol($profile )( \\ ($region \\ ) )( \\ [$duration \\ ] )]($style) " ,
2020-07-07 22:45:32 +00:00
symbol : " ☁️ " ,
style : " bold yellow " ,
2019-10-04 12:42:33 +00:00
disabled : false ,
2019-12-20 17:30:47 +00:00
region_aliases : HashMap ::new ( ) ,
2022-03-12 11:08:33 +00:00
profile_aliases : HashMap ::new ( ) ,
2021-05-13 00:43:46 +00:00
expiration_symbol : " X " ,
2022-03-25 21:30:36 +00:00
force_display : false ,
2019-11-02 11:08:54 +00:00
}
}
}