-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Include generated AuthTokenGenerator wrapper class for reference to r…
…eviewers
- Loading branch information
Sichan Yoo
committed
Dec 26, 2024
1 parent
635a500
commit e340c38
Showing
1 changed file
with
63 additions
and
0 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
Sources/Services/AWSRDS/Sources/AWSRDS/AuthTokenGenerator.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// | ||
// Copyright Amazon.com Inc. or its affiliates. | ||
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
// Code generated by smithy-swift-codegen. DO NOT EDIT! | ||
|
||
|
||
|
||
@_spi(AuthTokenGenerator) import class AWSClientRuntime.AuthTokenGenerator | ||
import SmithyIdentity | ||
import struct Foundation.TimeInterval | ||
|
||
/// A utility class with a single utility method that generates IAM authentication token used for connecting to RDS. | ||
public class AuthTokenGenerator { | ||
private let generator: AWSClientRuntime.AuthTokenGenerator | ||
|
||
/// The initializer that takes in AWSCredentialIdentity struct to use to generate the IAM authentication token. | ||
public init(awsCredentialIdentity: AWSCredentialIdentity) { | ||
self.generator = AWSClientRuntime.AuthTokenGenerator(awsCredentialIdentity: awsCredentialIdentity) | ||
} | ||
|
||
/// The initializer that takes in a specific AWSCredentialIdentityResolver, used to resolve the AWSCredentialIdentity used to generate the IAM authentication token. | ||
public init(awsCredentialIdentityResolver: any AWSCredentialIdentityResolver) async throws { | ||
self.generator = try await AWSClientRuntime.AuthTokenGenerator(awsCredentialIdentityResolver: awsCredentialIdentityResolver) | ||
} | ||
|
||
/// Updates the AWS credentials used to generate the IAM auth token. | ||
public func updateCredentials(newAWSCredentialIdentity: AWSCredentialIdentity) { | ||
generator.updateCredentials(newAWSCredentialIdentity: newAWSCredentialIdentity) | ||
} | ||
|
||
/// Updates the AWS credentials used to generate the IAM auth token by resolving credentials from passed in resolver. | ||
public func updateCredentials(awsCredentialIdentityResolver: any AWSCredentialIdentityResolver) async throws { | ||
try await generator.updateCredentials(awsCredentialIdentityResolver: awsCredentialIdentityResolver) | ||
} | ||
|
||
/// Generates authenetication token using given inputs to the method and credential identity instance variable. | ||
/// | ||
/// - Parameters: | ||
/// - endpoint: The endpoint of the RDS instance. E.g., `rdsmysql.123456789012.us-west-2.rds.amazonaws.com` | ||
/// - port: The port of the RDS instance to connect to. E.g., `3306` | ||
/// - region: The region that RDS instance is located in. E.g., `us-west-2` | ||
/// - username: The username of the RDS database user. E.g., `admin` | ||
/// - expiration: The expiration for the token in seconds. Default is 900 seconds (15 minutes). | ||
public func generateAuthToken( | ||
endpoint: String, | ||
port: Int16, | ||
region: String, | ||
username: String, | ||
expiration: TimeInterval = 900 | ||
) async throws -> String { | ||
return try await generator.generateAuthToken( | ||
endpoint: endpoint, | ||
port: port, | ||
region: region, | ||
username: username, | ||
expiration: expiration | ||
) | ||
} | ||
} |