|
16 | 16 | import AWSSDKIdentity |
17 | 17 | import Logging |
18 | 18 |
|
| 19 | +// for setenv and unsetenv functions |
| 20 | +#if os(Linux) |
| 21 | +import Glibc |
| 22 | +#else |
| 23 | +import Darwin.C |
| 24 | +#endif |
| 25 | + |
19 | 26 | #if canImport(FoundationEssentials) |
20 | 27 | import FoundationEssentials |
21 | 28 | #else |
@@ -60,18 +67,22 @@ extension BedrockAuthentication { |
60 | 67 | // to create AWS credentials |
61 | 68 | do { |
62 | 69 | logger.trace("Creating identity resolver using web identity token") |
63 | | - let identityResolver = try STSWebIdentityAWSCredentialIdentityResolver( |
64 | | - region: region.rawValue, |
65 | | - roleArn: roleARN, |
66 | | - roleSessionName: "SwiftBedrockService-\(UUID().uuidString)", |
67 | | - tokenFilePath: tokenFilePath |
68 | | - ) |
| 70 | + setenv("AWS_REGION", region.rawValue, 1) |
| 71 | + setenv("AWS_ROLE_ARN", roleARN, 1) |
| 72 | + setenv("AWS_ROLE_SESSION_NAME", "SwiftBedrockService-\(UUID().uuidString)", 1) |
| 73 | + setenv("AWS_WEB_IDENTITY_TOKEN_FILE", tokenFilePath, 1) |
| 74 | + let identityResolver = STSWebIdentityAWSCredentialIdentityResolver(source: .env) |
69 | 75 |
|
70 | 76 | // Test the resolver by retrieving credentials to ensure it works |
71 | 77 | logger.trace("Retrieving credentials using web identity token") |
72 | | - _ = try await identityResolver.crtAWSCredentialIdentityResolver.getCredentials() |
| 78 | + _ = try await identityResolver.getIdentity(identityProperties: nil) |
73 | 79 | logger.trace("Successfully retrieved credentials using web identity token") |
74 | 80 |
|
| 81 | + unsetenv("AWS_REGION") |
| 82 | + unsetenv("AWS_ROLE_ARN") |
| 83 | + unsetenv("AWS_ROLE_SESSION_NAME") |
| 84 | + unsetenv("AWS_WEB_IDENTITY_TOKEN_FILE") |
| 85 | + |
75 | 86 | // Notify observers, if any |
76 | 87 | logger.trace("Notifying observers of credentials update") |
77 | 88 | await MainActor.run { |
|
0 commit comments