Commit 6130a858 authored by Russell Cohen's avatar Russell Cohen Committed by AWS SDK Rust Bot
Browse files

[smithy-rs] Fix bug where Custom Auth Schemes were not respected (#3087)

## Motivation and Context
- Fixes #3034
## Description
Because AuthSchemeOptions were being registered at the operation level,
there was no way for them to be overridden by customer-provided runtime
plugins. This moves them into a separate plugin that is added at
Client/Default priority.

## Testing
- new unit test

## Checklist
<!--- If a checkbox below is not applicable, then please DELETE it
rather than leaving it unchecked -->
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the
smithy-rs codegen or runtime crates
- [x] I have updated `CHANGELOG.next.toml` if I made changes to the AWS
SDK, generated SDK code, or SDK runtime crates

----

_By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice._
parent b95f7d68
Loading
Loading
Loading
Loading
+35 −0
Original line number Diff line number Diff line
// Code generated by software.amazon.smithy.rust.codegen.smithy-rs. DO NOT EDIT.
/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * SPDX-License-Identifier: Apache-2.0
 */

use std::borrow::Cow;

use aws_smithy_runtime_api::client::auth::static_resolver::StaticAuthSchemeOptionResolver;
use aws_smithy_runtime_api::client::auth::AuthSchemeId;
use aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder;
use aws_smithy_runtime_api::client::runtime_plugin::{Order, RuntimePlugin};

#[derive(Debug)]
pub(crate) struct DefaultAuthOptionsPlugin {
    runtime_components: RuntimeComponentsBuilder,
}

impl DefaultAuthOptionsPlugin {
    pub(crate) fn new(auth_schemes: Vec<AuthSchemeId>) -> Self {
        let runtime_components = RuntimeComponentsBuilder::new("default_auth_options")
            .with_auth_scheme_option_resolver(Some(StaticAuthSchemeOptionResolver::new(auth_schemes)));
        Self { runtime_components }
    }
}

impl RuntimePlugin for DefaultAuthOptionsPlugin {
    fn order(&self) -> Order {
        Order::Defaults
    }

    fn runtime_components(&self, _current_components: &RuntimeComponentsBuilder) -> Cow<'_, RuntimeComponentsBuilder> {
        Cow::Borrowed(&self.runtime_components)
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -185,6 +185,8 @@ pub mod primitives;
/// Data structures used by operation inputs/outputs.
pub mod types;

mod auth_plugin;

pub(crate) mod client_idempotency_token;

mod idempotency_token;
+12 −15
Original line number Diff line number Diff line
@@ -61,14 +61,18 @@ impl ApplyArchiveRule {
        config_override: ::std::option::Option<crate::config::Builder>,
    ) -> ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins {
        let mut runtime_plugins = client_runtime_plugins.with_operation_plugin(Self::new());
        runtime_plugins = runtime_plugins.with_operation_plugin(crate::client_idempotency_token::IdempotencyTokenRuntimePlugin::new(
        runtime_plugins = runtime_plugins
            .with_operation_plugin(crate::client_idempotency_token::IdempotencyTokenRuntimePlugin::new(
                |token_provider, input| {
                    let input: &mut crate::operation::apply_archive_rule::ApplyArchiveRuleInput = input.downcast_mut().expect("correct type");
                    if input.client_token.is_none() {
                        input.client_token = ::std::option::Option::Some(token_provider.make_idempotency_token());
                    }
                },
        ));
            ))
            .with_client_plugin(crate::auth_plugin::DefaultAuthOptionsPlugin::new(vec![
                ::aws_runtime::auth::sigv4::SCHEME_ID,
            ]));
        if let ::std::option::Option::Some(config_override) = config_override {
            for plugin in config_override.runtime_plugins.iter().cloned() {
                runtime_plugins = runtime_plugins.with_operation_plugin(plugin);
@@ -118,13 +122,6 @@ impl ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin for ApplyAr
    ) -> ::std::borrow::Cow<'_, ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder> {
        ::std::borrow::Cow::Owned(
            ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("ApplyArchiveRule")
                .with_auth_scheme_option_resolver(::std::option::Option::Some(
                    ::aws_smithy_runtime_api::client::auth::SharedAuthSchemeOptionResolver::new(
                        ::aws_smithy_runtime_api::client::auth::static_resolver::StaticAuthSchemeOptionResolver::new(vec![
                            ::aws_runtime::auth::sigv4::SCHEME_ID,
                        ]),
                    ),
                ))
                .with_interceptor(ApplyArchiveRuleEndpointParamsInterceptor)
                .with_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::TransientErrorClassifier::<
                    crate::operation::apply_archive_rule::ApplyArchiveRuleError,
+3 −8
Original line number Diff line number Diff line
@@ -67,7 +67,9 @@ impl CancelPolicyGeneration {
        config_override: ::std::option::Option<crate::config::Builder>,
    ) -> ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins {
        let mut runtime_plugins = client_runtime_plugins.with_operation_plugin(Self::new());

        runtime_plugins = runtime_plugins.with_client_plugin(crate::auth_plugin::DefaultAuthOptionsPlugin::new(vec![
            ::aws_runtime::auth::sigv4::SCHEME_ID,
        ]));
        if let ::std::option::Option::Some(config_override) = config_override {
            for plugin in config_override.runtime_plugins.iter().cloned() {
                runtime_plugins = runtime_plugins.with_operation_plugin(plugin);
@@ -117,13 +119,6 @@ impl ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin for CancelP
    ) -> ::std::borrow::Cow<'_, ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder> {
        ::std::borrow::Cow::Owned(
            ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("CancelPolicyGeneration")
                .with_auth_scheme_option_resolver(::std::option::Option::Some(
                    ::aws_smithy_runtime_api::client::auth::SharedAuthSchemeOptionResolver::new(
                        ::aws_smithy_runtime_api::client::auth::static_resolver::StaticAuthSchemeOptionResolver::new(vec![
                            ::aws_runtime::auth::sigv4::SCHEME_ID,
                        ]),
                    ),
                ))
                .with_interceptor(CancelPolicyGenerationEndpointParamsInterceptor)
                .with_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::TransientErrorClassifier::<
                    crate::operation::cancel_policy_generation::CancelPolicyGenerationError,
+12 −15
Original line number Diff line number Diff line
@@ -67,14 +67,18 @@ impl CreateAccessPreview {
        config_override: ::std::option::Option<crate::config::Builder>,
    ) -> ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugins {
        let mut runtime_plugins = client_runtime_plugins.with_operation_plugin(Self::new());
        runtime_plugins = runtime_plugins.with_operation_plugin(crate::client_idempotency_token::IdempotencyTokenRuntimePlugin::new(
        runtime_plugins = runtime_plugins
            .with_operation_plugin(crate::client_idempotency_token::IdempotencyTokenRuntimePlugin::new(
                |token_provider, input| {
                    let input: &mut crate::operation::create_access_preview::CreateAccessPreviewInput = input.downcast_mut().expect("correct type");
                    if input.client_token.is_none() {
                        input.client_token = ::std::option::Option::Some(token_provider.make_idempotency_token());
                    }
                },
        ));
            ))
            .with_client_plugin(crate::auth_plugin::DefaultAuthOptionsPlugin::new(vec![
                ::aws_runtime::auth::sigv4::SCHEME_ID,
            ]));
        if let ::std::option::Option::Some(config_override) = config_override {
            for plugin in config_override.runtime_plugins.iter().cloned() {
                runtime_plugins = runtime_plugins.with_operation_plugin(plugin);
@@ -124,13 +128,6 @@ impl ::aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin for CreateA
    ) -> ::std::borrow::Cow<'_, ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder> {
        ::std::borrow::Cow::Owned(
            ::aws_smithy_runtime_api::client::runtime_components::RuntimeComponentsBuilder::new("CreateAccessPreview")
                .with_auth_scheme_option_resolver(::std::option::Option::Some(
                    ::aws_smithy_runtime_api::client::auth::SharedAuthSchemeOptionResolver::new(
                        ::aws_smithy_runtime_api::client::auth::static_resolver::StaticAuthSchemeOptionResolver::new(vec![
                            ::aws_runtime::auth::sigv4::SCHEME_ID,
                        ]),
                    ),
                ))
                .with_interceptor(CreateAccessPreviewEndpointParamsInterceptor)
                .with_retry_classifier(::aws_smithy_runtime::client::retries::classifiers::TransientErrorClassifier::<
                    crate::operation::create_access_preview::CreateAccessPreviewError,
Loading