Skip to content

feat: Add Bedrock API key support #951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jul 29, 2025
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 @@ -16,6 +16,12 @@ extension Context {
public func getAuthSchemePreference() -> [String]? {
get(key: authSchemePreferenceKey)
}

/// The auth scheme preferences for authenticating this request.
public var authSchemePreference: [String]? {
get { getAuthSchemePreference() }
set { set(key: authSchemePreferenceKey, value: newValue) }
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Bedrock API Key customization needs to alter the configured auth scheme preference order, hence a setter is provided

}

extension ContextBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ extension Context {
public func getIdentityResolvers() -> Attributes? {
get(key: identityResolversKey)
}

public func addIdentityResolver<T: IdentityResolver>(value: T, schemeID: String) {
var identityResolvers: Attributes = get(key: identityResolversKey) ?? Attributes()
identityResolvers.set(key: AttributeKey<any IdentityResolver>(name: schemeID), value: value)
set(key: identityResolversKey, value: identityResolvers)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Bedrock API Key customization needs to add an identity resolver after they have been set, hence this method is provided

}

extension ContextBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ abstract class HTTPBindingProtocolGenerator(
operationMiddleware.appendMiddleware(operation, RetryMiddleware(ctx.model, ctx.symbolProvider, retryErrorInfoProviderSymbol))
operationMiddleware.appendMiddleware(operation, SignerMiddleware(ctx.model, ctx.symbolProvider))
addProtocolSpecificMiddleware(ctx, operation)
addServiceSpecificMiddleware(ctx, operation)
operationMiddleware.appendMiddleware(operation, AuthSchemeMiddleware(ctx.model, ctx.symbolProvider))
for (integration in ctx.integrations) {
integration.customizeMiddleware(ctx, operation, operationMiddleware)
Expand Down Expand Up @@ -482,6 +483,13 @@ abstract class HTTPBindingProtocolGenerator(
operation: OperationShape,
)

protected open fun addServiceSpecificMiddleware(
ctx: ProtocolGenerator.GenerationContext,
operation: OperationShape,
) {
// No operation. Override in subclasses to install per-service custom middleware/interceptors.
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This provides a customization point for aws-sdk-swift to add in custom middleware based on the service that is being generated.

protected abstract fun addUserAgentMiddleware(
ctx: ProtocolGenerator.GenerationContext,
operation: OperationShape,
Expand Down
Loading