Struct rusoto_credential::EnvironmentProvider[][src]

pub struct EnvironmentProvider { /* fields omitted */ }

Provides AWS credentials from environment variables.

Available Environment Variables

Example

use futures::future::Future;
use rusoto_credential::{EnvironmentProvider, ProvideAwsCredentials};
use std::env;

#[tokio::main]
async fn main() {
    env::set_var("AWS_ACCESS_KEY_ID", "ANTN35UAENTS5UIAEATD");
    env::set_var("AWS_SECRET_ACCESS_KEY", "TtnuieannGt2rGuie2t8Tt7urarg5nauedRndrur");
    env::set_var("AWS_SESSION_TOKEN", "DfnGs8Td4rT8r4srxAg6Td4rT8r4srxAg6GtkTir");

    let creds = EnvironmentProvider::default().credentials().await.unwrap();

    assert_eq!(creds.aws_access_key_id(), "ANTN35UAENTS5UIAEATD");
    assert_eq!(creds.aws_secret_access_key(), "TtnuieannGt2rGuie2t8Tt7urarg5nauedRndrur");
    assert_eq!(creds.token(), &Some("DfnGs8Td4rT8r4srxAg6Td4rT8r4srxAg6GtkTir".to_string()));
    assert!(creds.expires_at().is_none()); // doesn't expire

    env::set_var("AWS_CREDENTIAL_EXPIRATION", "2018-04-21T01:13:02Z");
    let creds = EnvironmentProvider::default().credentials().await.unwrap();
    assert_eq!(creds.expires_at().unwrap().to_rfc3339(), "2018-04-21T01:13:02+00:00");
}

Implementations

impl EnvironmentProvider[src]

pub fn with_prefix(prefix: &str) -> Self[src]

Create an EnvironmentProvider with a non-standard variable prefix.

use std::future::Future;
use rusoto_credential::{EnvironmentProvider, ProvideAwsCredentials};
use std::env;

#[tokio::main]
async fn main() -> () {
    env::set_var("MYAPP_ACCESS_KEY_ID", "ANTN35UAENTS5UIAEATD");
    env::set_var("MYAPP_SECRET_ACCESS_KEY", "TtnuieannGt2rGuie2t8Tt7urarg5nauedRndrur");
    env::set_var("MYAPP_SESSION_TOKEN", "DfnGs8Td4rT8r4srxAg6Td4rT8r4srxAg6GtkTir");

    let creds = EnvironmentProvider::with_prefix("MYAPP").credentials().await.unwrap();

    assert_eq!(creds.aws_access_key_id(), "ANTN35UAENTS5UIAEATD");
    assert_eq!(creds.aws_secret_access_key(), "TtnuieannGt2rGuie2t8Tt7urarg5nauedRndrur");
    assert_eq!(creds.token(), &Some("DfnGs8Td4rT8r4srxAg6Td4rT8r4srxAg6GtkTir".to_string()));
    assert!(creds.expires_at().is_none()); // doesn't expire

    env::set_var("MYAPP_CREDENTIAL_EXPIRATION", "2018-04-21T01:13:02Z");
    let creds = EnvironmentProvider::with_prefix("MYAPP").credentials().await.unwrap();
    assert_eq!(creds.expires_at().unwrap().to_rfc3339(), "2018-04-21T01:13:02+00:00");
}

Trait Implementations

impl Clone for EnvironmentProvider[src]

impl Debug for EnvironmentProvider[src]

impl Default for EnvironmentProvider[src]

impl ProvideAwsCredentials for EnvironmentProvider[src]

Auto Trait Implementations

impl RefUnwindSafe for EnvironmentProvider

impl Send for EnvironmentProvider

impl Sync for EnvironmentProvider

impl Unpin for EnvironmentProvider

impl UnwindSafe for EnvironmentProvider

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.