Skip to content

Commit

Permalink
Threadsafe Context
Browse files Browse the repository at this point in the history
  • Loading branch information
jbelkins committed Nov 13, 2024
1 parent a7f1f8e commit 6896502
Show file tree
Hide file tree
Showing 7 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Package.version.next
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.39
1.0.38
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public struct Sha256TreeHashMiddleware<OperationStackInput, OperationStackOutput
if let treeHash = treeHash, let linearHash = linearHash {
builder.withHeader(name: X_AMZ_SHA256_TREE_HASH_HEADER_NAME, value: treeHash)
// provide the value but let CRT add the SHA256 header during signing
context.attributes.set(key: AttributeKey(name: X_AMZ_CONTENT_SHA256_HEADER_NAME), value: linearHash)
context.set(key: AttributeKey(name: X_AMZ_CONTENT_SHA256_HEADER_NAME), value: linearHash)
}
case .noStream:
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ private extension String {

public extension Context {
var businessMetrics: Dictionary<String, String> {
get { attributes.get(key: businessMetricsKey) ?? [:] }
get { get(key: businessMetricsKey) ?? [:] }
set(newPair) {
var combined = businessMetrics
combined.merge(newPair) { (_, new) in new }
attributes.set(key: businessMetricsKey, value: combined)
set(key: businessMetricsKey, value: combined)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class RulesBasedAuthSchemeResolverGenerator {
}

// Get endpoint param from middleware context
openBlock("guard let endpointParam = context.attributes.get(key: \$N<EndpointParams>(name: \"EndpointParams\")) else {", "}", SmithyTypes.AttributeKey) {
openBlock("guard let endpointParam = context.get(key: \$N<EndpointParams>(name: \"EndpointParams\")) else {", "}", SmithyTypes.AttributeKey) {
write("throw \$N.dataNotFound(\"Endpoint param not configured in middleware context for rules-based auth scheme resolver params construction.\")", SmithyTypes.ClientError)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class OperationEndpointResolverMiddleware(

// Write code that saves endpoint params to middleware context for use in auth scheme middleware when using rules-based auth scheme resolvers
if (AuthSchemeResolverGenerator.usesRulesBasedAuthResolver(ctx)) {
writer.write("context.attributes.set(key: \$N<EndpointParams>(name: \"EndpointParams\"), value: endpointParams)", SmithyTypes.AttributeKey)
writer.write("context.set(key: \$N<EndpointParams>(name: \"EndpointParams\"), value: endpointParams)", SmithyTypes.AttributeKey)
}

super.renderSpecific(ctx, writer, op, operationStackName, "applyEndpoint")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ extension PutObjectInput {
builder.retryErrorInfoProvider(AWSClientRuntime.AWSRetryErrorInfoProvider.errorInfo(for:))
builder.applySigner(ClientRuntime.SignerMiddleware<PutObjectOutput>())
let endpointParams = EndpointParams()
context.attributes.set(key: Smithy.AttributeKey<EndpointParams>(name: "EndpointParams"), value: endpointParams)
context.set(key: Smithy.AttributeKey<EndpointParams>(name: "EndpointParams"), value: endpointParams)
builder.applyEndpoint(AWSClientRuntime.EndpointResolverMiddleware<PutObjectOutput, EndpointParams>(endpointResolverBlock: { [config] in try config.endpointResolver.resolve(params: ${'$'}0) }, endpointParams: endpointParams))
builder.interceptors.add(AWSClientRuntime.UserAgentMiddleware<PutObjectInput, PutObjectOutput>(serviceID: serviceName, version: S3Client.version, config: config))
builder.selectAuthScheme(ClientRuntime.AuthSchemeMiddleware<PutObjectOutput>())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public struct DefaultS3AuthSchemeResolver: S3AuthSchemeResolver {
guard let opName = context.getOperation() else {
throw Smithy.ClientError.dataNotFound("Operation name not configured in middleware context for auth scheme resolver params construction.")
}
guard let endpointParam = context.attributes.get(key: Smithy.AttributeKey<EndpointParams>(name: "EndpointParams")) else {
guard let endpointParam = context.get(key: Smithy.AttributeKey<EndpointParams>(name: "EndpointParams")) else {
throw Smithy.ClientError.dataNotFound("Endpoint param not configured in middleware context for rules-based auth scheme resolver params construction.")
}
return S3AuthSchemeResolverParameters(operation: opName)
Expand Down

0 comments on commit 6896502

Please sign in to comment.