Unverified Commit cb50262c authored by Russell Cohen's avatar Russell Cohen Committed by GitHub
Browse files

Add CredentialsProvider to config (and related refactorings) (#182)

* Add credentials provider config & test

* Prepare to use `Features` during Operation Generation

* Fix sdk gradle build changes that were previously missed

* Utilize the credentials provider in the feature

* Update IdempotencyTokenProvider to be Send + Sync

* Add accessors for credential providers

* Fix build.gradle

* Update auth references to be aws-auth

* Update idempotency token test
parent 162d61b1
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -7,3 +7,4 @@ edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
smithy-http = { path = "../../../rust-runtime/smithy-http" }
+23 −0
Original line number Diff line number Diff line
pub mod provider;

use smithy_http::property_bag::PropertyBag;
use std::error::Error;
use std::fmt;
use std::fmt::{Debug, Display, Formatter};
use std::sync::Arc;
use std::time::SystemTime;

/// AWS SDK Credentials
@@ -53,6 +55,18 @@ impl Credentials {
            provider_name: STATIC_CREDENTIALS,
        }
    }

    pub fn access_key_id(&self) -> &str {
        &self.access_key_id
    }

    pub fn secret_access_key(&self) -> &str {
        &self.secret_access_key
    }

    pub fn session_token(&self) -> Option<&str> {
        self.session_token.as_deref()
    }
}

#[derive(Debug)]
@@ -90,8 +104,17 @@ pub trait ProvideCredentials: Send + Sync {
    fn credentials(&self) -> Result<Credentials, CredentialsError>;
}

pub fn default_provider() -> impl ProvideCredentials {
    // TODO: this should be a chain based on the CRT
    provider::EnvironmentVariableCredentialsProvider::new()
}

impl ProvideCredentials for Credentials {
    fn credentials(&self) -> Result<Credentials, CredentialsError> {
        Ok(self.clone())
    }
}

pub fn set_provider(config: &mut PropertyBag, provider: Arc<dyn ProvideCredentials>) {
    config.insert(provider);
}
+1 −1
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@ impl EnvironmentVariableCredentialsProvider {
    }

    /// Create a EnvironmentVariable provider from a HashMap for testing
    fn for_map(env: HashMap<String, String>) -> Self {
    pub fn for_map(env: HashMap<String, String>) -> Self {
        EnvironmentVariableCredentialsProvider {
            env: Box::new(move |key: &str| {
                env.get(key)
+1 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ dependencies {
    implementation("software.amazon.smithy:smithy-aws-protocol-tests:$smithyVersion")
    implementation("software.amazon.smithy:smithy-protocol-test-traits:$smithyVersion")
    implementation("software.amazon.smithy:smithy-aws-traits:$smithyVersion")
    testImplementation("org.junit.jupiter:junit-jupiter:5.6.1")
}

tasks.compileKotlin {
+1 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@

package software.amazon.smithy.rustsdk

import software.amazon.smithy.rust.codegen.smithy.RustCodegenDecorator
import software.amazon.smithy.rust.codegen.smithy.customize.RustCodegenDecorator
import software.amazon.smithy.rust.codegen.smithy.generators.ProtocolConfig
import software.amazon.smithy.rust.codegen.smithy.generators.config.ConfigCustomization

Loading