Unverified Commit 666c474f authored by John DiSanti's avatar John DiSanti Committed by GitHub
Browse files

Tidy up `aws-smithy-runtime-api` a bit (#2867)

This PR makes some progress towards documenting the
`aws-smithy-runtime-api` crate, as well as some additional work to make
it more stable:

- Places the `client` module behind a `client` feature so that it will
be possible to add a `server` module/feature in the future.
- Deletes `ConfigBagAccessors`.
- Renames auth types to reflect changes in the internal spec.
- Moves `RequestAttempts` into the `client::retries` module.
- Moves several types that were in floating around in
`client::orchestrator` to their own modules.
- Renames `Connector` to `HttpConnector`.
- Changes `DynResponseDeserializer` to `SharedResponseDeserializer` for
consistency with serialization, and also so that it could be moved into
runtime components or config in the future (since those need to
implement `Clone`).
- Updates the identity and auth design doc.
- Updates READMEs and crate-level documentation.
- Fixes most, but not all, the missing documentation in the crate.
- Hides the builder macros.

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
parent e060135e
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -11,7 +11,6 @@ use aws_sigv4::http_request::SignableBody;
use aws_smithy_http::body::SdkBody;
use aws_smithy_http::byte_stream;
use aws_smithy_runtime_api::box_error::BoxError;
use aws_smithy_runtime_api::client::config_bag_accessors::ConfigBagAccessors;
use aws_smithy_runtime_api::client::interceptors::context::{
    BeforeSerializationInterceptorContextMut, BeforeTransmitInterceptorContextMut,
};
@@ -126,7 +125,7 @@ impl Interceptor for GlacierTreeHashHeaderInterceptor {
        // Request the request body to be loaded into memory immediately after serialization
        // so that it can be checksummed before signing and transmit
        cfg.interceptor_state()
            .set_loaded_request_body(LoadedRequestBody::Requested);
            .store_put(LoadedRequestBody::Requested);
        Ok(())
    }

+2 −2
Original line number Diff line number Diff line
@@ -18,8 +18,8 @@ aws-sigv4 = { path = "../aws-sigv4" }
aws-smithy-async = { path = "../../../rust-runtime/aws-smithy-async" }
aws-smithy-eventstream = { path = "../../../rust-runtime/aws-smithy-eventstream", optional = true }
aws-smithy-http = { path = "../../../rust-runtime/aws-smithy-http" }
aws-smithy-runtime = { path = "../../../rust-runtime/aws-smithy-runtime" }
aws-smithy-runtime-api = { path = "../../../rust-runtime/aws-smithy-runtime-api" }
aws-smithy-runtime = { path = "../../../rust-runtime/aws-smithy-runtime", features = ["client"] }
aws-smithy-runtime-api = { path = "../../../rust-runtime/aws-smithy-runtime-api", features = ["client"] }
aws-smithy-types = { path = "../../../rust-runtime/aws-smithy-types" }
aws-types = { path = "../aws-types" }
fastrand = "2.0.0"
+18 −22
Original line number Diff line number Diff line
@@ -10,7 +10,7 @@ use aws_sigv4::http_request::{
};
use aws_smithy_runtime_api::box_error::BoxError;
use aws_smithy_runtime_api::client::auth::{
    AuthSchemeEndpointConfig, AuthSchemeId, HttpAuthScheme, HttpRequestSigner,
    AuthScheme, AuthSchemeEndpointConfig, AuthSchemeId, Signer,
};
use aws_smithy_runtime_api::client::identity::{Identity, SharedIdentityResolver};
use aws_smithy_runtime_api::client::orchestrator::HttpRequest;
@@ -79,18 +79,18 @@ impl StdError for SigV4SigningError {

/// SigV4 auth scheme.
#[derive(Debug, Default)]
pub struct SigV4HttpAuthScheme {
    signer: SigV4HttpRequestSigner,
pub struct SigV4AuthScheme {
    signer: SigV4Signer,
}

impl SigV4HttpAuthScheme {
    /// Creates a new `SigV4HttpAuthScheme`.
impl SigV4AuthScheme {
    /// Creates a new `SigV4AuthScheme`.
    pub fn new() -> Self {
        Default::default()
    }
}

impl HttpAuthScheme for SigV4HttpAuthScheme {
impl AuthScheme for SigV4AuthScheme {
    fn scheme_id(&self) -> AuthSchemeId {
        SCHEME_ID
    }
@@ -102,7 +102,7 @@ impl HttpAuthScheme for SigV4HttpAuthScheme {
        identity_resolvers.identity_resolver(self.scheme_id())
    }

    fn request_signer(&self) -> &dyn HttpRequestSigner {
    fn signer(&self) -> &dyn Signer {
        &self.signer
    }
}
@@ -174,11 +174,11 @@ impl Storable for SigV4OperationSigningConfig {
    type Storer = StoreReplace<Self>;
}

/// SigV4 HTTP request signer.
/// SigV4 signer.
#[derive(Debug, Default)]
pub struct SigV4HttpRequestSigner;
pub struct SigV4Signer;

impl SigV4HttpRequestSigner {
impl SigV4Signer {
    /// Creates a new signer instance.
    pub fn new() -> Self {
        Self
@@ -291,7 +291,7 @@ impl SigV4HttpRequestSigner {
        endpoint_config: AuthSchemeEndpointConfig<'_>,
    ) -> Result<EndpointAuthSchemeConfig, SigV4SigningError> {
        let (mut signing_region_override, mut signing_service_override) = (None, None);
        if let Some(config) = endpoint_config.config().and_then(Document::as_object) {
        if let Some(config) = endpoint_config.as_document().and_then(Document::as_object) {
            use SigV4SigningError::BadTypeInEndpointAuthSchemeConfig as UnexpectedType;
            signing_region_override = match config.get("signingRegion") {
                Some(Document::String(s)) => Some(SigningRegion::from(Region::new(s.clone()))),
@@ -311,8 +311,8 @@ impl SigV4HttpRequestSigner {
    }
}

impl HttpRequestSigner for SigV4HttpRequestSigner {
    fn sign_request(
impl Signer for SigV4Signer {
    fn sign_http_request(
        &self,
        request: &mut HttpRequest,
        identity: &Identity,
@@ -550,15 +550,13 @@ mod tests {
                payload_override: None,
            },
        };
        SigV4HttpRequestSigner::signing_params(settings, &credentials, &operation_config, now)
            .unwrap();
        SigV4Signer::signing_params(settings, &credentials, &operation_config, now).unwrap();
        assert!(!logs_contain(EXPIRATION_WARNING));

        let mut settings = SigningSettings::default();
        settings.expires_in = Some(creds_expire_in + Duration::from_secs(10));

        SigV4HttpRequestSigner::signing_params(settings, &credentials, &operation_config, now)
            .unwrap();
        SigV4Signer::signing_params(settings, &credentials, &operation_config, now).unwrap();
        assert!(logs_contain(EXPIRATION_WARNING));
    }

@@ -583,11 +581,10 @@ mod tests {
            );
            out
        });
        let config = AuthSchemeEndpointConfig::new(Some(&config));
        let config = AuthSchemeEndpointConfig::from(Some(&config));

        let cfg = ConfigBag::of_layers(vec![layer]);
        let result =
            SigV4HttpRequestSigner::extract_operation_config(config, &cfg).expect("success");
        let result = SigV4Signer::extract_operation_config(config, &cfg).expect("success");

        assert_eq!(
            result.region,
@@ -611,8 +608,7 @@ mod tests {
        let cfg = ConfigBag::of_layers(vec![layer]);
        let config = AuthSchemeEndpointConfig::empty();

        let result =
            SigV4HttpRequestSigner::extract_operation_config(config, &cfg).expect("success");
        let result = SigV4Signer::extract_operation_config(config, &cfg).expect("success");

        assert_eq!(
            result.region,
+1 −1
Original line number Diff line number Diff line
@@ -7,7 +7,7 @@ use aws_smithy_runtime::client::orchestrator::interceptors::ServiceClockSkew;
use aws_smithy_runtime_api::box_error::BoxError;
use aws_smithy_runtime_api::client::interceptors::context::BeforeTransmitInterceptorContextMut;
use aws_smithy_runtime_api::client::interceptors::Interceptor;
use aws_smithy_runtime_api::client::request_attempts::RequestAttempts;
use aws_smithy_runtime_api::client::retries::RequestAttempts;
use aws_smithy_runtime_api::client::runtime_components::RuntimeComponents;
use aws_smithy_types::config_bag::ConfigBag;
use aws_smithy_types::date_time::Format;
+0 −1
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ class CustomizableOperationTestHelpers(runtimeConfig: RuntimeConfig) :
        "AwsUserAgent" to AwsRuntimeType.awsHttp(runtimeConfig).resolve("user_agent::AwsUserAgent"),
        "BeforeTransmitInterceptorContextMut" to RuntimeType.beforeTransmitInterceptorContextMut(runtimeConfig),
        "ConfigBag" to RuntimeType.configBag(runtimeConfig),
        "ConfigBagAccessors" to RuntimeType.configBagAccessors(runtimeConfig),
        "http" to CargoDependency.Http.toType(),
        "InterceptorContext" to RuntimeType.interceptorContext(runtimeConfig),
        "RuntimeComponentsBuilder" to RuntimeType.runtimeComponentsBuilder(runtimeConfig),
Loading