Skip to content

Commit

Permalink
Integrate ProvideCredentials into SDK runtime and codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
rcoh committed Aug 31, 2021
1 parent 6fd3f80 commit a2c5655
Show file tree
Hide file tree
Showing 17 changed files with 253 additions and 353 deletions.
106 changes: 0 additions & 106 deletions aws/rust-runtime/aws-auth/src/credentials.rs

This file was deleted.

8 changes: 6 additions & 2 deletions aws/rust-runtime/aws-auth/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
* SPDX-License-Identifier: Apache-2.0.
*/

mod credentials;
pub mod middleware;
pub mod provider;

pub use credentials::Credentials;
use aws_types::credentials::SharedCredentialsProvider;
use smithy_http::property_bag::PropertyBag;

pub fn set_provider(bag: &mut PropertyBag, provider: SharedCredentialsProvider) {
bag.insert(provider);
}
22 changes: 13 additions & 9 deletions aws/rust-runtime/aws-auth/src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* SPDX-License-Identifier: Apache-2.0.
*/

use crate::provider::{CredentialsError, CredentialsProvider};
use smithy_http::middleware::AsyncMapRequest;
use smithy_http::operation::Request;
use std::future::Future;
Expand All @@ -26,7 +25,10 @@ impl CredentialsStage {
}

async fn load_creds(mut request: Request) -> Result<Request, CredentialsStageError> {
let provider = request.properties().get::<CredentialsProvider>().cloned();
let provider = request
.properties()
.get::<SharedCredentialsProvider>()
.cloned();
let provider = match provider {
Some(provider) => provider,
None => {
Expand All @@ -51,7 +53,7 @@ impl CredentialsStage {
}

mod error {
use crate::provider::CredentialsError;
use aws_types::credentials::CredentialsError;
use std::error::Error as StdError;
use std::fmt;

Expand Down Expand Up @@ -86,6 +88,7 @@ mod error {
}
}

use aws_types::credentials::{CredentialsError, ProvideCredentials, SharedCredentialsProvider};
pub use error::*;

type BoxFuture<T> = Pin<Box<dyn Future<Output = T> + Send>>;
Expand All @@ -102,12 +105,13 @@ impl AsyncMapRequest for CredentialsStage {
#[cfg(test)]
mod tests {
use super::CredentialsStage;
use crate::provider::{async_provide_credentials_fn, set_provider, CredentialsError};
use crate::Credentials;
use crate::provider::async_provide_credentials_fn;
use crate::set_provider;
use aws_types::credentials::{CredentialsError, SharedCredentialsProvider};
use aws_types::Credentials;
use smithy_http::body::SdkBody;
use smithy_http::middleware::AsyncMapRequest;
use smithy_http::operation;
use std::sync::Arc;

#[tokio::test]
async fn no_cred_provider_is_ok() {
Expand All @@ -123,7 +127,7 @@ mod tests {
let mut req = operation::Request::new(http::Request::new(SdkBody::from("some body")));
set_provider(
&mut req.properties_mut(),
Arc::new(async_provide_credentials_fn(|| async {
SharedCredentialsProvider::new(async_provide_credentials_fn(|| async {
Err(CredentialsError::Unhandled("whoops".into()))
})),
);
Expand All @@ -138,7 +142,7 @@ mod tests {
let mut req = operation::Request::new(http::Request::new(SdkBody::from("some body")));
set_provider(
&mut req.properties_mut(),
Arc::new(async_provide_credentials_fn(|| async {
SharedCredentialsProvider::new(async_provide_credentials_fn(|| async {
Err(CredentialsError::CredentialsNotLoaded)
})),
);
Expand All @@ -153,7 +157,7 @@ mod tests {
let mut req = operation::Request::new(http::Request::new(SdkBody::from("some body")));
set_provider(
&mut req.properties_mut(),
Arc::new(Credentials::from_keys("test", "test", None)),
SharedCredentialsProvider::new(Credentials::from_keys("test", "test", None)),
);
let req = CredentialsStage::new()
.apply(req)
Expand Down
Loading

0 comments on commit a2c5655

Please sign in to comment.