Skip to content

Commit 0679678

Browse files
authored
fix: authSchemePreference in config + remove from default resolver (#948)
1 parent 37cbf9c commit 0679678

File tree

2 files changed

+11
-26
lines changed

2 files changed

+11
-26
lines changed

smithy-swift-codegen/src/main/kotlin/software/amazon/smithy/swift/codegen/AuthSchemeResolverGenerator.kt

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class AuthSchemeResolverGenerator(
5454
"}",
5555
SmithyHTTPAuthAPITypes.AuthSchemeResolverParams,
5656
) {
57+
writer.write("public let authSchemePreference: \$N?", SwiftTypes.StringList)
5758
write("public let operation: \$N", SwiftTypes.String)
5859

5960
if (usesRulesBasedAuthResolver(ctx)) {
@@ -146,8 +147,6 @@ class AuthSchemeResolverGenerator(
146147
defaultResolverName,
147148
serviceSpecificAuthResolverProtocol,
148149
) {
149-
write("")
150-
renderInit(writer)
151150
write("")
152151
renderResolveAuthSchemeMethod(serviceIndex, ctx, writer)
153152
write("")
@@ -160,19 +159,6 @@ class AuthSchemeResolverGenerator(
160159
}
161160
}
162161

163-
private fun renderInit(writer: SwiftWriter) {
164-
writer.apply {
165-
write("public let authSchemePreference: [String]")
166-
write("")
167-
openBlock(
168-
"public init(authSchemePreference: [String] = []) {",
169-
"}",
170-
) {
171-
write("self.authSchemePreference = authSchemePreference")
172-
}
173-
}
174-
}
175-
176162
private fun renderResolveAuthSchemeMethod(
177163
serviceIndex: ServiceIndex,
178164
ctx: ProtocolGenerator.GenerationContext,
@@ -200,7 +186,9 @@ class AuthSchemeResolverGenerator(
200186
// Render switch block
201187
renderSwitchBlock(serviceIndex, ctx, writer)
202188
// Call reprioritizeAuthOptions and return result
203-
write("return self.reprioritizeAuthOptions(authSchemePreference: authSchemePreference, authOptions: validAuthOptions)")
189+
write(
190+
"return self.reprioritizeAuthOptions(authSchemePreference: serviceParams.authSchemePreference, authOptions: validAuthOptions)",
191+
)
204192
}
205193
}
206194
}
@@ -317,12 +305,13 @@ class AuthSchemeResolverGenerator(
317305
SmithyTypes.ClientError,
318306
)
319307
}
308+
writer.write("let authSchemePreference = context.getAuthSchemePreference()")
320309
val paramType = getSdkId(ctx) + SmithyHTTPAuthAPITypes.AuthSchemeResolverParams.name
321310
if (hasSigV4) {
322311
write("let opRegion = context.getRegion()")
323-
write("return $paramType(operation: opName, region: opRegion)")
312+
write("return $paramType(authSchemePreference: authSchemePreference, operation: opName, region: opRegion)")
324313
} else {
325-
write("return $paramType(operation: opName)")
314+
write("return $paramType(authSchemePreference: authSchemePreference, operation: opName)")
326315
}
327316
}
328317
}

smithy-swift-codegen/src/test/kotlin/software/amazon/smithy/swift/codegen/requestandresponse/requestflow/AuthSchemeResolverGeneratorTests.kt

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class AuthSchemeResolverGeneratorTests {
2121
contents.shouldSyntacticSanityCheck()
2222
val expected = """
2323
public struct ExampleAuthSchemeResolverParameters: SmithyHTTPAuthAPI.AuthSchemeResolverParameters {
24+
public let authSchemePreference: [String]?
2425
public let operation: Swift.String
2526
// Region is used for SigV4 auth scheme
2627
public let region: Swift.String?
@@ -34,12 +35,6 @@ public protocol ExampleAuthSchemeResolver: SmithyHTTPAuthAPI.AuthSchemeResolver
3435
3536
public struct DefaultExampleAuthSchemeResolver: ExampleAuthSchemeResolver {
3637
37-
public let authSchemePreference: [String]
38-
39-
public init(authSchemePreference: [String] = []) {
40-
self.authSchemePreference = authSchemePreference
41-
}
42-
4338
public func resolveAuthScheme(params: SmithyHTTPAuthAPI.AuthSchemeResolverParameters) throws -> [SmithyHTTPAuthAPI.AuthOption] {
4439
var validAuthOptions = [SmithyHTTPAuthAPI.AuthOption]()
4540
guard let serviceParams = params as? ExampleAuthSchemeResolverParameters else {
@@ -103,15 +98,16 @@ public struct DefaultExampleAuthSchemeResolver: ExampleAuthSchemeResolver {
10398
sigv4Option.signingProperties.set(key: SmithyHTTPAuthAPI.SigningPropertyKeys.signingRegion, value: region)
10499
validAuthOptions.append(sigv4Option)
105100
}
106-
return self.reprioritizeAuthOptions(authSchemePreference: authSchemePreference, authOptions: validAuthOptions)
101+
return self.reprioritizeAuthOptions(authSchemePreference: serviceParams.authSchemePreference, authOptions: validAuthOptions)
107102
}
108103
109104
public func constructParameters(context: Smithy.Context) throws -> SmithyHTTPAuthAPI.AuthSchemeResolverParameters {
110105
guard let opName = context.getOperation() else {
111106
throw Smithy.ClientError.dataNotFound("Operation name not configured in middleware context for auth scheme resolver params construction.")
112107
}
108+
let authSchemePreference = context.getAuthSchemePreference()
113109
let opRegion = context.getRegion()
114-
return ExampleAuthSchemeResolverParameters(operation: opName, region: opRegion)
110+
return ExampleAuthSchemeResolverParameters(authSchemePreference: authSchemePreference, operation: opName, region: opRegion)
115111
}
116112
}
117113
"""

0 commit comments

Comments
 (0)