awsmfa 0.3.2

The automation tool for Multi-Factor Authentication (MFA) process to use awscli.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use anyhow::{anyhow, Error};
use totp_rs::{Algorithm, Secret, TOTP};

pub mod aws;
pub mod cmd;
mod config;

pub type Result<T> = std::result::Result<T, Error>;
pub use config::MfaConfig;

pub fn get_otp(config: &MfaConfig, profile: &str) -> Result<String> {
    let secret = Secret::Encoded(config.get_secret(profile)?.to_ascii_uppercase())
        .to_bytes()
        .map_err(|e| anyhow!("{:#?}", e))?;
    TOTP::new(Algorithm::SHA1, 6, 1, 30, secret)
        .map_err(|e| anyhow!("{:#?}", e))
        .and_then(|totp| totp.generate_current().map_err(Error::new))
}