Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class AuthSchemeResolverGenerator(
"}",
SmithyHTTPAuthAPITypes.AuthSchemeResolverParams,
) {
writer.write("public let authSchemePreference: \$N?", SwiftTypes.StringList)
write("public let operation: \$N", SwiftTypes.String)

if (usesRulesBasedAuthResolver(ctx)) {
Expand Down Expand Up @@ -146,8 +147,6 @@ class AuthSchemeResolverGenerator(
defaultResolverName,
serviceSpecificAuthResolverProtocol,
) {
write("")
renderInit(writer)
write("")
renderResolveAuthSchemeMethod(serviceIndex, ctx, writer)
write("")
Expand All @@ -160,19 +159,6 @@ class AuthSchemeResolverGenerator(
}
}

private fun renderInit(writer: SwiftWriter) {
writer.apply {
write("public let authSchemePreference: [String]")
write("")
openBlock(
"public init(authSchemePreference: [String] = []) {",
"}",
) {
write("self.authSchemePreference = authSchemePreference")
}
}
}

private fun renderResolveAuthSchemeMethod(
serviceIndex: ServiceIndex,
ctx: ProtocolGenerator.GenerationContext,
Expand Down Expand Up @@ -200,7 +186,9 @@ class AuthSchemeResolverGenerator(
// Render switch block
renderSwitchBlock(serviceIndex, ctx, writer)
// Call reprioritizeAuthOptions and return result
write("return self.reprioritizeAuthOptions(authSchemePreference: authSchemePreference, authOptions: validAuthOptions)")
write(
"return self.reprioritizeAuthOptions(authSchemePreference: serviceParams.authSchemePreference, authOptions: validAuthOptions)",
)
}
}
}
Expand Down Expand Up @@ -317,12 +305,13 @@ class AuthSchemeResolverGenerator(
SmithyTypes.ClientError,
)
}
writer.write("let authSchemePreference = context.getAuthSchemePreference()")
val paramType = getSdkId(ctx) + SmithyHTTPAuthAPITypes.AuthSchemeResolverParams.name
if (hasSigV4) {
write("let opRegion = context.getRegion()")
write("return $paramType(operation: opName, region: opRegion)")
write("return $paramType(authSchemePreference: authSchemePreference, operation: opName, region: opRegion)")
} else {
write("return $paramType(operation: opName)")
write("return $paramType(authSchemePreference: authSchemePreference, operation: opName)")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class AuthSchemeResolverGeneratorTests {
contents.shouldSyntacticSanityCheck()
val expected = """
public struct ExampleAuthSchemeResolverParameters: SmithyHTTPAuthAPI.AuthSchemeResolverParameters {
public let authSchemePreference: [String]?
public let operation: Swift.String
// Region is used for SigV4 auth scheme
public let region: Swift.String?
Expand All @@ -34,12 +35,6 @@ public protocol ExampleAuthSchemeResolver: SmithyHTTPAuthAPI.AuthSchemeResolver

public struct DefaultExampleAuthSchemeResolver: ExampleAuthSchemeResolver {

public let authSchemePreference: [String]

public init(authSchemePreference: [String] = []) {
self.authSchemePreference = authSchemePreference
}

public func resolveAuthScheme(params: SmithyHTTPAuthAPI.AuthSchemeResolverParameters) throws -> [SmithyHTTPAuthAPI.AuthOption] {
var validAuthOptions = [SmithyHTTPAuthAPI.AuthOption]()
guard let serviceParams = params as? ExampleAuthSchemeResolverParameters else {
Expand Down Expand Up @@ -103,15 +98,16 @@ public struct DefaultExampleAuthSchemeResolver: ExampleAuthSchemeResolver {
sigv4Option.signingProperties.set(key: SmithyHTTPAuthAPI.SigningPropertyKeys.signingRegion, value: region)
validAuthOptions.append(sigv4Option)
}
return self.reprioritizeAuthOptions(authSchemePreference: authSchemePreference, authOptions: validAuthOptions)
return self.reprioritizeAuthOptions(authSchemePreference: serviceParams.authSchemePreference, authOptions: validAuthOptions)
}

public func constructParameters(context: Smithy.Context) throws -> SmithyHTTPAuthAPI.AuthSchemeResolverParameters {
guard let opName = context.getOperation() else {
throw Smithy.ClientError.dataNotFound("Operation name not configured in middleware context for auth scheme resolver params construction.")
}
let authSchemePreference = context.getAuthSchemePreference()
let opRegion = context.getRegion()
return ExampleAuthSchemeResolverParameters(operation: opName, region: opRegion)
return ExampleAuthSchemeResolverParameters(authSchemePreference: authSchemePreference, operation: opName, region: opRegion)
}
}
"""
Expand Down
Loading