Skip to content

Commit

Permalink
Add parameters for StsWebIdentity (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
waahm7 authored Sep 26, 2023
1 parent b49aea3 commit d470acc
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -383,12 +383,20 @@ extension CredentialsProvider.Source {
/// - bootstrap: Connection bootstrap to use for any network connections made while sourcing credentials.
/// - tlsContext: Client TLS context to use when querying STS web identity provider.
/// - fileBasedConfiguration: The file based configuration to read the configuration from.
/// - region: (Optional) region override
/// - roleArn: (Optional) roleArn override
/// - roleSessionName: (Optional) roleSessionName override
/// - tokenFilePath: (Optional) tokenFilePath override
/// - shutdownCallback: (Optional) shutdown callback
/// - Returns: `CredentialsProvider`
/// - Throws: CommonRuntimeError.crtError
public static func `stsWebIdentity`(bootstrap: ClientBootstrap,
tlsContext: TLSContext,
fileBasedConfiguration: FileBasedConfiguration,
region: String? = nil,
roleArn: String? = nil,
roleSessionName: String? = nil,
tokenFilePath: String? = nil,
shutdownCallback: ShutdownCallback? = nil) -> Self {
Self {
let shutdownCallbackCore = ShutdownCallbackCore(shutdownCallback)
Expand All @@ -397,9 +405,18 @@ extension CredentialsProvider.Source {
stsOptions.tls_ctx = tlsContext.rawValue
stsOptions.config_profile_collection_cached = fileBasedConfiguration.rawValue
stsOptions.shutdown_options = shutdownCallbackCore.getRetainedCredentialProviderShutdownOptions()

guard let provider = aws_credentials_provider_new_sts_web_identity(allocator.rawValue,
&stsOptions)
guard let provider: UnsafeMutablePointer<aws_credentials_provider> = withByteCursorFromStrings(
region,
roleArn,
roleSessionName,
tokenFilePath, { regionCursor, roleArnCursor, roleSessionNameCursor, tokenFilePathCursor in
stsOptions.region = regionCursor
stsOptions.role_arn = roleArnCursor
stsOptions.role_session_name = roleSessionNameCursor
stsOptions.token_file_path = tokenFilePathCursor
return aws_credentials_provider_new_sts_web_identity(allocator.rawValue,
&stsOptions)
})
else {
shutdownCallbackCore.release()
throw CommonRunTimeError.crtError(CRTError.makeFromLastError())
Expand Down
22 changes: 22 additions & 0 deletions Source/AwsCommonRuntimeKit/crt/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,25 @@ func withByteCursorFromStrings<Result>(
}
}
}

func withByteCursorFromStrings<Result>(
_ arg1: String?,
_ arg2: String?,
_ arg3: String?,
_ arg4: String?,
_ body: (aws_byte_cursor, aws_byte_cursor, aws_byte_cursor, aws_byte_cursor) -> Result
) -> Result {
return withOptionalCString(to: arg1) { arg1C in
return withOptionalCString(to: arg2) { arg2C in
return withOptionalCString(to: arg3) {arg3c in
return withOptionalCString(to: arg4) {arg4c in
return body(
aws_byte_cursor_from_c_str(arg1C),
aws_byte_cursor_from_c_str(arg2C),
aws_byte_cursor_from_c_str(arg3c),
aws_byte_cursor_from_c_str(arg4c))
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,17 @@ class CredentialsProviderTests: XCBaseTestCase {
tlsContext: getTlsContext(),
fileBasedConfiguration: FileBasedConfiguration()))
)

}

func testCreateDestroyStsWebIdentity() async throws {
_ = try! CredentialsProvider(source: .stsWebIdentity(
bootstrap: getClientBootstrap(),
tlsContext: getTlsContext(),
fileBasedConfiguration: FileBasedConfiguration(),
region: "region",
roleArn: "roleArn",
roleSessionName: "roleSessionName",
tokenFilePath: "tokenFilePath"))
}

func testCreateDestroyStsInvalidRole() async throws {
Expand Down
2 changes: 1 addition & 1 deletion aws-common-runtime/aws-c-common
2 changes: 1 addition & 1 deletion aws-common-runtime/aws-c-event-stream
2 changes: 1 addition & 1 deletion aws-common-runtime/s2n
Submodule s2n updated 132 files

0 comments on commit d470acc

Please sign in to comment.