Skip to content

Commit

Permalink
Remove DefaultBearerTokenIdentityResolverChain from plugin codegen too.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sichan Yoo committed Jul 26, 2024
1 parent a4ad5bf commit 8de16ee
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package software.amazon.smithy.aws.swift.codegen

import software.amazon.smithy.aws.swift.codegen.swiftmodules.AWSSDKIdentityTypes
import software.amazon.smithy.codegen.core.Symbol
import software.amazon.smithy.model.knowledge.ServiceIndex
import software.amazon.smithy.model.traits.HttpBearerAuthTrait
import software.amazon.smithy.swift.codegen.AuthSchemeResolverGenerator
import software.amazon.smithy.swift.codegen.SwiftWriter
Expand All @@ -23,6 +22,7 @@ import software.amazon.smithy.swift.codegen.swiftmodules.SmithyHTTPAPITypes
import software.amazon.smithy.swift.codegen.swiftmodules.SmithyHTTPAuthAPITypes
import software.amazon.smithy.swift.codegen.swiftmodules.SmithyIdentityTypes
import software.amazon.smithy.swift.codegen.swiftmodules.SmithyRetriesAPITypes
import software.amazon.smithy.swift.codegen.utils.AuthUtils
import software.amazon.smithy.swift.codegen.utils.toUpperCamelCase

class AWSHttpProtocolServiceClient(
Expand Down Expand Up @@ -52,7 +52,7 @@ class AWSHttpProtocolServiceClient(
ConfigProperty("authSchemes", SmithyHTTPAuthAPITypes.AuthSchemes.toOptional(), AWSAuthUtils(ctx).authSchemesDefaultProvider)
}
"bearerTokenIdentityResolver" -> {
if (ServiceIndex(ctx.model).getEffectiveAuthSchemes(ctx.service).contains(HttpBearerAuthTrait.ID)) {
if (AuthUtils(ctx).isSupportedAuthScheme(HttpBearerAuthTrait.ID)) {
ConfigProperty(
"bearerTokenIdentityResolver",
SmithyIdentityTypes.BearerTokenIdentityResolver.toGeneric(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import software.amazon.smithy.aws.swift.codegen.AWSAuthUtils
import software.amazon.smithy.aws.swift.codegen.swiftmodules.AWSClientRuntimeTypes
import software.amazon.smithy.aws.swift.codegen.swiftmodules.AWSSDKIdentityTypes
import software.amazon.smithy.codegen.core.Symbol
import software.amazon.smithy.model.traits.HttpBearerAuthTrait
import software.amazon.smithy.swift.codegen.AuthSchemeResolverGenerator
import software.amazon.smithy.swift.codegen.SwiftWriter
import software.amazon.smithy.swift.codegen.integration.Plugin
import software.amazon.smithy.swift.codegen.integration.ProtocolGenerator
import software.amazon.smithy.swift.codegen.integration.ServiceConfig
import software.amazon.smithy.swift.codegen.model.buildSymbol
import software.amazon.smithy.swift.codegen.swiftmodules.ClientRuntimeTypes
import software.amazon.smithy.swift.codegen.swiftmodules.SmithyIdentityTypes
import software.amazon.smithy.swift.codegen.utils.AuthUtils

class DefaultAWSAuthSchemePlugin(private val serviceConfig: ServiceConfig) : Plugin {
override val className: Symbol
Expand All @@ -31,7 +34,18 @@ class DefaultAWSAuthSchemePlugin(private val serviceConfig: ServiceConfig) : Plu
writer.write("config.authSchemeResolver = \$L", "Default${AuthSchemeResolverGenerator.getSdkId(ctx)}AuthSchemeResolver()")
writer.write("config.authSchemes = \$L", AWSAuthUtils(ctx).getModeledAuthSchemesSupportedBySDK(ctx, writer))
writer.write("config.awsCredentialIdentityResolver = try \$N.awsCredentialIdentityResolver()", AWSClientRuntimeTypes.Core.AWSClientConfigDefaultsProvider)
writer.write("config.bearerTokenIdentityResolver = try \$N()", AWSSDKIdentityTypes.DefaultBearerTokenIdentityResolverChain)
if (AuthUtils(ctx).isSupportedAuthScheme(HttpBearerAuthTrait.ID)) {
writer.write(
"config.bearerTokenIdentityResolver = try \$N()",
AWSSDKIdentityTypes.DefaultBearerTokenIdentityResolverChain
)
} else {
writer.write(
"config.bearerTokenIdentityResolver = \$N(token: \$N(token: \"\"))",
SmithyIdentityTypes.StaticBearerTokenIdentityResolver,
SmithyIdentityTypes.BearerTokenIdentity
)
}
}
}
}
Expand Down

0 comments on commit 8de16ee

Please sign in to comment.