Skip to content

Commit

Permalink
feat: Update CRT to 0.5.0+ (#777)
Browse files Browse the repository at this point in the history
* Updates CRT to 0.5.0

* Updates CRT to 0.5.0

* Bumps CRT to 0.5.2

* Updates tests

* Cleans up and adds tests

* Adds tests

* Addresses PR feedback

* Logs when we fail to resolve a region

* Updates codegen tests

* Updates codegen and error models

* Updates codegen
  • Loading branch information
epau authored Jan 4, 2023
1 parent b62fb99 commit 6dd1d5a
Show file tree
Hide file tree
Showing 47 changed files with 418 additions and 522 deletions.
22 changes: 15 additions & 7 deletions AWSClientRuntime/Sources/Auth/AWSCredentials.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@
//

import AwsCommonRuntimeKit
import Foundation

public struct AWSCredentials {
let accessKey: String
let secret: String
let expirationTimeout: UInt64
let expirationTimeout: Date?
let sessionToken: String?

public init(accessKey: String, secret: String, expirationTimeout: UInt64, sessionToken: String? = nil) {
public init(
accessKey: String,
secret: String,
expirationTimeout: Date? = nil,
sessionToken: String? = nil
) {
self.accessKey = accessKey
self.secret = secret
self.expirationTimeout = expirationTimeout
Expand All @@ -22,10 +28,12 @@ public struct AWSCredentials {
}

extension AWSCredentials {
func toCRTType() -> CRTCredentials {
return CRTCredentials(accessKey: accessKey,
secret: secret,
sessionToken: sessionToken,
expirationTimeout: expirationTimeout)
func toCRTType() throws -> Credentials {
return try Credentials(
accessKey: accessKey,
secret: secret,
sessionToken: sessionToken,
expiration: expirationTimeout
)
}
}
82 changes: 58 additions & 24 deletions AWSClientRuntime/Sources/Auth/AWSCredentialsProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,89 +6,123 @@ import AwsCommonRuntimeKit
import ClientRuntime

public class AWSCredentialsProvider: CredentialsProvider {
let crtCredentialsProvider: CRTAWSCredentialsProvider
private let sharedDefaultIO: SDKDefaultIO = SDKDefaultIO.shared
let crtCredentialsProvider: AwsCommonRuntimeKit.CredentialsProvider

init(awsCredentialsProvider: CRTAWSCredentialsProvider) {
init(awsCredentialsProvider: AwsCommonRuntimeKit.CredentialsProvider) {
self.crtCredentialsProvider = awsCredentialsProvider
}

public static func fromEnv() throws -> AWSCredentialsProvider {
let credsProvider = try CRTAWSCredentialsProvider(fromEnv: nil)
let credsProvider = try AwsCommonRuntimeKit.CredentialsProvider(source: .environment())
return AWSCredentialsProvider(awsCredentialsProvider: credsProvider)
}

public static func fromProfile(
_ options: AWSCredentialsProviderProfileOptions = AWSCredentialsProviderProfileOptions()
) throws -> AWSCredentialsProvider {
let credsProvider = try CRTAWSCredentialsProvider(fromProfile: options.toCRTType())
let credsProvider = try AwsCommonRuntimeKit.CredentialsProvider(source: .profile(
configFileNameOverride: options.configFileNameOverride,
profileFileNameOverride: options.profileFileNameOverride,
credentialsFileNameOverride: options.credentialsFileNameOverride,
shutdownCallback: options.shutdownCallback
))
return AWSCredentialsProvider(awsCredentialsProvider: credsProvider)
}

public static func fromStatic(_ config: AWSCredentialsProviderStaticConfig) throws -> AWSCredentialsProvider {
let credsProvider = try CRTAWSCredentialsProvider(fromStatic: config.toCRTType())
let credsProvider = try AwsCommonRuntimeKit.CredentialsProvider(source: .static(
accessKey: config.accessKey,
secret: config.secret,
sessionToken: config.sessionToken,
shutdownCallback: config.shutDownCallback
))
return AWSCredentialsProvider(awsCredentialsProvider: credsProvider)
}

public static func fromStatic(_ credentials: AWSCredentials) throws -> AWSCredentialsProvider {
let config = AWSCredentialsProviderStaticConfig(
let credsProvider = try AwsCommonRuntimeKit.CredentialsProvider(source: .static(
accessKey: credentials.accessKey,
secret: credentials.secret,
sessionToken: credentials.sessionToken
)
let credsProvider = try CRTAWSCredentialsProvider(fromStatic: config.toCRTType())
))
return AWSCredentialsProvider(awsCredentialsProvider: credsProvider)
}

public static func fromWebIdentity(shutDownCallback: ShutDownCallback? = nil) throws -> AWSCredentialsProvider {
let config = AWSCredentialsProviderWebIdentityConfig(shutDownCallback: shutDownCallback)
let credsProvider = try CRTAWSCredentialsProvider(fromWebIdentity: config.toCRTType())
let config = try AWSCredentialsProviderWebIdentityConfig(shutDownCallback: shutDownCallback)
let credsProvider = try AwsCommonRuntimeKit.CredentialsProvider(source: .stsWebIdentity(
bootstrap: SDKDefaultIO.shared.clientBootstrap,
tlsContext: SDKDefaultIO.shared.tlsContext,
shutdownCallback: config.shutDownCallback
))
return AWSCredentialsProvider(awsCredentialsProvider: credsProvider)
}

public static func fromSTS(_ config: AWSCredentialsProviderSTSConfig) throws -> AWSCredentialsProvider {
let stsConfig = config.toCRTType()
let credsProvider = try CRTAWSCredentialsProvider(fromSTS: stsConfig)
let credsProvider = try AwsCommonRuntimeKit.CredentialsProvider(source: .sts(
bootstrap: SDKDefaultIO.shared.clientBootstrap,
tlsContext: SDKDefaultIO.shared.tlsContext,
credentialsProvider: config.credentialsProvider.crtCredentialsProvider,
roleArn: config.roleArn,
sessionName: config.sessionName,
duration: config.durationSeconds,
shutdownCallback: config.shutDownCallback
))
return AWSCredentialsProvider(awsCredentialsProvider: credsProvider)
}

public static func fromContainer(
_ config: AWSCredentialsProviderContainerConfig
) throws -> AWSCredentialsProvider {
let containerConfig = config.toCRTType()
let credsProvider = try CRTAWSCredentialsProvider(fromContainer: containerConfig)
let credsProvider = try AwsCommonRuntimeKit.CredentialsProvider(source: .ecs(
bootstrap: SDKDefaultIO.shared.clientBootstrap,
tlsContext: SDKDefaultIO.shared.tlsContext,
authToken: config.authToken,
pathAndQuery: config.pathAndQuery,
host: config.host,
shutdownCallback: config.shutDownCallback
))
return AWSCredentialsProvider(awsCredentialsProvider: credsProvider)
}

public static func fromCached(_ config: AWSCredentialsProviderCachedConfig) throws -> AWSCredentialsProvider {
var cachedConfig = config.toCRTType()
let credsProvider = try CRTAWSCredentialsProvider(fromCached: &cachedConfig)
let credsProvider = try AwsCommonRuntimeKit.CredentialsProvider(source: .cached(
source: config.source.crtCredentialsProvider,
refreshTime: config.refreshTime,
shutdownCallback: config.shutDownCallback
))
return AWSCredentialsProvider(awsCredentialsProvider: credsProvider)
}

public static func fromChain(shutDownCallback: ShutDownCallback? = nil) throws -> AWSCredentialsProvider {
let config = AWSCredentialsProviderChainDefaultConfig(shutDownCallback: shutDownCallback)
let credsProvider = try CRTAWSCredentialsProvider(fromChainDefault: config.toCRTType())
let credsProvider = try AwsCommonRuntimeKit.CredentialsProvider(source: .defaultChain(
bootstrap: SDKDefaultIO.shared.clientBootstrap,
shutdownCallback: config.shutDownCallback
))
return AWSCredentialsProvider(awsCredentialsProvider: credsProvider)
}

public static func fromCustom(_ credentialsProvider: CredentialsProvider) throws -> AWSCredentialsProvider {
let crtCredentialsProviderWrapper = CredentialsProviderCRTAdapter(credentialsProvider: credentialsProvider)
let credsProvider = try CRTAWSCredentialsProvider(fromProvider: crtCredentialsProviderWrapper)
let credsProvider = try AwsCommonRuntimeKit.CredentialsProvider(provider: crtCredentialsProviderWrapper)
return AWSCredentialsProvider(awsCredentialsProvider: credsProvider)
}

public func getCredentials() async throws -> AWSCredentials {
let crtCredentials = try await crtCredentialsProvider.getCredentials()

guard let accessKey = crtCredentials.getAccessKey(),
let secret = crtCredentials.getSecret() else {
throw ClientError.authError("Unable to get credentials. Required: accessKey, secret.")
}
guard
let accessKey = crtCredentials.getAccessKey(),
let secret = crtCredentials.getSecret()
else {
throw ClientError.authError("Unable to get credentials. Required: accessKey, secret.")
}

return AWSCredentials(
accessKey: accessKey,
secret: secret,
expirationTimeout: crtCredentials.getExpirationTimeout(),
expirationTimeout: crtCredentials.getExpiration(),
sessionToken: crtCredentials.getSessionToken()
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,10 @@
// SPDX-License-Identifier: Apache-2.0
//
import AwsCommonRuntimeKit
import Foundation

public struct AWSCredentialsProviderCachedConfig {
public let shutDownCallback: ShutDownCallback?
public let source: AWSCredentialsProvider
public let refreshTime: Int
}

extension AWSCredentialsProviderCachedConfig {
func toCRTType() -> CRTCredentialsProviderCachedConfig {
return CredentialsProviderCachedConfig(
source: source,
refreshTime: Int64(refreshTime),
shutDownOptions: shutDownCallback
)
}
}

struct CredentialsProviderCachedConfig: CRTCredentialsProviderCachedConfig {
var shutDownOptions: CRTCredentialsProviderShutdownOptions?

var source: CRTAWSCredentialsProvider

var refreshTime: Int64

init(
source: AWSCredentialsProvider,
refreshTime: Int64,
shutDownOptions: ShutDownCallback? = nil
) {
self.source = source.crtCredentialsProvider
self.refreshTime = refreshTime
}
public let refreshTime: TimeInterval
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,9 @@ import ClientRuntime

public struct AWSCredentialsProviderChainDefaultConfig {
let shutDownCallback: ShutDownCallback?
private let sharedDefaultIO: SDKDefaultIO = SDKDefaultIO.shared

public init(shutDownCallback: ShutDownCallback? = nil) {
self.shutDownCallback = shutDownCallback
}
}

extension AWSCredentialsProviderChainDefaultConfig {
func toCRTType() -> CRTCredentialsProviderChainDefaultConfig {
return CredentialsProviderChainDefaultConfig(
bootstrap: SDKDefaultIO.shared.clientBootstrap,
shutDownOptions: shutDownCallback
)
}
}

struct CredentialsProviderChainDefaultConfig: CRTCredentialsProviderChainDefaultConfig {
var shutDownOptions: CRTCredentialsProviderShutdownOptions?

var bootstrap: ClientBootstrap

init(bootstrap: ClientBootstrap, shutDownOptions: ShutDownCallback? = nil) {
self.bootstrap = bootstrap
if let shutDownOptions = shutDownOptions {
self.shutDownOptions = CRTCredentialsProviderShutdownOptions(shutDownCallback: shutDownOptions)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,20 @@ import AwsCommonRuntimeKit
import ClientRuntime

public struct AWSCredentialsProviderContainerConfig {
public let authToken: String?
public let host: String?
public let pathAndQuery: String?
public let authToken: String
public let host: String
public let pathAndQuery: String
public let shutDownCallback: ShutDownCallback?
private let sharedDefaultIO: SDKDefaultIO = SDKDefaultIO.shared

init(authToken: String? = nil,
host: String? = nil,
pathAndQuery: String? = nil,
shutDownCallback: ShutDownCallback? = nil) {
init(
authToken: String,
host: String,
pathAndQuery: String,
shutDownCallback: ShutDownCallback? = nil
) throws {
self.authToken = authToken
self.host = host
self.pathAndQuery = pathAndQuery
self.shutDownCallback = shutDownCallback
}
}

extension AWSCredentialsProviderContainerConfig {
func toCRTType() -> CredentialsProviderContainerConfig {
return CredentialsProviderContainerConfig(bootstrap: SDKDefaultIO.shared.clientBootstrap,
tlsContext: SDKDefaultIO.shared.tlsContext,
authToken: authToken,
pathAndQuery: pathAndQuery,
host: host,
shutDownOptions: shutDownCallback)
}
}

struct CredentialsProviderContainerConfig: CRTCredentialsProviderContainerConfig {
var bootstrap: ClientBootstrap
var tlsContext: TlsContext
var authToken: String?
var pathAndQuery: String?
var host: String?
var shutDownOptions: CRTCredentialsProviderShutdownOptions?

init(bootstrap: ClientBootstrap,
tlsContext: TlsContext,
authToken: String? = nil,
pathAndQuery: String? = nil,
host: String? = nil,
shutDownOptions: ShutDownCallback? = nil) {
self.bootstrap = bootstrap
self.tlsContext = tlsContext
self.authToken = authToken
self.pathAndQuery = pathAndQuery
self.host = host
if let shutDownOptions = shutDownOptions {
self.shutDownOptions = CRTCredentialsProviderShutdownOptions(shutDownCallback: shutDownOptions)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,44 +17,15 @@ public struct AWSCredentialsProviderProfileOptions {

public let credentialsFileNameOverride: String?

public init(configFileNameOverride: String? = nil,
profileFileNameOverride: String? = nil,
credentialsFileNameOverride: String? = nil,
shutdownCallback: ShutDownCallback? = nil) {
public init(
configFileNameOverride: String? = nil,
profileFileNameOverride: String? = nil,
credentialsFileNameOverride: String? = nil,
shutdownCallback: ShutDownCallback? = nil
) {
self.configFileNameOverride = configFileNameOverride
self.profileFileNameOverride = profileFileNameOverride
self.credentialsFileNameOverride = credentialsFileNameOverride
self.shutdownCallback = shutdownCallback
}
}

extension AWSCredentialsProviderProfileOptions {
func toCRTType() -> CredentialsProviderProfileOptions {
return CredentialsProviderProfileOptions(configFileNameOverride: configFileNameOverride,
profileFileNameOverride: profileFileNameOverride,
credentialsFileNameOverride: credentialsFileNameOverride,
shutdownOptions: shutdownCallback)
}
}

struct CredentialsProviderProfileOptions: CRTCredentialsProviderProfileOptions {
var shutdownOptions: CRTCredentialsProviderShutdownOptions?

var configFileNameOverride: String?

var profileFileNameOverride: String?

var credentialsFileNameOverride: String?

init(configFileNameOverride: String? = nil,
profileFileNameOverride: String? = nil,
credentialsFileNameOverride: String? = nil,
shutdownOptions: ShutDownCallback? = nil) {
self.configFileNameOverride = configFileNameOverride
self.profileFileNameOverride = profileFileNameOverride
self.credentialsFileNameOverride = credentialsFileNameOverride
if let shutdownOptions = shutdownOptions {
self.shutdownOptions = CRTCredentialsProviderShutdownOptions(shutDownCallback: shutdownOptions)
}
}
}
Loading

0 comments on commit 6dd1d5a

Please sign in to comment.