Skip to content

Commit 6c9f6b6

Browse files
authored
fix api keys errors introduced by latest AWS SDK (#34)
* fix api keys errors introduced by latest AWS SDK * swift -format * fix typo
1 parent 76606f2 commit 6c9f6b6

File tree

6 files changed

+10
-19
lines changed

6 files changed

+10
-19
lines changed

Package.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ let package = Package(
1111
],
1212
dependencies: [
1313
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.6.1"),
14-
.package(url: "https://github.com/awslabs/aws-sdk-swift", from: "1.3.50"),
15-
.package(url: "https://github.com/smithy-lang/smithy-swift", from: "0.145.0"),
16-
.package(url: "https://github.com/apple/swift-log.git", from: "1.6.3"),
17-
.package(url: "https://github.com/awslabs/aws-crt-swift", from: "0.52.0"),
14+
.package(url: "https://github.com/awslabs/aws-sdk-swift", from: "1.5.16"),
15+
.package(url: "https://github.com/smithy-lang/smithy-swift", from: "0.152.0"),
16+
.package(url: "https://github.com/apple/swift-log.git", from: "1.6.4"),
17+
.package(url: "https://github.com/awslabs/aws-crt-swift", from: "0.52.1"),
1818
],
1919
targets: [
2020
.target(

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ let bedrock = try await BedrockService(
146146
)
147147
```
148148

149-
As usual, do not store or hardcode API Keys in yoru front end application.
149+
As usual, do not store or hardcode API Keys in your front end application.
150150

151151
### Static Credentials Authentication
152152

Sources/BedrockAuthentication.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public enum BedrockAuthentication: Sendable, CustomStringConvertible {
6666
case .default, .apiKey(_):
6767
return nil //TODO should we throw an error when apiKey is used ?
6868
case .profile(let profileName):
69-
return try? ProfileAWSCredentialIdentityResolver(profileName: profileName)
69+
return ProfileAWSCredentialIdentityResolver(profileName: profileName)
7070
case .sso(let profileName):
7171
return try? SSOAWSCredentialIdentityResolver(profileName: profileName)
7272
case .webIdentity(let token, let roleARN, let region, let notification):

Sources/BedrockService.swift

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -176,18 +176,9 @@ public struct BedrockService: Sendable {
176176

177177
// support API keys
178178
if case .apiKey(_) = authentication {
179-
// config.httpClientConfiguration.defaultHeaders.add(
180-
// name: "Authorization",
181-
// value: "Bearer \(key)"
182-
// )
183179
if let bearerTokenIdentityresolver = authentication.getBearerTokenIdentityResolver(logger: logger) {
184180
config.bearerTokenIdentityResolver = bearerTokenIdentityresolver
185-
186-
// force utilisation of a bearer token instead of AWS credentials + Signv4
187-
// see https://github.com/awslabs/aws-sdk-swift/blob/15b8951d108968f767f4199a3c011e27ac519d61/Sources/Services/AWSBedrockRuntime/Sources/AWSBedrockRuntime/AuthSchemeResolver.swift#L58
188-
config.authSchemeResolver = DefaultBedrockRuntimeAuthSchemeResolver(authSchemePreference: [
189-
"httpBearerAuth"
190-
])
181+
config.authSchemePreference = ["httpBearerAuth"]
191182
} else {
192183
// TODO: should we throw an error here ?
193184
logger.error(

Sources/Protocols/BedrockConfigProtocol.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ protocol BedrockConfigProtocol {
2525

2626
// support bearer token authentication (for API Keys)
2727
var bearerTokenIdentityResolver: any SmithyIdentity.BearerTokenIdentityResolver { get set }
28-
var authSchemeResolver: SmithyHTTPAuthAPI.AuthSchemeResolver { get set }
28+
var authSchemePreference: [String]? { get set }
2929

3030
// not used at the moment, we use the bearer token instead
3131
//var httpClientConfiguration: ClientRuntime.HttpClientConfiguration { get set }

Tests/AuthenticationTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,8 @@ extension BedrockServiceTests {
106106
#expect(token == testApiKey, "Expected token to match the API key")
107107

108108
// check bearer auth scheme
109-
let authScheme = (config.authSchemeResolver as? DefaultBedrockRuntimeAuthSchemeResolver)?.authSchemePreference
110-
#expect(authScheme?.contains("httpBearerAuth") == true, "Expected auth scheme to be HTTP Bearer")
109+
let authSchemePreference = config.authSchemePreference
110+
#expect(authSchemePreference?.contains("httpBearerAuth") == true, "Expected auth scheme to be HTTP Bearer")
111111

112112
}
113113

0 commit comments

Comments
 (0)