Skip to content

Commit

Permalink
feat: tie up some loose ends (#645)
Browse files Browse the repository at this point in the history
* Rename runtime type and file in Kotlin side to match corresponding type in Swift side, now both called SignerMiddleware.

* Change DefaultIdentityResolverConfiguration's identity resolvers member field to be Attributes so it can store multiple types of identity resolvers and return one with matching identity type. Necessary for supporting multiple types of identities down the line.

* Detect newly added SigV4a trait and handle accordingly.

---------

Co-authored-by: Sichan Yoo <[email protected]>
  • Loading branch information
sichanyoo and Sichan Yoo authored Jan 16, 2024
1 parent b5868d8 commit 6b51513
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
//

public struct DefaultIdentityResolverConfiguration: IdentityResolverConfiguration {
let credentialsProvider: (any IdentityResolver)?
let credentialsProvider: Attributes

public init(configuredIdResolvers: Attributes) {
self.credentialsProvider = configuredIdResolvers.get(key: AttributeKeys.awsIdResolver) ?? nil
self.credentialsProvider = configuredIdResolvers
}

func getIdentityResolver(identityKind: IdentityKind) -> (any IdentityResolver)? {
switch identityKind {
case .aws:
return self.credentialsProvider
return self.credentialsProvider.get(key: AttributeKeys.awsIdResolver)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ class AuthSchemeResolverGenerator {
// endpoint resolver's auth scheme resolution to resolve an auth scheme.
renderEndpointParamFields(ctx, this)
} else {
// If service supports SigV4 auth scheme, it's a special-case for now - change once sigv4a trait is added
// and it becomes possible at model level to notate custom members for a given auth scheme.
// If service supports SigV4/SigV4a auth scheme, it's a special-case for now - change once
// it becomes possible at model level to notate custom members for a given auth scheme.
// Region has to be in params in addition to operation string.
if (serviceIndex.getEffectiveAuthSchemes(ctx.service).contains(SigV4Trait.ID)) {
write("// Region is used for SigV4 auth scheme")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ object ClientRuntimeTypes {
val RetryMiddleware = runtimeSymbol("RetryMiddleware")
val IdempotencyTokenMiddleware = runtimeSymbol("IdempotencyTokenMiddleware")
val NoopHandler = runtimeSymbol("NoopHandler")
val SigningMiddleware = runtimeSymbol("SignerMiddleware")
val SignerMiddleware = runtimeSymbol("SignerMiddleware")
val AuthSchemeMiddleware = runtimeSymbol("AuthSchemeMiddleware")
val BodyMiddleware = runtimeSymbol("BodyMiddleware")
val PayloadBodyMiddleware = runtimeSymbol("PayloadBodyMiddleware")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import software.amazon.smithy.swift.codegen.integration.middlewares.OperationInp
import software.amazon.smithy.swift.codegen.integration.middlewares.OperationInputUrlHostMiddleware
import software.amazon.smithy.swift.codegen.integration.middlewares.OperationInputUrlPathMiddleware
import software.amazon.smithy.swift.codegen.integration.middlewares.RetryMiddleware
import software.amazon.smithy.swift.codegen.integration.middlewares.SigningMiddleware
import software.amazon.smithy.swift.codegen.integration.middlewares.SignerMiddleware
import software.amazon.smithy.swift.codegen.integration.middlewares.providers.HttpHeaderProvider
import software.amazon.smithy.swift.codegen.integration.middlewares.providers.HttpQueryItemProvider
import software.amazon.smithy.swift.codegen.integration.middlewares.providers.HttpUrlPathProvider
Expand Down Expand Up @@ -465,7 +465,7 @@ abstract class HttpBindingProtocolGenerator : ProtocolGenerator {
operationMiddleware.appendMiddleware(operation, LoggingMiddleware(ctx.model, ctx.symbolProvider))
operationMiddleware.appendMiddleware(operation, RetryMiddleware(ctx.model, ctx.symbolProvider, retryErrorInfoProviderSymbol))

operationMiddleware.appendMiddleware(operation, SigningMiddleware(ctx.model, ctx.symbolProvider))
operationMiddleware.appendMiddleware(operation, SignerMiddleware(ctx.model, ctx.symbolProvider))

addProtocolSpecificMiddleware(ctx, operation)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

package software.amazon.smithy.swift.codegen.integration

import software.amazon.smithy.aws.traits.auth.SigV4ATrait
import software.amazon.smithy.aws.traits.auth.SigV4Trait
import software.amazon.smithy.codegen.core.Symbol
import software.amazon.smithy.model.knowledge.ServiceIndex
Expand Down Expand Up @@ -45,6 +46,9 @@ open class HttpProtocolServiceClient(
if (ServiceIndex(ctx.model).getEffectiveAuthSchemes(ctx.service).contains(SigV4Trait.ID)) {
writer.write("modeledAuthSchemes.append(SigV4AuthScheme())")
}
if (ServiceIndex(ctx.model).getEffectiveAuthSchemes(ctx.service).contains(SigV4ATrait.ID)) {
writer.write("modeledAuthSchemes.append(SigV4AAuthScheme())")
}
writer.write("config.authSchemes = config.authSchemes ?? modeledAuthSchemes")
writer.write("self.config = config")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import software.amazon.smithy.swift.codegen.middleware.MiddlewarePosition
import software.amazon.smithy.swift.codegen.middleware.MiddlewareRenderable
import software.amazon.smithy.swift.codegen.middleware.MiddlewareStep

class SigningMiddleware(
class SignerMiddleware(
val model: Model,
val symbolProvider: SymbolProvider
) : MiddlewareRenderable {
Expand All @@ -31,7 +31,7 @@ class SigningMiddleware(
val outputError = MiddlewareShapeUtils.outputErrorSymbol(op)
writer.write(
"$operationStackName.${middlewareStep.stringValue()}.intercept(position: ${position.stringValue()}, middleware: \$N<\$N, \$N>())",
ClientRuntimeTypes.Middleware.SigningMiddleware, output, outputError
ClientRuntimeTypes.Middleware.SignerMiddleware, output, outputError
)
}
}

0 comments on commit 6b51513

Please sign in to comment.