From 6c2bb49b17075ee969886ba0ba1aaebf3624daaf Mon Sep 17 00:00:00 2001 From: Ed Paulosky Date: Wed, 21 Dec 2022 11:09:43 -0500 Subject: [PATCH 01/13] Updates CRT to 0.5.0 --- packageDependencies.plist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packageDependencies.plist b/packageDependencies.plist index 48fef84b459..c8be435719f 100644 --- a/packageDependencies.plist +++ b/packageDependencies.plist @@ -5,7 +5,7 @@ clientRuntimeVersion 0.7.0 awsCRTSwiftVersion - 0.4.0 + 0.5.0 clientRuntimeBranch main awsCRTSwiftBranch From 052a43a8de831d66dab0f86d2b92b950ea62cde5 Mon Sep 17 00:00:00 2001 From: Ed Paulosky Date: Wed, 21 Dec 2022 16:02:08 -0500 Subject: [PATCH 02/13] Updates CRT to 0.5.0 --- .../Sources/Auth/AWSCredentials.swift | 22 +++-- .../Sources/Auth/AWSCredentialsProvider.swift | 82 +++++++++++++------ .../AWSCredentialsProviderCachedConfig.swift | 30 +------ ...redentialsProviderChainDefaultConfig.swift | 22 ----- ...WSCredentialsProviderContainerConfig.swift | 53 ++---------- ...AWSCredentialsProviderProfileOptions.swift | 41 ++-------- .../AWSCredentialsProviderSTSConfig.swift | 56 ++----------- .../AWSCredentialsProviderStaticConfig.swift | 43 ++-------- ...CredentialsProviderWebIdentityConfig.swift | 29 +------ .../Auth/CredentialsProviderCRTAdapter.swift | 6 +- AWSClientRuntime/Sources/Config/Profile.swift | 4 +- .../Sources/Config/ProfileCollection.swift | 2 +- .../AWSEndpointsRequestContext.swift | 6 +- .../AWSEndpointsResolvedEndpoint.swift | 42 +++++++--- .../AWSEndpointsResolvedEndpointType.swift | 2 +- .../Endpoints/AWSEndpointsRuleEngine.swift | 9 +- .../Sources/IMDS/IMDSClient.swift | 13 ++- .../Sources/IMDS/IMDSConfig.swift | 9 -- .../Sha256TreeHashMiddleware.swift | 39 +++------ .../Sources/Middlewares/SigV4Middleware.swift | 30 ++++--- .../PrimitiveExtensions/Data+Extension.swift | 20 +++++ .../PrimitiveExtensions/Date+Extension.swift | 15 ---- .../Protocols/Ec2Query/Ec2QueryError.swift | 2 +- .../Protocols/RestJSON/RestJSONError.swift | 2 +- .../Protocols/RestXML/RestXMLError.swift | 2 +- .../Regions/DefaultRegionResolver.swift | 16 ++-- .../Sources/Regions/IMDSRegionProvider.swift | 4 +- .../Regions/ProfileRegionResolver.swift | 8 +- .../Sources/Signing/AWSSigV4Signer.swift | 55 +++++++------ .../Sources/Signing/AWSSigningConfig.swift | 61 ++++++++------ .../Sources/Signing/SigV4Config.swift | 24 +++--- .../Sources/Signing/SigningFlags.swift | 8 -- .../Auth/AWSCredentialProviderTests.swift | 6 +- .../Errors/ComplexXMLError+ResponseInit.swift | 2 +- .../ComplexXMLErrorNoErrorWrapping+Init.swift | 2 +- .../Errors/InvalidGreeting+ResponseInit.swift | 2 +- .../Tests/Regions/RegionTests.swift | 16 ++-- .../Tests/Sigv4/SigV4SigningTests.swift | 12 ++- .../aws/swift/codegen/AWSServiceConfig.kt | 6 +- ...Ec2QueryHttpResponseTraitWithoutPayload.kt | 2 +- .../AWSXMLHttpResponseTraitWithoutPayload.kt | 2 +- ...yHttpResponseBindingErrorGeneratorTests.kt | 2 +- ...LHttpResponseBindingErrorGeneratorTests.kt | 4 +- 43 files changed, 335 insertions(+), 478 deletions(-) create mode 100644 AWSClientRuntime/Sources/PrimitiveExtensions/Data+Extension.swift delete mode 100644 AWSClientRuntime/Sources/PrimitiveExtensions/Date+Extension.swift diff --git a/AWSClientRuntime/Sources/Auth/AWSCredentials.swift b/AWSClientRuntime/Sources/Auth/AWSCredentials.swift index b57ddd95ceb..c107c9a28d2 100644 --- a/AWSClientRuntime/Sources/Auth/AWSCredentials.swift +++ b/AWSClientRuntime/Sources/Auth/AWSCredentials.swift @@ -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 @@ -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 + ) } } diff --git a/AWSClientRuntime/Sources/Auth/AWSCredentialsProvider.swift b/AWSClientRuntime/Sources/Auth/AWSCredentialsProvider.swift index 1ecdbd136a4..42d8c180ba5 100644 --- a/AWSClientRuntime/Sources/Auth/AWSCredentialsProvider.swift +++ b/AWSClientRuntime/Sources/Auth/AWSCredentialsProvider.swift @@ -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() ) } diff --git a/AWSClientRuntime/Sources/Auth/AWSCredentialsProviderCachedConfig.swift b/AWSClientRuntime/Sources/Auth/AWSCredentialsProviderCachedConfig.swift index dc4d6d21a9a..f291681f664 100644 --- a/AWSClientRuntime/Sources/Auth/AWSCredentialsProviderCachedConfig.swift +++ b/AWSClientRuntime/Sources/Auth/AWSCredentialsProviderCachedConfig.swift @@ -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 } diff --git a/AWSClientRuntime/Sources/Auth/AWSCredentialsProviderChainDefaultConfig.swift b/AWSClientRuntime/Sources/Auth/AWSCredentialsProviderChainDefaultConfig.swift index 5cd97a4cf84..dc95fccc36a 100644 --- a/AWSClientRuntime/Sources/Auth/AWSCredentialsProviderChainDefaultConfig.swift +++ b/AWSClientRuntime/Sources/Auth/AWSCredentialsProviderChainDefaultConfig.swift @@ -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) - } - } -} diff --git a/AWSClientRuntime/Sources/Auth/AWSCredentialsProviderContainerConfig.swift b/AWSClientRuntime/Sources/Auth/AWSCredentialsProviderContainerConfig.swift index dde922d246e..3c8efcc6450 100644 --- a/AWSClientRuntime/Sources/Auth/AWSCredentialsProviderContainerConfig.swift +++ b/AWSClientRuntime/Sources/Auth/AWSCredentialsProviderContainerConfig.swift @@ -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) - } - } -} diff --git a/AWSClientRuntime/Sources/Auth/AWSCredentialsProviderProfileOptions.swift b/AWSClientRuntime/Sources/Auth/AWSCredentialsProviderProfileOptions.swift index 0070593d819..8587651cd86 100644 --- a/AWSClientRuntime/Sources/Auth/AWSCredentialsProviderProfileOptions.swift +++ b/AWSClientRuntime/Sources/Auth/AWSCredentialsProviderProfileOptions.swift @@ -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) - } - } -} diff --git a/AWSClientRuntime/Sources/Auth/AWSCredentialsProviderSTSConfig.swift b/AWSClientRuntime/Sources/Auth/AWSCredentialsProviderSTSConfig.swift index dd4ae9bf915..3717edb9684 100644 --- a/AWSClientRuntime/Sources/Auth/AWSCredentialsProviderSTSConfig.swift +++ b/AWSClientRuntime/Sources/Auth/AWSCredentialsProviderSTSConfig.swift @@ -7,20 +7,22 @@ import AwsCommonRuntimeKit import ClientRuntime +import Foundation public struct AWSCredentialsProviderSTSConfig { public let credentialsProvider: AWSCredentialsProvider public let roleArn: String public let sessionName: String - public let durationSeconds: UInt16 + public let durationSeconds: TimeInterval public let shutDownCallback: ShutDownCallback? - private let sharedDefaultIO: SDKDefaultIO = SDKDefaultIO.shared - public init(credentialsProvider: AWSCredentialsProvider, - roleArn: String, - sessionName: String, - durationSeconds: UInt16, - shutDownCallback: ShutDownCallback? = nil) { + public init( + credentialsProvider: AWSCredentialsProvider, + roleArn: String, + sessionName: String, + durationSeconds: TimeInterval, + shutDownCallback: ShutDownCallback? = nil + ) throws { self.credentialsProvider = credentialsProvider self.roleArn = roleArn self.sessionName = sessionName @@ -28,43 +30,3 @@ public struct AWSCredentialsProviderSTSConfig { self.shutDownCallback = shutDownCallback } } - -extension AWSCredentialsProviderSTSConfig { - func toCRTType() -> CredentialsProviderSTSConfig { - return CredentialsProviderSTSConfig(bootstrap: SDKDefaultIO.shared.clientBootstrap, - tlsContext: SDKDefaultIO.shared.tlsContext, - credentialsProvider: credentialsProvider.crtCredentialsProvider, - roleArn: roleArn, - sessionName: sessionName, - durationSeconds: durationSeconds, - shutDownOptions: shutDownCallback) - } -} - -struct CredentialsProviderSTSConfig: CRTCredentialsProviderSTSConfig { - var bootstrap: ClientBootstrap - var tlsContext: TlsContext - var credentialsProvider: CRTAWSCredentialsProvider - var roleArn: String - var sessionName: String - var durationSeconds: UInt16 - var shutDownOptions: CRTCredentialsProviderShutdownOptions? - - init(bootstrap: ClientBootstrap, - tlsContext: TlsContext, - credentialsProvider: CRTAWSCredentialsProvider, - roleArn: String, - sessionName: String, - durationSeconds: UInt16, - shutDownOptions: ShutDownCallback? = nil) { - self.bootstrap = bootstrap - self.tlsContext = tlsContext - self.credentialsProvider = credentialsProvider - self.roleArn = roleArn - self.sessionName = sessionName - self.durationSeconds = durationSeconds - if let shutDownOptions = shutDownOptions { - self.shutDownOptions = CRTCredentialsProviderShutdownOptions(shutDownCallback: shutDownOptions) - } - } -} diff --git a/AWSClientRuntime/Sources/Auth/AWSCredentialsProviderStaticConfig.swift b/AWSClientRuntime/Sources/Auth/AWSCredentialsProviderStaticConfig.swift index 20ff599370b..379f7d792e0 100644 --- a/AWSClientRuntime/Sources/Auth/AWSCredentialsProviderStaticConfig.swift +++ b/AWSClientRuntime/Sources/Auth/AWSCredentialsProviderStaticConfig.swift @@ -4,7 +4,7 @@ // // SPDX-License-Identifier: Apache-2.0 // - + import AwsCommonRuntimeKit public struct AWSCredentialsProviderStaticConfig { @@ -16,44 +16,15 @@ public struct AWSCredentialsProviderStaticConfig { public let sessionToken: String? - public init(accessKey: String, - secret: String, - sessionToken: String? = nil, - shutDownCallback: ShutDownCallback? = nil) { + public init( + accessKey: String, + secret: String, + sessionToken: String? = nil, + shutDownCallback: ShutDownCallback? = nil + ) { self.accessKey = accessKey self.secret = secret self.sessionToken = sessionToken self.shutDownCallback = shutDownCallback } } - -extension AWSCredentialsProviderStaticConfig { - func toCRTType() -> CredentialsProviderStaticConfig { - return CredentialsProviderStaticConfig(accessKey: accessKey, - secret: secret, - sessionToken: sessionToken, - shutDownOptions: shutDownCallback) - } -} - -struct CredentialsProviderStaticConfig: CRTCredentialsProviderStaticConfigOptions { - var shutDownOptions: CRTCredentialsProviderShutdownOptions? - - var accessKey: String - - var secret: String - - var sessionToken: String? - - init(accessKey: String, - secret: String, - sessionToken: String? = nil, - shutDownOptions: ShutDownCallback? = nil) { - self.accessKey = accessKey - self.secret = secret - self.sessionToken = sessionToken - if let shutDownOptions = shutDownOptions { - self.shutDownOptions = CRTCredentialsProviderShutdownOptions(shutDownCallback: shutDownOptions) - } - } -} diff --git a/AWSClientRuntime/Sources/Auth/AWSCredentialsProviderWebIdentityConfig.swift b/AWSClientRuntime/Sources/Auth/AWSCredentialsProviderWebIdentityConfig.swift index 0209dec12c6..6dd76663d04 100644 --- a/AWSClientRuntime/Sources/Auth/AWSCredentialsProviderWebIdentityConfig.swift +++ b/AWSClientRuntime/Sources/Auth/AWSCredentialsProviderWebIdentityConfig.swift @@ -10,35 +10,8 @@ import ClientRuntime public struct AWSCredentialsProviderWebIdentityConfig { public let shutDownCallback: ShutDownCallback? - private let sharedDefaultIO: SDKDefaultIO = SDKDefaultIO.shared - public init(shutDownCallback: ShutDownCallback? = nil) { + public init(shutDownCallback: ShutDownCallback? = nil) throws { self.shutDownCallback = shutDownCallback } } - -extension AWSCredentialsProviderWebIdentityConfig { - func toCRTType() -> CredentialsProviderWebIdentityConfig { - return CredentialsProviderWebIdentityConfig(bootstrap: SDKDefaultIO.shared.clientBootstrap, - tlsContext: SDKDefaultIO.shared.tlsContext, - shutDownOptions: shutDownCallback) - } -} - -struct CredentialsProviderWebIdentityConfig: CRTCredentialsProviderWebIdentityConfig { - var bootstrap: ClientBootstrap - - var tlsContext: TlsContext - - var shutDownOptions: CRTCredentialsProviderShutdownOptions? - - init(bootstrap: ClientBootstrap, - tlsContext: TlsContext, - shutDownOptions: ShutDownCallback? = nil) { - self.bootstrap = bootstrap - self.tlsContext = tlsContext - if let shutDownOptions = shutDownOptions { - self.shutDownOptions = CRTCredentialsProviderShutdownOptions(shutDownCallback: shutDownOptions) - } - } -} diff --git a/AWSClientRuntime/Sources/Auth/CredentialsProviderCRTAdapter.swift b/AWSClientRuntime/Sources/Auth/CredentialsProviderCRTAdapter.swift index 892b0a459e8..eb199431aae 100644 --- a/AWSClientRuntime/Sources/Auth/CredentialsProviderCRTAdapter.swift +++ b/AWSClientRuntime/Sources/Auth/CredentialsProviderCRTAdapter.swift @@ -8,7 +8,7 @@ import AwsCommonRuntimeKit import ClientRuntime -struct CredentialsProviderCRTAdapter: CRTCredentialsProvider { +class CredentialsProviderCRTAdapter: CredentialsProviding { var allocator: Allocator let credentialsProvider: CredentialsProvider let logger: SwiftLogger @@ -20,8 +20,8 @@ struct CredentialsProviderCRTAdapter: CRTCredentialsProvider { self.allocator = defaultAllocator } - func getCredentials() async throws -> CRTCredentials { + func getCredentials() async throws -> Credentials { let credentials = try await credentialsProvider.getCredentials() - return credentials.toCRTType() + return try credentials.toCRTType() } } diff --git a/AWSClientRuntime/Sources/Config/Profile.swift b/AWSClientRuntime/Sources/Config/Profile.swift index d2a9d2b52d7..8a0eb48b236 100644 --- a/AWSClientRuntime/Sources/Config/Profile.swift +++ b/AWSClientRuntime/Sources/Config/Profile.swift @@ -9,9 +9,9 @@ import AwsCommonRuntimeKit public struct Profile { public let name: String? public let propertyCount: Int - let crtProfile: CRTAWSProfile? + let crtProfile: AwsCommonRuntimeKit.Profile? - init(crtProfile: CRTAWSProfile) { + init(crtProfile: AwsCommonRuntimeKit.Profile) { self.name = crtProfile.name self.propertyCount = crtProfile.propertyCount self.crtProfile = crtProfile diff --git a/AWSClientRuntime/Sources/Config/ProfileCollection.swift b/AWSClientRuntime/Sources/Config/ProfileCollection.swift index 2a15f5fd1f2..600d603ad41 100644 --- a/AWSClientRuntime/Sources/Config/ProfileCollection.swift +++ b/AWSClientRuntime/Sources/Config/ProfileCollection.swift @@ -11,7 +11,7 @@ public protocol ProfileCollection { func profile(for name: String) -> Profile? } -extension CRTAWSProfileCollection: ProfileCollection { +extension AwsCommonRuntimeKit.ProfileCollection: ProfileCollection { public func profile(for name: String) -> Profile? { guard let crtProfile = getProfile(name: name) else { return nil diff --git a/AWSClientRuntime/Sources/Endpoints/AWSEndpointsRequestContext.swift b/AWSClientRuntime/Sources/Endpoints/AWSEndpointsRequestContext.swift index 44d1a9b1a3d..5c3c450825b 100644 --- a/AWSClientRuntime/Sources/Endpoints/AWSEndpointsRequestContext.swift +++ b/AWSClientRuntime/Sources/Endpoints/AWSEndpointsRequestContext.swift @@ -6,10 +6,10 @@ import AwsCommonRuntimeKit /// Wrapper for CRTAWSEndpointsRequestContext public class AWSEndpointsRequestContext { - let crtContext: CRTAWSEndpointsRequestContext + let crtContext: AwsCommonRuntimeKit.EndpointsRequestContext public init() throws { - self.crtContext = try CRTAWSEndpointsRequestContext() + self.crtContext = try AwsCommonRuntimeKit.EndpointsRequestContext() } public func add(name: String, value: String?) throws { @@ -20,7 +20,7 @@ public class AWSEndpointsRequestContext { try crtContext.add(name: name, value: value) } - public func toCRT() -> CRTAWSEndpointsRequestContext { + public func toCRT() -> AwsCommonRuntimeKit.EndpointsRequestContext { crtContext } } diff --git a/AWSClientRuntime/Sources/Endpoints/AWSEndpointsResolvedEndpoint.swift b/AWSClientRuntime/Sources/Endpoints/AWSEndpointsResolvedEndpoint.swift index db825c7c7f4..a21f769fc5e 100644 --- a/AWSClientRuntime/Sources/Endpoints/AWSEndpointsResolvedEndpoint.swift +++ b/AWSClientRuntime/Sources/Endpoints/AWSEndpointsResolvedEndpoint.swift @@ -6,29 +6,49 @@ import AwsCommonRuntimeKit /// Wrapper for CRTAWSEndpointResolvedEndpoint public class AWSEndpointsResolvedEndpoint { - let crtResolvedEndpoint: CRTAWSEndpointResolvedEndpoint + let crtResolvedEndpoint: AwsCommonRuntimeKit.ResolvedEndpoint - init(crtResolvedEndpoint: CRTAWSEndpointResolvedEndpoint) { + init(crtResolvedEndpoint: AwsCommonRuntimeKit.ResolvedEndpoint) { self.crtResolvedEndpoint = crtResolvedEndpoint } public func getType() -> AWSEndpointsResolvedEndpointType { - AWSEndpointsResolvedEndpointType(crtType: crtResolvedEndpoint.getType()) + AWSEndpointsResolvedEndpointType(crtType: crtResolvedEndpoint) } - public func getError() throws -> String? { - try crtResolvedEndpoint.getError() + public func getError() -> String? { + switch crtResolvedEndpoint { + case .endpoint: + return nil + case let .error(message): + return message + } } - public func getURL() throws -> String? { - try crtResolvedEndpoint.getURL() + public func getURL() -> String? { + switch crtResolvedEndpoint { + case let .endpoint(url, _, _): + return url + case .error: + return nil + } } - public func getProperties() throws -> [String: AnyHashable]? { - try crtResolvedEndpoint.getProperties() + public func getProperties() -> [String: AnyHashable]? { + switch crtResolvedEndpoint { + case let .endpoint(_, _, properties): + return properties + case .error: + return nil + } } - public func getHeaders() throws -> [String: [String]]? { - try crtResolvedEndpoint.getHeaders() + public func getHeaders() -> [String: [String]]? { + switch crtResolvedEndpoint { + case let .endpoint(_, headers, _): + return headers + case .error: + return nil + } } } diff --git a/AWSClientRuntime/Sources/Endpoints/AWSEndpointsResolvedEndpointType.swift b/AWSClientRuntime/Sources/Endpoints/AWSEndpointsResolvedEndpointType.swift index 67fec8c81d6..4a82f6c7e45 100644 --- a/AWSClientRuntime/Sources/Endpoints/AWSEndpointsResolvedEndpointType.swift +++ b/AWSClientRuntime/Sources/Endpoints/AWSEndpointsResolvedEndpointType.swift @@ -8,7 +8,7 @@ public enum AWSEndpointsResolvedEndpointType { case error case endpoint - init(crtType: CRTAWSEndpointsResolvedEndpointType) { + init(crtType: AwsCommonRuntimeKit.ResolvedEndpoint) { switch crtType { case .error: self = .error diff --git a/AWSClientRuntime/Sources/Endpoints/AWSEndpointsRuleEngine.swift b/AWSClientRuntime/Sources/Endpoints/AWSEndpointsRuleEngine.swift index e1bc99eff99..8e06565167b 100644 --- a/AWSClientRuntime/Sources/Endpoints/AWSEndpointsRuleEngine.swift +++ b/AWSClientRuntime/Sources/Endpoints/AWSEndpointsRuleEngine.swift @@ -6,17 +6,14 @@ import AwsCommonRuntimeKit /// Wrapper for CRTAWSEndpointsRuleEngine public class AWSEndpointsRuleEngine { - let crtEngine: CRTAWSEndpointsRuleEngine + let crtEngine: AwsCommonRuntimeKit.EndpointsRuleEngine public init(partitions: String, ruleSet: String) throws { - crtEngine = try CRTAWSEndpointsRuleEngine(partitions: partitions, ruleSet: ruleSet) + crtEngine = try AwsCommonRuntimeKit.EndpointsRuleEngine(partitions: partitions, ruleSet: ruleSet) } public func resolve(context: AWSEndpointsRequestContext) throws -> AWSEndpointsResolvedEndpoint? { - guard let crtResolvedEndpoint = try crtEngine.resolve(context: context.toCRT()) else { - return nil - } - + let crtResolvedEndpoint = try crtEngine.resolve(context: context.toCRT()) return AWSEndpointsResolvedEndpoint(crtResolvedEndpoint: crtResolvedEndpoint) } } diff --git a/AWSClientRuntime/Sources/IMDS/IMDSClient.swift b/AWSClientRuntime/Sources/IMDS/IMDSClient.swift index 2112d74c21a..e504c3cf37c 100644 --- a/AWSClientRuntime/Sources/IMDS/IMDSClient.swift +++ b/AWSClientRuntime/Sources/IMDS/IMDSClient.swift @@ -15,12 +15,17 @@ import ClientRuntime /// See https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html#instance-metadata-transition-to-version-2 /// for more information. public class IMDSClient { - let crtIMDSClient: CRTIMDSClient + let crtIMDSClient: AwsCommonRuntimeKit.IMDSClient private let sharedDefaultIO: SDKDefaultIO = SDKDefaultIO.shared - public init(config: IMDSConfig = IMDSConfig()) { - let crtConfig = config.toCRTConfig() - self.crtIMDSClient = CRTIMDSClient(options: crtConfig) + public init(config: IMDSConfig = IMDSConfig()) throws { + self.crtIMDSClient = try AwsCommonRuntimeKit.IMDSClient( + bootstrap: sharedDefaultIO.clientBootstrap, + retryStrategy: .init( + eventLoopGroup: sharedDefaultIO.eventLoopGroup, + maxRetries: config.retries + ) + ) } public func get(path: String) async throws -> String? { diff --git a/AWSClientRuntime/Sources/IMDS/IMDSConfig.swift b/AWSClientRuntime/Sources/IMDS/IMDSConfig.swift index d2ccdc04b72..d1359161369 100644 --- a/AWSClientRuntime/Sources/IMDS/IMDSConfig.swift +++ b/AWSClientRuntime/Sources/IMDS/IMDSConfig.swift @@ -14,12 +14,3 @@ public struct IMDSConfig { self.retries = retries } } - -extension IMDSConfig { - // swiftlint:disable force_try - func toCRTConfig() -> CRTIMDSClientOptions { - let options = RetryOptions(backOffRetryOptions: ExponentialBackOffRetryOptions(maxRetries: retries)) - let crtRetryer = try! CRTAWSRetryStrategy(options: options.toCRTType()) - return CRTIMDSClientOptions(bootstrap: SDKDefaultIO.shared.clientBootstrap, retryStrategy: crtRetryer) - } -} diff --git a/AWSClientRuntime/Sources/Middlewares/Sha256TreeHashMiddleware.swift b/AWSClientRuntime/Sources/Middlewares/Sha256TreeHashMiddleware.swift index 421bfe8a5a4..00aa050ac0f 100644 --- a/AWSClientRuntime/Sources/Middlewares/Sha256TreeHashMiddleware.swift +++ b/AWSClientRuntime/Sources/Middlewares/Sha256TreeHashMiddleware.swift @@ -30,15 +30,15 @@ public struct Sha256TreeHashMiddleware 0 else { + guard streamBytes.length() > 0 else { return try await next.handle(context: context, input: input) } - let (linearHash, treeHash) = computeHashes(bytes: streamBytes) + let (linearHash, treeHash) = try computeHashes(data: streamBytes.getData()) if let treeHash = treeHash, let linearHash = linearHash { input.withHeader(name: X_AMZ_SHA256_TREE_HASH_HEADER_NAME, value: treeHash) input.withHeader(name: X_AMZ_CONTENT_SHA256_HEADER_NAME, value: linearHash) @@ -50,30 +50,19 @@ public struct Sha256TreeHashMiddleware (String?, String?) { - let bufferSize = 1024 * 1024 - var hashes = [[UInt8]]() - - while true { - var oneMbTempBuffer = ByteBuffer(size: bufferSize) - let bytesRead = bytes.readIntoBuffer(buffer: &oneMbTempBuffer) - if bytesRead == 0 { - break - } - let hash = oneMbTempBuffer.sha256() - hashes.append(hash.toByteArray()) - } - - return (bytes.sha256().encodeToHexString(), computeTreeHash(hashes: hashes)) + private func computeHashes(data: Data) throws -> (String?, String?) { + let ONE_MB = 1024 * 1024 + let hashes: [[UInt8]] = try data.chunked(size: ONE_MB).map{ try $0.sha256().bytes() } + return try (data.sha256().encodeToHexString(), computeTreeHash(hashes: hashes)) } /// Builds a tree hash root node given a slice of hashes. Glacier tree hash to be derived from SHA256 hashes /// of 1MB chunks of the data. /// See http://docs.aws.amazon.com/amazonglacier/latest/dev/checksum-calculations.html /// for more information. - private func computeTreeHash(hashes: [[UInt8]]) -> String? { + private func computeTreeHash(hashes: [[UInt8]]) throws -> String? { guard !hashes.isEmpty else { return nil } @@ -85,10 +74,8 @@ public struct Sha256TreeHashMiddleware.client( ClientError.authError("AwsSigv4Signer requires a credentialsProvider")) @@ -55,18 +55,22 @@ public struct SigV4Middleware [Data] { + return stride(from: 0, to: count, by: size).map { + self[$0 ..< Swift.min($0 + size, count)] + } + } + + func bytes() -> [UInt8] { + return [UInt8](self) + } +} diff --git a/AWSClientRuntime/Sources/PrimitiveExtensions/Date+Extension.swift b/AWSClientRuntime/Sources/PrimitiveExtensions/Date+Extension.swift deleted file mode 100644 index 6d32abfedf7..00000000000 --- a/AWSClientRuntime/Sources/PrimitiveExtensions/Date+Extension.swift +++ /dev/null @@ -1,15 +0,0 @@ -// -// Copyright Amazon.com Inc. or its affiliates. -// All Rights Reserved. -// -// SPDX-License-Identifier: Apache-2.0 -// - -import AwsCommonRuntimeKit -import struct Foundation.Date - -extension Date { - var awsDateTimeIntervalSince1970: AWSDate { - return AWSDate(epochS: self.timeIntervalSince1970) - } -} diff --git a/AWSClientRuntime/Sources/Protocols/Ec2Query/Ec2QueryError.swift b/AWSClientRuntime/Sources/Protocols/Ec2Query/Ec2QueryError.swift index 7733d1f314c..63ec901b64b 100644 --- a/AWSClientRuntime/Sources/Protocols/Ec2Query/Ec2QueryError.swift +++ b/AWSClientRuntime/Sources/Protocols/Ec2Query/Ec2QueryError.swift @@ -21,7 +21,7 @@ public struct Ec2QueryError { self.requestId = decoded.requestId return } else if case .stream(let byteStream) = httpResponse.body { - let decoded: Ec2Response = try XMLDecoder().decode(responseBody: byteStream.toBytes().toData()) + let decoded: Ec2Response = try XMLDecoder().decode(responseBody: byteStream.toBytes().getData()) self.errorCode = decoded.errors.error.code self.message = decoded.errors.error.message self.requestId = decoded.requestId diff --git a/AWSClientRuntime/Sources/Protocols/RestJSON/RestJSONError.swift b/AWSClientRuntime/Sources/Protocols/RestJSON/RestJSONError.swift index a88e6102394..e2713c27b44 100644 --- a/AWSClientRuntime/Sources/Protocols/RestJSON/RestJSONError.swift +++ b/AWSClientRuntime/Sources/Protocols/RestJSON/RestJSONError.swift @@ -36,7 +36,7 @@ public struct RestJSONError { var type = httpResponse.headers.value(for: X_AMZN_ERROR_TYPE_HEADER_NAME) if case .stream(let reader) = httpResponse.body { - let data = reader.toBytes().toData() + let data = reader.toBytes().getData() let output: RestJSONErrorPayload = try JSONDecoder().decode(responseBody: data) if message == nil { message = output.resolvedErrorMessage diff --git a/AWSClientRuntime/Sources/Protocols/RestXML/RestXMLError.swift b/AWSClientRuntime/Sources/Protocols/RestXML/RestXMLError.swift index b9858391da0..14611608fcc 100644 --- a/AWSClientRuntime/Sources/Protocols/RestXML/RestXMLError.swift +++ b/AWSClientRuntime/Sources/Protocols/RestXML/RestXMLError.swift @@ -14,7 +14,7 @@ public struct RestXMLError { public init(httpResponse: HttpResponse) throws { switch httpResponse.body { case .stream(let reader): - let responseBody = reader.toBytes().toData() + let responseBody = reader.toBytes().getData() do { let decoded: ErrorResponseContainer decoded = try XMLDecoder().decode(responseBody: responseBody) diff --git a/AWSClientRuntime/Sources/Regions/DefaultRegionResolver.swift b/AWSClientRuntime/Sources/Regions/DefaultRegionResolver.swift index c177ecc5984..6961193b115 100644 --- a/AWSClientRuntime/Sources/Regions/DefaultRegionResolver.swift +++ b/AWSClientRuntime/Sources/Regions/DefaultRegionResolver.swift @@ -11,11 +11,11 @@ public struct DefaultRegionResolver: RegionResolver { public let providers: [RegionProvider] let logger: SwiftLogger - public init(providers: [RegionProvider]? = nil) { + public init(providers: [RegionProvider]? = nil) throws { #if os(iOS) || os(watchOS) || os(tvOS) self.providers = providers ?? [BundleRegionProvider(), EnvironmentRegionProvider()] #else - self.providers = providers ?? [ + self.providers = try providers ?? [ BundleRegionProvider(), EnvironmentRegionProvider(), ProfileRegionProvider(), @@ -27,14 +27,10 @@ public struct DefaultRegionResolver: RegionResolver { public func resolveRegion() async -> String? { for provider in providers { - do { - logger.debug("Attempting to resolve region with: \(String(describing: type(of: provider)))") - if let region = try await provider.resolveRegion() { - logger.debug("Resolved region with: \(String(describing: type(of: provider)))") - return region - } - } catch { - return nil + logger.debug("Attempting to resolve region with: \(String(describing: type(of: provider)))") + if let region = try? await provider.resolveRegion() { + logger.debug("Resolved region with: \(String(describing: type(of: provider)))") + return region } } logger.debug("Unable to resolve region") diff --git a/AWSClientRuntime/Sources/Regions/IMDSRegionProvider.swift b/AWSClientRuntime/Sources/Regions/IMDSRegionProvider.swift index df34aa2e1f4..ac1e9347f83 100644 --- a/AWSClientRuntime/Sources/Regions/IMDSRegionProvider.swift +++ b/AWSClientRuntime/Sources/Regions/IMDSRegionProvider.swift @@ -10,8 +10,8 @@ public struct IMDSRegionProvider: RegionProvider { private let REGION_PATH = "/latest/meta-data/placement/region" let imdsClient: IMDSClient - public init() { - self.imdsClient = IMDSClient() + public init() throws { + self.imdsClient = try IMDSClient() } public func resolveRegion() async throws -> String? { diff --git a/AWSClientRuntime/Sources/Regions/ProfileRegionResolver.swift b/AWSClientRuntime/Sources/Regions/ProfileRegionResolver.swift index 50207afcc27..c54b22e538f 100644 --- a/AWSClientRuntime/Sources/Regions/ProfileRegionResolver.swift +++ b/AWSClientRuntime/Sources/Regions/ProfileRegionResolver.swift @@ -26,13 +26,7 @@ public struct ProfileRegionProvider: RegionProvider { } public func resolveRegion() async throws -> String? { - - let profileCollection = profileCollection ?? CRTAWSProfileCollection(fromFile: path, source: .config) - guard let profileCollection = profileCollection else { - logger.debug("No default profile collection was found at the path of \(path)") - return nil - } - + let profileCollection = try profileCollection ?? AwsCommonRuntimeKit.ProfileCollection(fromFile: path, source: .config) guard let profile = profileCollection.profile(for: profileName) else { logger.debug("Unable to find profile: \(profileName) in \(path)") return nil diff --git a/AWSClientRuntime/Sources/Signing/AWSSigV4Signer.swift b/AWSClientRuntime/Sources/Signing/AWSSigV4Signer.swift index 7b905a2eea2..5653d89a6b6 100644 --- a/AWSClientRuntime/Sources/Signing/AWSSigV4Signer.swift +++ b/AWSClientRuntime/Sources/Signing/AWSSigV4Signer.swift @@ -5,18 +5,21 @@ // SPDX-License-Identifier: Apache-2.0 // -import ClientRuntime import AwsCommonRuntimeKit +import ClientRuntime +import Foundation public class AWSSigV4Signer { static let logger: SwiftLogger = SwiftLogger(label: "AWSSigV4Signer") - public static func sigV4SignedURL(requestBuilder: SdkHttpRequestBuilder, - credentialsProvider: CredentialsProvider, - signingName: Swift.String, - signingRegion: Swift.String, - date: ClientRuntime.Date, - expiration: Int64) async -> ClientRuntime.URL? { + public static func sigV4SignedURL( + requestBuilder: SdkHttpRequestBuilder, + credentialsProvider: CredentialsProvider, + signingName: Swift.String, + signingRegion: Swift.String, + date: ClientRuntime.Date, + expiration: TimeInterval + ) async -> ClientRuntime.URL? { do { let credentials = try await credentialsProvider.getCredentials() let flags = SigningFlags(useDoubleURIEncode: true, @@ -24,15 +27,17 @@ public class AWSSigV4Signer { omitSessionToken: false) let signedBodyHeader: AWSSignedBodyHeader = .none let signedBodyValue: AWSSignedBodyValue = .empty - let signingConfig = AWSSigningConfig(credentials: credentials, - expiration: expiration, - signedBodyHeader: signedBodyHeader, - signedBodyValue: signedBodyValue, - flags: flags, - date: date, - service: signingName, - region: signingRegion, - signatureType: .requestQueryParams) + let signingConfig = AWSSigningConfig( + credentials: credentials, + expiration: expiration, + signedBodyHeader: signedBodyHeader, + signedBodyValue: signedBodyValue, + flags: flags, + date: date, + service: signingName, + region: signingRegion, + signatureType: .requestQueryParams + ) let builtRequest = await sigV4SignedRequest(requestBuilder: requestBuilder, signingConfig: signingConfig) guard let presignedURL = builtRequest?.endpoint.url else { logger.error("Failed to generate presigend url") @@ -45,17 +50,21 @@ public class AWSSigV4Signer { } } - public static func sigV4SignedRequest(requestBuilder: SdkHttpRequestBuilder, - signingConfig: AWSSigningConfig) async -> SdkHttpRequest? { + public static func sigV4SignedRequest( + requestBuilder: SdkHttpRequestBuilder, + signingConfig: AWSSigningConfig + ) async -> SdkHttpRequest? { let originalRequest = requestBuilder.build() - let crtUnsignedRequest = originalRequest.toHttpRequest() - let signer = SigV4HttpRequestSigner() do { - let crtSignedRequest = try await signer.signRequest(request: crtUnsignedRequest, - config: signingConfig.toCRTType()) + let crtUnsignedRequest = try originalRequest.toHttpRequest() + + let crtSignedRequest = try await Signer.signRequest( + request: crtUnsignedRequest, + config: signingConfig.toCRTType() + ) let sdkSignedRequest = requestBuilder.update(from: crtSignedRequest, originalRequest: originalRequest) return sdkSignedRequest.build() - } catch CRTError.crtError(let crtError) { + } catch CommonRunTimeError.crtError(let crtError) { logger.error("Failed to sign request (CRT): \(crtError)") return nil } catch let err { diff --git a/AWSClientRuntime/Sources/Signing/AWSSigningConfig.swift b/AWSClientRuntime/Sources/Signing/AWSSigningConfig.swift index 4b3ce51d2a4..7c74debb722 100644 --- a/AWSClientRuntime/Sources/Signing/AWSSigningConfig.swift +++ b/AWSClientRuntime/Sources/Signing/AWSSigningConfig.swift @@ -5,32 +5,36 @@ // SPDX-License-Identifier: Apache-2.0 // import AwsCommonRuntimeKit -import struct Foundation.Date +import Foundation public struct AWSSigningConfig { public let credentials: AWSCredentials? public let credentialsProvider: AWSCredentialsProvider? - public let expiration: Int64 + public let expiration: TimeInterval public let signedBodyHeader: AWSSignedBodyHeader public let signedBodyValue: AWSSignedBodyValue public let flags: SigningFlags public let date: Date public let service: String public let region: String + public let shouldSignHeader: ((String) -> Bool)? public let signatureType: AWSSignatureType public let signingAlgorithm: AWSSigningAlgorithm - public init(credentials: AWSCredentials? = nil, - credentialsProvider: AWSCredentialsProvider? = nil, - expiration: Int64 = 0, - signedBodyHeader: AWSSignedBodyHeader = .none, - signedBodyValue: AWSSignedBodyValue, - flags: SigningFlags, - date: Date, - service: String, - region: String, - signatureType: AWSSignatureType, - signingAlgorithm: AWSSigningAlgorithm = .sigv4) { + public init( + credentials: AWSCredentials? = nil, + credentialsProvider: AWSCredentialsProvider? = nil, + expiration: TimeInterval = 0, + signedBodyHeader: AWSSignedBodyHeader = .none, + signedBodyValue: AWSSignedBodyValue, + flags: SigningFlags, + date: Date, + service: String, + region: String, + shouldSignHeader: ((String) -> Bool)? = nil, + signatureType: AWSSignatureType, + signingAlgorithm: AWSSigningAlgorithm = .sigv4 + ) { self.credentials = credentials self.credentialsProvider = credentialsProvider self.expiration = expiration @@ -40,24 +44,29 @@ public struct AWSSigningConfig { self.date = date self.service = service self.region = region + self.shouldSignHeader = shouldSignHeader self.signatureType = signatureType self.signingAlgorithm = signingAlgorithm } } extension AWSSigningConfig { - func toCRTType() -> SigningConfig { - return SigningConfig(credentials: credentials?.toCRTType(), - credentialsProvider: credentialsProvider?.crtCredentialsProvider, - date: date.awsDateTimeIntervalSince1970, - service: service, - region: region, - expiration: expiration, - signedBodyHeader: signedBodyHeader.toCRTType(), - signedBodyValue: signedBodyValue.toCRTType(), - flags: flags.toCRTType(), - signatureType: signatureType.toCRTType(), - signingAlgorithm: signingAlgorithm.toCRTType(), - configType: .aws) + func toCRTType() throws -> SigningConfig { + SigningConfig( + algorithm: signingAlgorithm.toCRTType(), + signatureType: signatureType.toCRTType(), + service: service, + region: region, + date: date, + credentials: try credentials?.toCRTType(), + credentialsProvider: credentialsProvider?.crtCredentialsProvider, + expiration: expiration, + signedBodyHeader: signedBodyHeader.toCRTType(), + signedBodyValue: signedBodyValue.toCRTType(), + shouldSignHeader: shouldSignHeader, + useDoubleURIEncode: flags.useDoubleURIEncode, + shouldNormalizeURIPath: flags.shouldNormalizeURIPath, + omitSessionToken: flags.omitSessionToken + ) } } diff --git a/AWSClientRuntime/Sources/Signing/SigV4Config.swift b/AWSClientRuntime/Sources/Signing/SigV4Config.swift index 16738b391fe..b049a828862 100644 --- a/AWSClientRuntime/Sources/Signing/SigV4Config.swift +++ b/AWSClientRuntime/Sources/Signing/SigV4Config.swift @@ -4,6 +4,8 @@ // // SPDX-License-Identifier: Apache-2.0 // + +import Foundation public struct SigV4Config { let credentialsProvider: AWSCredentialsProvider? @@ -12,19 +14,21 @@ public struct SigV4Config { let useDoubleURIEncode: Bool let shouldNormalizeURIPath: Bool let omitSessionToken: Bool - let expiration: Int64 + let expiration: TimeInterval let signedBodyHeader: AWSSignedBodyHeader let unsignedBody: Bool - public init(credentialsProvider: AWSCredentialsProvider? = nil, - signingService: String? = nil, - signatureType: AWSSignatureType = .requestHeaders, - useDoubleURIEncode: Bool = true, - shouldNormalizeURIPath: Bool = true, - omitSessionToken: Bool = false, - expiration: Int64 = 0, - signedBodyHeader: AWSSignedBodyHeader = .none, - unsignedBody: Bool) { + public init( + credentialsProvider: AWSCredentialsProvider? = nil, + signingService: String? = nil, + signatureType: AWSSignatureType = .requestHeaders, + useDoubleURIEncode: Bool = true, + shouldNormalizeURIPath: Bool = true, + omitSessionToken: Bool = false, + expiration: TimeInterval = 0, + signedBodyHeader: AWSSignedBodyHeader = .none, + unsignedBody: Bool + ) { self.credentialsProvider = credentialsProvider self.signingService = signingService self.signatureType = signatureType diff --git a/AWSClientRuntime/Sources/Signing/SigningFlags.swift b/AWSClientRuntime/Sources/Signing/SigningFlags.swift index 52a1c8f9ef3..9348b827abf 100644 --- a/AWSClientRuntime/Sources/Signing/SigningFlags.swift +++ b/AWSClientRuntime/Sources/Signing/SigningFlags.swift @@ -17,11 +17,3 @@ public struct SigningFlags { self.omitSessionToken = omitSessionToken } } - -extension SigningFlags { - func toCRTType() -> SigningConfig.Flags { - return SigningConfig.Flags(useDoubleURIEncode: useDoubleURIEncode, - shouldNormalizeURIPath: shouldNormalizeURIPath, - omitSessionToken: omitSessionToken) - } -} diff --git a/AWSClientRuntime/Tests/Auth/AWSCredentialProviderTests.swift b/AWSClientRuntime/Tests/Auth/AWSCredentialProviderTests.swift index bccdb47f834..612441efa62 100644 --- a/AWSClientRuntime/Tests/Auth/AWSCredentialProviderTests.swift +++ b/AWSClientRuntime/Tests/Auth/AWSCredentialProviderTests.swift @@ -22,6 +22,10 @@ class AWSCredentialProviderTests: XCTestCase { struct MyCustomCredentialsProvider: CredentialsProvider { func getCredentials() async throws -> AWSCredentials { - return AWSCredentials(accessKey: "MYACCESSKEY", secret: "sekrit", expirationTimeout: 30) + return AWSCredentials( + accessKey: "MYACCESSKEY", + secret: "sekrit", + expirationTimeout: .init(timeIntervalSinceNow: 30) + ) } } diff --git a/AWSClientRuntime/Tests/Protocols/RestXML/Models/Errors/ComplexXMLError+ResponseInit.swift b/AWSClientRuntime/Tests/Protocols/RestXML/Models/Errors/ComplexXMLError+ResponseInit.swift index 4ebcdfcb32b..6312eabe662 100644 --- a/AWSClientRuntime/Tests/Protocols/RestXML/Models/Errors/ComplexXMLError+ResponseInit.swift +++ b/AWSClientRuntime/Tests/Protocols/RestXML/Models/Errors/ComplexXMLError+ResponseInit.swift @@ -20,7 +20,7 @@ extension ComplexXMLError: AWSHttpServiceError { if case .stream(let reader) = httpResponse.body, let responseDecoder = decoder { - let data = reader.toBytes().toData() + let data = reader.toBytes().getData() let output: ErrorResponseContainer = try responseDecoder.decode(responseBody: data) self.nested = output.error.nested self.topLevel = output.error.topLevel diff --git a/AWSClientRuntime/Tests/Protocols/RestXML/Models/Errors/ComplexXMLErrorNoErrorWrapping+Init.swift b/AWSClientRuntime/Tests/Protocols/RestXML/Models/Errors/ComplexXMLErrorNoErrorWrapping+Init.swift index 50e513b9a06..96ff1bd8e3f 100644 --- a/AWSClientRuntime/Tests/Protocols/RestXML/Models/Errors/ComplexXMLErrorNoErrorWrapping+Init.swift +++ b/AWSClientRuntime/Tests/Protocols/RestXML/Models/Errors/ComplexXMLErrorNoErrorWrapping+Init.swift @@ -19,7 +19,7 @@ extension ComplexXMLErrorNoErrorWrapping: AWSHttpServiceError { } if case .stream(let reader) = httpResponse.body, let responseDecoder = decoder { - let data = reader.toBytes().toData() + let data = reader.toBytes().getData() let output: ComplexXMLErrorNoErrorWrappingBody = try responseDecoder.decode(responseBody: data) self.nested = output.nested self.topLevel = output.topLevel diff --git a/AWSClientRuntime/Tests/Protocols/RestXML/Models/Errors/InvalidGreeting+ResponseInit.swift b/AWSClientRuntime/Tests/Protocols/RestXML/Models/Errors/InvalidGreeting+ResponseInit.swift index 51f1711ca4b..4f1d1198a69 100644 --- a/AWSClientRuntime/Tests/Protocols/RestXML/Models/Errors/InvalidGreeting+ResponseInit.swift +++ b/AWSClientRuntime/Tests/Protocols/RestXML/Models/Errors/InvalidGreeting+ResponseInit.swift @@ -15,7 +15,7 @@ extension InvalidGreeting: AWSHttpServiceError { if case .stream(let reader) = httpResponse.body, let responseDecoder = decoder { - let data = reader.toBytes().toData() + let data = reader.toBytes().getData() let output: InvalidGreetingBody = try responseDecoder.decode(responseBody: data) self.message = output.message } else { diff --git a/AWSClientRuntime/Tests/Regions/RegionTests.swift b/AWSClientRuntime/Tests/Regions/RegionTests.swift index e6ae215726a..611652a1ee8 100644 --- a/AWSClientRuntime/Tests/Regions/RegionTests.swift +++ b/AWSClientRuntime/Tests/Regions/RegionTests.swift @@ -12,39 +12,39 @@ import XCTest class RegionTests: XCTestCase { - func testItResolvesRegionFromEnvironment() async { + func testItResolvesRegionFromEnvironment() async throws { let providers = [EnvironmentRegionProvider(env: MockEnvironment(region: "us-west-1"))] - let region = await DefaultRegionResolver(providers: providers).resolveRegion() + let region = try await DefaultRegionResolver(providers: providers).resolveRegion() XCTAssertEqual(region, "us-west-1") } - func testCustomChain() async { + func testCustomChain() async throws { let providers: [RegionProvider] = [ EnvironmentRegionProvider(env: MockEnvironment(region: nil)), EnvironmentRegionProvider(env: MockEnvironment(region: "us-east-1")), EnvironmentRegionProvider(env: MockEnvironment(region: "us-east-2")) ] - let region = await DefaultRegionResolver(providers: providers).resolveRegion() + let region = try await DefaultRegionResolver(providers: providers).resolveRegion() XCTAssertEqual(region, "us-east-1") } - func testChainWithBadProfileProviderFailsGracefully() async { + func testChainWithBadProfileProviderFailsGracefully() async throws { let providers: [RegionProvider] = [ EnvironmentRegionProvider(env: MockEnvironment(region: nil)), ProfileRegionProvider(path: "~/.aws/configz", profileName: "default"), EnvironmentRegionProvider(env: MockEnvironment(region: "us-east-1")), EnvironmentRegionProvider(env: MockEnvironment(region: "us-east-2")) ] - let region = await DefaultRegionResolver(providers: providers).resolveRegion() + let region = try await DefaultRegionResolver(providers: providers).resolveRegion() XCTAssertEqual(region, "us-east-1") } - func testChainWithBadProfileProviderFails() async { + func testChainWithBadProfileProviderFails() async throws { let providers: [RegionProvider] = [ EnvironmentRegionProvider(env: MockEnvironment(region: nil)), ProfileRegionProvider(path: "~/.aws/configz", profileName: "default") ] - let region = await DefaultRegionResolver(providers: providers).resolveRegion() + let region = try await DefaultRegionResolver(providers: providers).resolveRegion() XCTAssertEqual(region, nil) } } diff --git a/AWSClientRuntime/Tests/Sigv4/SigV4SigningTests.swift b/AWSClientRuntime/Tests/Sigv4/SigV4SigningTests.swift index a845abdca21..11f5f000609 100644 --- a/AWSClientRuntime/Tests/Sigv4/SigV4SigningTests.swift +++ b/AWSClientRuntime/Tests/Sigv4/SigV4SigningTests.swift @@ -13,12 +13,16 @@ import XCTest class Sigv4SigningTests: XCTestCase { override func setUp() { - AwsCommonRuntimeKit.initialize() + CommonRuntimeKit.initialize() } - struct MyCustomCredentialsProvider: CredentialsProvider { - func getCredentials() async throws -> AWSCredentials { - return AWSCredentials(accessKey: "AKIDEXAMPLE", secret: "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY", expirationTimeout: 30) + class MyCustomCredentialsProvider: AWSClientRuntime.CredentialsProvider { + func getCredentials() async throws -> AWSClientRuntime.AWSCredentials { + return AWSCredentials( + accessKey: "AKIDEXAMPLE", + secret: "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY", + expirationTimeout: .init(timeIntervalSinceNow: 30) + ) } } diff --git a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/AWSServiceConfig.kt b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/AWSServiceConfig.kt index 96ef5d67f41..f17b3d7970d 100644 --- a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/AWSServiceConfig.kt +++ b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/AWSServiceConfig.kt @@ -91,7 +91,7 @@ class AWSServiceConfig(writer: SwiftWriter, val ctx: ProtocolGenerator.Generatio } REGION_RESOLVER -> { - writer.write("self.${it.memberName} = ${it.memberName} ?? DefaultRegionResolver()") + writer.write("self.${it.memberName} = try ${it.memberName} ?? DefaultRegionResolver()") } else -> { @@ -156,7 +156,7 @@ class AWSServiceConfig(writer: SwiftWriter, val ctx: ProtocolGenerator.Generatio when (it.memberName) { REGION_CONFIG_NAME -> { // region must be resolved asynchronously - writer.write("let resolvedRegionResolver = regionResolver ?? DefaultRegionResolver()") + writer.write("let resolvedRegionResolver = try regionResolver ?? DefaultRegionResolver()") writer.write("self.${it.memberName} = await resolvedRegionResolver.resolveRegion()") } @@ -190,7 +190,7 @@ class AWSServiceConfig(writer: SwiftWriter, val ctx: ProtocolGenerator.Generatio } REGION_RESOLVER -> { - writer.write("self.${it.memberName} = ${it.memberName} ?? DefaultRegionResolver()") + writer.write("self.${it.memberName} = try ${it.memberName} ?? DefaultRegionResolver()") } else -> { diff --git a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/ec2query/httpResponse/AWSEc2QueryHttpResponseTraitWithoutPayload.kt b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/ec2query/httpResponse/AWSEc2QueryHttpResponseTraitWithoutPayload.kt index a10b0b9dbc8..cd5b305ec7e 100644 --- a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/ec2query/httpResponse/AWSEc2QueryHttpResponseTraitWithoutPayload.kt +++ b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/ec2query/httpResponse/AWSEc2QueryHttpResponseTraitWithoutPayload.kt @@ -39,7 +39,7 @@ class AWSEc2QueryHttpResponseTraitWithoutPayload( writer.write("if case .stream(let reader) = httpResponse.body,") writer.indent() writer.write("let responseDecoder = decoder {") - writer.write("let data = reader.toBytes().toData()") + writer.write("let data = reader.toBytes().getData()") renderWithoutErrorResponseContainer(outputShapeName, bodyMembersWithoutQueryTrait) writer.dedent() diff --git a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/restxml/httpResponse/AWSXMLHttpResponseTraitWithoutPayload.kt b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/restxml/httpResponse/AWSXMLHttpResponseTraitWithoutPayload.kt index 5158fa93144..32a74737e34 100644 --- a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/restxml/httpResponse/AWSXMLHttpResponseTraitWithoutPayload.kt +++ b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/restxml/httpResponse/AWSXMLHttpResponseTraitWithoutPayload.kt @@ -41,7 +41,7 @@ class AWSXMLHttpResponseTraitWithoutPayload( writer.write("if case .stream(let reader) = httpResponse.body,") writer.indent() writer.write("let responseDecoder = decoder {") - writer.write("let data = reader.toBytes().toData()") + writer.write("let data = reader.toBytes().getData()") if (serviceDisablesWrappingOfErrorProperties()) { renderWithoutErrorResponseContainer(outputShapeName, bodyMembersWithoutQueryTrait) } else { diff --git a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/ec2query/Ec2QueryHttpResponseBindingErrorGeneratorTests.kt b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/ec2query/Ec2QueryHttpResponseBindingErrorGeneratorTests.kt index 00d09260514..7fc64890bba 100644 --- a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/ec2query/Ec2QueryHttpResponseBindingErrorGeneratorTests.kt +++ b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/ec2query/Ec2QueryHttpResponseBindingErrorGeneratorTests.kt @@ -68,7 +68,7 @@ class Ec2QueryHttpResponseBindingErrorGeneratorTests { public init (httpResponse: ClientRuntime.HttpResponse, decoder: ClientRuntime.ResponseDecoder? = nil, message: Swift.String? = nil, requestID: Swift.String? = nil) throws { if case .stream(let reader) = httpResponse.body, let responseDecoder = decoder { - let data = reader.toBytes().toData() + let data = reader.toBytes().getData() let output: AWSClientRuntime.Ec2NarrowedResponse = try responseDecoder.decode(responseBody: data) self.nested = output.errors.error.nested self.topLevel = output.errors.error.topLevel diff --git a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/restxml/AWSRestXMLHttpResponseBindingErrorGeneratorTests.kt b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/restxml/AWSRestXMLHttpResponseBindingErrorGeneratorTests.kt index 51bf3541b60..a025766032a 100644 --- a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/restxml/AWSRestXMLHttpResponseBindingErrorGeneratorTests.kt +++ b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/restxml/AWSRestXMLHttpResponseBindingErrorGeneratorTests.kt @@ -73,7 +73,7 @@ class AWSRestXMLHttpResponseBindingErrorGeneratorTests { } if case .stream(let reader) = httpResponse.body, let responseDecoder = decoder { - let data = reader.toBytes().toData() + let data = reader.toBytes().getData() let output: AWSClientRuntime.ErrorResponseContainer = try responseDecoder.decode(responseBody: data) self.nested = output.error.nested self.topLevel = output.error.topLevel @@ -139,7 +139,7 @@ class AWSRestXMLHttpResponseBindingErrorGeneratorTests { } if case .stream(let reader) = httpResponse.body, let responseDecoder = decoder { - let data = reader.toBytes().toData() + let data = reader.toBytes().getData() let output: ComplexXMLErrorNoErrorWrappingBody = try responseDecoder.decode(responseBody: data) self.nested = output.nested self.topLevel = output.topLevel From 546165c6ef5cc831ea757d1554f8066d9c605156 Mon Sep 17 00:00:00 2001 From: Ed Paulosky Date: Wed, 21 Dec 2022 16:10:21 -0500 Subject: [PATCH 03/13] Bumps CRT to 0.5.2 --- packageDependencies.plist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packageDependencies.plist b/packageDependencies.plist index c8be435719f..504f8dea7b1 100644 --- a/packageDependencies.plist +++ b/packageDependencies.plist @@ -5,7 +5,7 @@ clientRuntimeVersion 0.7.0 awsCRTSwiftVersion - 0.5.0 + 0.5.2 clientRuntimeBranch main awsCRTSwiftBranch From c832bf515a22b20ad4ed1952aaf73facc2f15ffa Mon Sep 17 00:00:00 2001 From: Ed Paulosky Date: Wed, 21 Dec 2022 16:51:21 -0500 Subject: [PATCH 04/13] Updates tests --- .../aws/swift/codegen/RestJsonProtocolGeneratorTests.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/RestJsonProtocolGeneratorTests.kt b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/RestJsonProtocolGeneratorTests.kt index 1e4fd6fc0b2..f43b8f9248b 100644 --- a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/RestJsonProtocolGeneratorTests.kt +++ b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/RestJsonProtocolGeneratorTests.kt @@ -157,7 +157,7 @@ class RestJsonProtocolGeneratorTests { } self.frameworkMetadata = frameworkMetadata self.region = region - self.regionResolver = regionResolver ?? DefaultRegionResolver() + self.regionResolver = try regionResolver ?? DefaultRegionResolver() self.signingRegion = signingRegion ?? region self.useDualStack = useDualStack self.useFIPS = useFIPS @@ -220,9 +220,9 @@ class RestJsonProtocolGeneratorTests { self.endpointResolver = try DefaultEndpointResolver() } self.frameworkMetadata = frameworkMetadata - let resolvedRegionResolver = regionResolver ?? DefaultRegionResolver() + let resolvedRegionResolver = try regionResolver ?? DefaultRegionResolver() self.region = await resolvedRegionResolver.resolveRegion() - self.regionResolver = regionResolver ?? DefaultRegionResolver() + self.regionResolver = try regionResolver ?? DefaultRegionResolver() self.signingRegion = signingRegion ?? region self.useDualStack = useDualStack self.useFIPS = useFIPS From 0f3ea217aa255db5af7d92751bb80ca807d2fe8e Mon Sep 17 00:00:00 2001 From: Ed Paulosky Date: Thu, 22 Dec 2022 10:28:31 -0500 Subject: [PATCH 05/13] Cleans up and adds tests --- .../Sources/Auth/CredentialsProviderCRTAdapter.swift | 2 +- .../Sources/PrimitiveExtensions/Data+Extension.swift | 7 +++++++ AWSClientRuntime/Tests/DataExtensionTests.swift | 8 ++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 AWSClientRuntime/Tests/DataExtensionTests.swift diff --git a/AWSClientRuntime/Sources/Auth/CredentialsProviderCRTAdapter.swift b/AWSClientRuntime/Sources/Auth/CredentialsProviderCRTAdapter.swift index eb199431aae..6859cd85a20 100644 --- a/AWSClientRuntime/Sources/Auth/CredentialsProviderCRTAdapter.swift +++ b/AWSClientRuntime/Sources/Auth/CredentialsProviderCRTAdapter.swift @@ -8,7 +8,7 @@ import AwsCommonRuntimeKit import ClientRuntime -class CredentialsProviderCRTAdapter: CredentialsProviding { +struct CredentialsProviderCRTAdapter: CredentialsProviding { var allocator: Allocator let credentialsProvider: CredentialsProvider let logger: SwiftLogger diff --git a/AWSClientRuntime/Sources/PrimitiveExtensions/Data+Extension.swift b/AWSClientRuntime/Sources/PrimitiveExtensions/Data+Extension.swift index ad8e8d2921f..9cb0faf6a58 100644 --- a/AWSClientRuntime/Sources/PrimitiveExtensions/Data+Extension.swift +++ b/AWSClientRuntime/Sources/PrimitiveExtensions/Data+Extension.swift @@ -8,12 +8,19 @@ import Foundation extension Data { + /// Returns an array of `Data` instances by splitting the receiver into equal sized chunks. + /// The last instance may be less than the provided size since it will contain the last remaining chunk of data. + /// + /// - Parameter size: The maximum size, in bytes, of each data chunk + /// - Returns: An array of `Data` instances func chunked(size: Int) -> [Data] { return stride(from: 0, to: count, by: size).map { self[$0 ..< Swift.min($0 + size, count)] } } + /// Returns an array of bytes representing the data. + /// - Returns: A byte array representation of the data. func bytes() -> [UInt8] { return [UInt8](self) } diff --git a/AWSClientRuntime/Tests/DataExtensionTests.swift b/AWSClientRuntime/Tests/DataExtensionTests.swift new file mode 100644 index 00000000000..2e9ffc0427d --- /dev/null +++ b/AWSClientRuntime/Tests/DataExtensionTests.swift @@ -0,0 +1,8 @@ +// +// File.swift +// +// +// Created by Paulosky, Ed on 12/22/22. +// + +import Foundation From 59157b94a5ef73c381eac247b5f90603fda287c3 Mon Sep 17 00:00:00 2001 From: Ed Paulosky Date: Thu, 22 Dec 2022 10:28:36 -0500 Subject: [PATCH 06/13] Adds tests --- .../Tests/DataExtensionTests.swift | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/AWSClientRuntime/Tests/DataExtensionTests.swift b/AWSClientRuntime/Tests/DataExtensionTests.swift index 2e9ffc0427d..74c8e83c348 100644 --- a/AWSClientRuntime/Tests/DataExtensionTests.swift +++ b/AWSClientRuntime/Tests/DataExtensionTests.swift @@ -6,3 +6,43 @@ // import Foundation +import XCTest + +@testable import AWSClientRuntime + +class DataExtensionTests: XCTestCase { + func testBytesReturnsAnArrayOfBytes() { + let expectedBytes: [UInt8] = [ + 0x68, // h + 0x65, // e + 0x6C, // l + 0x6C, // l + 0x6F // o + ] + let data = "hello".data(using: .utf8)! + let bytes = data.bytes() + XCTAssertEqual(bytes, expectedBytes) + } + + func testChunkedReturnsEqualSizedChunks() { + let data = Data(repeating: 0x01, count: 12) + let chunks = data.chunked(size: 3) + XCTAssertEqual(chunks.count, 4) + chunks.forEach { + XCTAssertEqual($0.count, 3) + } + } + + func testLastItemInChunkedIsLessThanSize() { + let data = Data(repeating: 0x01, count: 15) + let chunks = data.chunked(size: 2) + XCTAssertEqual(chunks.count, 8) + for i in (0...7) { + if i == 7 { + XCTAssertEqual(chunks[i].count, 1) + } else { + XCTAssertEqual(chunks[i].count, 2) + } + } + } +} From 4af2df273fef40a3a91ff4f1a2a0a019a2234437 Mon Sep 17 00:00:00 2001 From: Ed Paulosky Date: Thu, 22 Dec 2022 12:38:41 -0500 Subject: [PATCH 07/13] Addresses PR feedback --- .../Sources/Middlewares/Sha256TreeHashMiddleware.swift | 2 +- .../Sources/PrimitiveExtensions/Data+Extension.swift | 6 +++--- AWSClientRuntime/Tests/DataExtensionTests.swift | 6 +++--- .../smithy/aws/swift/codegen/EndpointResolverGenerator.kt | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/AWSClientRuntime/Sources/Middlewares/Sha256TreeHashMiddleware.swift b/AWSClientRuntime/Sources/Middlewares/Sha256TreeHashMiddleware.swift index 00aa050ac0f..5aa12028992 100644 --- a/AWSClientRuntime/Sources/Middlewares/Sha256TreeHashMiddleware.swift +++ b/AWSClientRuntime/Sources/Middlewares/Sha256TreeHashMiddleware.swift @@ -54,7 +54,7 @@ public struct Sha256TreeHashMiddleware (String?, String?) { let ONE_MB = 1024 * 1024 - let hashes: [[UInt8]] = try data.chunked(size: ONE_MB).map{ try $0.sha256().bytes() } + let hashes: [[UInt8]] = try data.chunked(size: ONE_MB).map { try $0.sha256().bytes() } return try (data.sha256().encodeToHexString(), computeTreeHash(hashes: hashes)) } diff --git a/AWSClientRuntime/Sources/PrimitiveExtensions/Data+Extension.swift b/AWSClientRuntime/Sources/PrimitiveExtensions/Data+Extension.swift index 9cb0faf6a58..511d55b8bdc 100644 --- a/AWSClientRuntime/Sources/PrimitiveExtensions/Data+Extension.swift +++ b/AWSClientRuntime/Sources/PrimitiveExtensions/Data+Extension.swift @@ -1,8 +1,8 @@ // -// File.swift -// +// Copyright Amazon.com Inc. or its affiliates. +// All Rights Reserved. // -// Created by Paulosky, Ed on 12/21/22. +// SPDX-License-Identifier: Apache-2.0 // import Foundation diff --git a/AWSClientRuntime/Tests/DataExtensionTests.swift b/AWSClientRuntime/Tests/DataExtensionTests.swift index 74c8e83c348..fb00166b55b 100644 --- a/AWSClientRuntime/Tests/DataExtensionTests.swift +++ b/AWSClientRuntime/Tests/DataExtensionTests.swift @@ -1,8 +1,8 @@ // -// File.swift -// +// Copyright Amazon.com Inc. or its affiliates. +// All Rights Reserved. // -// Created by Paulosky, Ed on 12/22/22. +// SPDX-License-Identifier: Apache-2.0 // import Foundation diff --git a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/EndpointResolverGenerator.kt b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/EndpointResolverGenerator.kt index f39957f723f..9adb674f169 100644 --- a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/EndpointResolverGenerator.kt +++ b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/EndpointResolverGenerator.kt @@ -88,7 +88,7 @@ class EndpointResolverGenerator() { }.write("") writer.openBlock("if crtResolvedEndpoint.getType() == .error {", "}") { - writer.write("let error = try crtResolvedEndpoint.getError()") + writer.write("let error = crtResolvedEndpoint.getError()") writer.write("throw EndpointError.unresolved(error)") }.write("") From f2a68097c75d6dd744e8404df13614b0211a9b37 Mon Sep 17 00:00:00 2001 From: Ed Paulosky Date: Thu, 22 Dec 2022 12:54:28 -0500 Subject: [PATCH 08/13] Logs when we fail to resolve a region --- .../Sources/Regions/DefaultRegionResolver.swift | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/AWSClientRuntime/Sources/Regions/DefaultRegionResolver.swift b/AWSClientRuntime/Sources/Regions/DefaultRegionResolver.swift index 6961193b115..ea871331f7c 100644 --- a/AWSClientRuntime/Sources/Regions/DefaultRegionResolver.swift +++ b/AWSClientRuntime/Sources/Regions/DefaultRegionResolver.swift @@ -28,9 +28,17 @@ public struct DefaultRegionResolver: RegionResolver { public func resolveRegion() async -> String? { for provider in providers { logger.debug("Attempting to resolve region with: \(String(describing: type(of: provider)))") - if let region = try? await provider.resolveRegion() { - logger.debug("Resolved region with: \(String(describing: type(of: provider)))") - return region + do { + if let region = try await provider.resolveRegion() { + logger.debug("Resolved region with: \(String(describing: type(of: provider)))") + return region + } + } catch { + let logMessage = [ + "Failed to resolve region with: \(String(describing: type(of: provider)))", + "Error: \(error.localizedDescription)" + ].joined(separator: "\n") + logger.debug(logMessage) } } logger.debug("Unable to resolve region") From 242674d55a11cabbf9fb5a23e5cb258e8203881f Mon Sep 17 00:00:00 2001 From: Ed Paulosky Date: Thu, 22 Dec 2022 13:10:49 -0500 Subject: [PATCH 09/13] Updates codegen tests --- .../aws/swift/codegen/RestJsonProtocolGeneratorTests.kt | 4 ---- 1 file changed, 4 deletions(-) diff --git a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/RestJsonProtocolGeneratorTests.kt b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/RestJsonProtocolGeneratorTests.kt index f43b8f9248b..33d13d2d89e 100644 --- a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/RestJsonProtocolGeneratorTests.kt +++ b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/RestJsonProtocolGeneratorTests.kt @@ -107,10 +107,6 @@ class RestJsonProtocolGeneratorTests { self.init(config: config) } - deinit { - client.close() - } - public class ExampleClientConfiguration: ExampleClientConfigurationProtocol { public var clientLogMode: ClientRuntime.ClientLogMode public var decoder: ClientRuntime.ResponseDecoder? From d504197b492230566fce63197e900a7a75de0a13 Mon Sep 17 00:00:00 2001 From: Ed Paulosky Date: Thu, 22 Dec 2022 13:51:03 -0500 Subject: [PATCH 10/13] Updates codegen and error models --- .../Protocols/Ec2Query/Ec2QueryError.swift | 24 ++++++--------- .../Protocols/RestJSON/RestJSONError.swift | 3 +- .../Protocols/RestXML/RestXMLError.swift | 30 +++++++++---------- .../Errors/ComplexXMLError+ResponseInit.swift | 4 +-- .../ComplexXMLErrorNoErrorWrapping+Init.swift | 4 +-- .../Errors/InvalidGreeting+ResponseInit.swift | 4 +-- ...Ec2QueryHttpResponseTraitWithoutPayload.kt | 3 +- ...yHttpResponseBindingErrorGeneratorTests.kt | 3 +- ...LHttpResponseBindingErrorGeneratorTests.kt | 6 ++-- 9 files changed, 31 insertions(+), 50 deletions(-) diff --git a/AWSClientRuntime/Sources/Protocols/Ec2Query/Ec2QueryError.swift b/AWSClientRuntime/Sources/Protocols/Ec2Query/Ec2QueryError.swift index 63ec901b64b..8f981f137d6 100644 --- a/AWSClientRuntime/Sources/Protocols/Ec2Query/Ec2QueryError.swift +++ b/AWSClientRuntime/Sources/Protocols/Ec2Query/Ec2QueryError.swift @@ -13,22 +13,16 @@ public struct Ec2QueryError { public let message: String? public init(httpResponse: HttpResponse) throws { - if case .data(let data) = httpResponse.body, - let responseBody = data { - let decoded: Ec2Response = try XMLDecoder().decode(responseBody: responseBody) - self.errorCode = decoded.errors.error.code - self.message = decoded.errors.error.message - self.requestId = decoded.requestId - return - } else if case .stream(let byteStream) = httpResponse.body { - let decoded: Ec2Response = try XMLDecoder().decode(responseBody: byteStream.toBytes().getData()) - self.errorCode = decoded.errors.error.code - self.message = decoded.errors.error.message - self.requestId = decoded.requestId + guard let data = httpResponse.body.toBytes()?.getData() else { + errorCode = nil + requestId = nil + message = nil return } - errorCode = nil - requestId = nil - message = nil + + let decoded: Ec2Response = try XMLDecoder().decode(responseBody: data) + self.errorCode = decoded.errors.error.code + self.message = decoded.errors.error.message + self.requestId = decoded.requestId } } diff --git a/AWSClientRuntime/Sources/Protocols/RestJSON/RestJSONError.swift b/AWSClientRuntime/Sources/Protocols/RestJSON/RestJSONError.swift index e2713c27b44..82ea259d2da 100644 --- a/AWSClientRuntime/Sources/Protocols/RestJSON/RestJSONError.swift +++ b/AWSClientRuntime/Sources/Protocols/RestJSON/RestJSONError.swift @@ -35,8 +35,7 @@ public struct RestJSONError { var type = httpResponse.headers.value(for: X_AMZN_ERROR_TYPE_HEADER_NAME) - if case .stream(let reader) = httpResponse.body { - let data = reader.toBytes().getData() + if let data = httpResponse.body.toBytes()?.getData() { let output: RestJSONErrorPayload = try JSONDecoder().decode(responseBody: data) if message == nil { message = output.resolvedErrorMessage diff --git a/AWSClientRuntime/Sources/Protocols/RestXML/RestXMLError.swift b/AWSClientRuntime/Sources/Protocols/RestXML/RestXMLError.swift index 14611608fcc..5d2f0824144 100644 --- a/AWSClientRuntime/Sources/Protocols/RestXML/RestXMLError.swift +++ b/AWSClientRuntime/Sources/Protocols/RestXML/RestXMLError.swift @@ -12,25 +12,23 @@ public struct RestXMLError { public let requestId: String? public let message: String? public init(httpResponse: HttpResponse) throws { - switch httpResponse.body { - case .stream(let reader): - let responseBody = reader.toBytes().getData() - do { - let decoded: ErrorResponseContainer - decoded = try XMLDecoder().decode(responseBody: responseBody) - self.errorCode = decoded.error.errorCode - self.message = decoded.error.message - self.requestId = decoded.requestId - } catch { - let decoded: RestXMLErrorNoErrorWrappingPayload = try XMLDecoder().decode(responseBody: responseBody) - self.errorCode = decoded.errorCode - self.message = decoded.message - self.requestId = decoded.requestId - } - default: + guard let data = httpResponse.body.toBytes()?.getData() else { errorCode = nil requestId = nil message = nil + return + } + do { + let decoded: ErrorResponseContainer + decoded = try XMLDecoder().decode(responseBody: data) + self.errorCode = decoded.error.errorCode + self.message = decoded.error.message + self.requestId = decoded.requestId + } catch { + let decoded: RestXMLErrorNoErrorWrappingPayload = try XMLDecoder().decode(responseBody: data) + self.errorCode = decoded.errorCode + self.message = decoded.message + self.requestId = decoded.requestId } } public init(errorCode: String? = nil, requestId: String? = nil, message: String? = nil) { diff --git a/AWSClientRuntime/Tests/Protocols/RestXML/Models/Errors/ComplexXMLError+ResponseInit.swift b/AWSClientRuntime/Tests/Protocols/RestXML/Models/Errors/ComplexXMLError+ResponseInit.swift index 6312eabe662..31331bb18c3 100644 --- a/AWSClientRuntime/Tests/Protocols/RestXML/Models/Errors/ComplexXMLError+ResponseInit.swift +++ b/AWSClientRuntime/Tests/Protocols/RestXML/Models/Errors/ComplexXMLError+ResponseInit.swift @@ -18,9 +18,7 @@ extension ComplexXMLError: AWSHttpServiceError { self.header = nil } - if case .stream(let reader) = httpResponse.body, - let responseDecoder = decoder { - let data = reader.toBytes().getData() + if let data = httpResponse.body.toBytes()?.getData(), let responseDecoder = decoder { let output: ErrorResponseContainer = try responseDecoder.decode(responseBody: data) self.nested = output.error.nested self.topLevel = output.error.topLevel diff --git a/AWSClientRuntime/Tests/Protocols/RestXML/Models/Errors/ComplexXMLErrorNoErrorWrapping+Init.swift b/AWSClientRuntime/Tests/Protocols/RestXML/Models/Errors/ComplexXMLErrorNoErrorWrapping+Init.swift index 96ff1bd8e3f..8e3ad684d5d 100644 --- a/AWSClientRuntime/Tests/Protocols/RestXML/Models/Errors/ComplexXMLErrorNoErrorWrapping+Init.swift +++ b/AWSClientRuntime/Tests/Protocols/RestXML/Models/Errors/ComplexXMLErrorNoErrorWrapping+Init.swift @@ -17,9 +17,7 @@ extension ComplexXMLErrorNoErrorWrapping: AWSHttpServiceError { } else { self.header = nil } - if case .stream(let reader) = httpResponse.body, - let responseDecoder = decoder { - let data = reader.toBytes().getData() + if let data = httpResponse.body.toBytes()?.getData(), let responseDecoder = decoder { let output: ComplexXMLErrorNoErrorWrappingBody = try responseDecoder.decode(responseBody: data) self.nested = output.nested self.topLevel = output.topLevel diff --git a/AWSClientRuntime/Tests/Protocols/RestXML/Models/Errors/InvalidGreeting+ResponseInit.swift b/AWSClientRuntime/Tests/Protocols/RestXML/Models/Errors/InvalidGreeting+ResponseInit.swift index 4f1d1198a69..865edc883cf 100644 --- a/AWSClientRuntime/Tests/Protocols/RestXML/Models/Errors/InvalidGreeting+ResponseInit.swift +++ b/AWSClientRuntime/Tests/Protocols/RestXML/Models/Errors/InvalidGreeting+ResponseInit.swift @@ -13,9 +13,7 @@ import ClientRuntime extension InvalidGreeting: AWSHttpServiceError { public init (httpResponse: HttpResponse, decoder: ResponseDecoder? = nil, message: String? = nil, requestID: String? = nil) throws { - if case .stream(let reader) = httpResponse.body, - let responseDecoder = decoder { - let data = reader.toBytes().getData() + if let data = httpResponse.body.toBytes()?.getData(), let responseDecoder = decoder { let output: InvalidGreetingBody = try responseDecoder.decode(responseBody: data) self.message = output.message } else { diff --git a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/ec2query/httpResponse/AWSEc2QueryHttpResponseTraitWithoutPayload.kt b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/ec2query/httpResponse/AWSEc2QueryHttpResponseTraitWithoutPayload.kt index cd5b305ec7e..b50edf5705e 100644 --- a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/ec2query/httpResponse/AWSEc2QueryHttpResponseTraitWithoutPayload.kt +++ b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/ec2query/httpResponse/AWSEc2QueryHttpResponseTraitWithoutPayload.kt @@ -36,10 +36,9 @@ class AWSEc2QueryHttpResponseTraitWithoutPayload( .toMutableSet() if (bodyMembersWithoutQueryTrait.isNotEmpty()) { - writer.write("if case .stream(let reader) = httpResponse.body,") + writer.write("if let data = httpResponse.body.toBytes()?.getData(),") writer.indent() writer.write("let responseDecoder = decoder {") - writer.write("let data = reader.toBytes().getData()") renderWithoutErrorResponseContainer(outputShapeName, bodyMembersWithoutQueryTrait) writer.dedent() diff --git a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/ec2query/Ec2QueryHttpResponseBindingErrorGeneratorTests.kt b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/ec2query/Ec2QueryHttpResponseBindingErrorGeneratorTests.kt index 7fc64890bba..9a3a9ff2e80 100644 --- a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/ec2query/Ec2QueryHttpResponseBindingErrorGeneratorTests.kt +++ b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/ec2query/Ec2QueryHttpResponseBindingErrorGeneratorTests.kt @@ -66,9 +66,8 @@ class Ec2QueryHttpResponseBindingErrorGeneratorTests { """ extension ComplexError { public init (httpResponse: ClientRuntime.HttpResponse, decoder: ClientRuntime.ResponseDecoder? = nil, message: Swift.String? = nil, requestID: Swift.String? = nil) throws { - if case .stream(let reader) = httpResponse.body, + if let data = httpResponse.body.toBytes()?.getData(), let responseDecoder = decoder { - let data = reader.toBytes().getData() let output: AWSClientRuntime.Ec2NarrowedResponse = try responseDecoder.decode(responseBody: data) self.nested = output.errors.error.nested self.topLevel = output.errors.error.topLevel diff --git a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/restxml/AWSRestXMLHttpResponseBindingErrorGeneratorTests.kt b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/restxml/AWSRestXMLHttpResponseBindingErrorGeneratorTests.kt index a025766032a..350549affe2 100644 --- a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/restxml/AWSRestXMLHttpResponseBindingErrorGeneratorTests.kt +++ b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/restxml/AWSRestXMLHttpResponseBindingErrorGeneratorTests.kt @@ -71,9 +71,8 @@ class AWSRestXMLHttpResponseBindingErrorGeneratorTests { } else { self.header = nil } - if case .stream(let reader) = httpResponse.body, + if let data = httpResponse.body.toBytes()?.getData(), let responseDecoder = decoder { - let data = reader.toBytes().getData() let output: AWSClientRuntime.ErrorResponseContainer = try responseDecoder.decode(responseBody: data) self.nested = output.error.nested self.topLevel = output.error.topLevel @@ -137,9 +136,8 @@ class AWSRestXMLHttpResponseBindingErrorGeneratorTests { } else { self.header = nil } - if case .stream(let reader) = httpResponse.body, + if let data = httpResponse.body.toBytes()?.getData(), let responseDecoder = decoder { - let data = reader.toBytes().getData() let output: ComplexXMLErrorNoErrorWrappingBody = try responseDecoder.decode(responseBody: data) self.nested = output.nested self.topLevel = output.topLevel From 7e356ce198cc6d74125d64eb63503c70fa0d1fdd Mon Sep 17 00:00:00 2001 From: Ed Paulosky Date: Thu, 22 Dec 2022 14:04:42 -0500 Subject: [PATCH 11/13] Updates codegen --- .../httpResponse/AWSXMLHttpResponseTraitWithoutPayload.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/restxml/httpResponse/AWSXMLHttpResponseTraitWithoutPayload.kt b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/restxml/httpResponse/AWSXMLHttpResponseTraitWithoutPayload.kt index 32a74737e34..6abf4330fb7 100644 --- a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/restxml/httpResponse/AWSXMLHttpResponseTraitWithoutPayload.kt +++ b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/restxml/httpResponse/AWSXMLHttpResponseTraitWithoutPayload.kt @@ -38,10 +38,9 @@ class AWSXMLHttpResponseTraitWithoutPayload( .toMutableSet() if (bodyMembersWithoutQueryTrait.isNotEmpty()) { - writer.write("if case .stream(let reader) = httpResponse.body,") + writer.write("if let data = httpResponse.body.toBytes()?.getData(),") writer.indent() writer.write("let responseDecoder = decoder {") - writer.write("let data = reader.toBytes().getData()") if (serviceDisablesWrappingOfErrorProperties()) { renderWithoutErrorResponseContainer(outputShapeName, bodyMembersWithoutQueryTrait) } else { From 249540c879a4075ee72b5b4a8ebdefdb7e30de8f Mon Sep 17 00:00:00 2001 From: Ed Paulosky Date: Thu, 29 Dec 2022 14:05:10 -0500 Subject: [PATCH 12/13] Adds customization for Route53 ChangeResourceRecordSets to handle InvalidBatchError --- .../Route53InvalidBatchErrorIntegration.kt | 91 +++++++++++++++++++ .../route53/Route53ModelUtils.kt | 7 ++ .../route53/Route53TrimHostedZone.kt | 6 +- ...swift.codegen.integration.SwiftIntegration | 1 + ...oute53InvalidBatchErrorIntegrationTests.kt | 90 ++++++++++++++++++ .../route53-invalidbatch.smithy | 28 ++++++ 6 files changed, 220 insertions(+), 3 deletions(-) create mode 100644 codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/customization/route53/Route53InvalidBatchErrorIntegration.kt create mode 100644 codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/customization/route53/Route53ModelUtils.kt create mode 100644 codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/customizations/Route53InvalidBatchErrorIntegrationTests.kt create mode 100644 codegen/smithy-aws-swift-codegen/src/test/resources/software.amazon.smithy.aws.swift.codegen/route53-invalidbatch.smithy diff --git a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/customization/route53/Route53InvalidBatchErrorIntegration.kt b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/customization/route53/Route53InvalidBatchErrorIntegration.kt new file mode 100644 index 00000000000..60c6fb7e656 --- /dev/null +++ b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/customization/route53/Route53InvalidBatchErrorIntegration.kt @@ -0,0 +1,91 @@ +package software.amazon.smithy.aws.swift.codegen.customization.route53 + +import software.amazon.smithy.aws.swift.codegen.restxml.AWSRestXMLHttpResponseBindingErrorGenerator +import software.amazon.smithy.model.Model +import software.amazon.smithy.model.shapes.ServiceShape +import software.amazon.smithy.swift.codegen.SwiftSettings +import software.amazon.smithy.swift.codegen.SwiftDelegator +import software.amazon.smithy.swift.codegen.SwiftDependency +import software.amazon.smithy.swift.codegen.SwiftWriter +import software.amazon.smithy.swift.codegen.core.CodegenContext +import software.amazon.smithy.swift.codegen.integration.ProtocolGenerator +import software.amazon.smithy.swift.codegen.integration.SectionWriter +import software.amazon.smithy.swift.codegen.integration.SectionWriterBinding +import software.amazon.smithy.swift.codegen.integration.SwiftIntegration +import software.amazon.smithy.swift.codegen.model.expectShape + +class Route53InvalidBatchErrorIntegration : SwiftIntegration { + override fun enabledForService(model: Model, settings: SwiftSettings): Boolean { + return model.expectShape(settings.service).isRoute53 + } + + override val sectionWriters: List + get() = listOf( + SectionWriterBinding(AWSRestXMLHttpResponseBindingErrorGenerator.RestXMLResponseBindingSectionId, httpResponseBindingErrorGenerator) + ) + + private val httpResponseBindingErrorGenerator = SectionWriter { writer, previousCode -> + val operationErrorName = writer.getContext("operationErrorName") as String + if (operationErrorName == "ChangeResourceRecordSetsOutputError") { + writer.openBlock("if let customBatchError = CustomInvalidBatchError.makeFromHttpResponse(httpResponse) {", "}") { + writer.openBlock("let invalidChangeBatchError = InvalidChangeBatch(", ")") { + writer.write("customError: customBatchError,") + writer.write("headers: httpResponse.headers,") + writer.write("statusCode: httpResponse.statusCode") + } + writer.write("self = .invalidChangeBatch(invalidChangeBatchError)") + writer.write("return") + } + } + writer.write(previousCode) + } + + override fun writeAdditionalFiles(ctx: CodegenContext, protocolGenerationContext: ProtocolGenerator.GenerationContext, delegator: SwiftDelegator) { + delegator.useFileWriter("${ctx.settings.moduleName}/models/ChangeResourceRecordSetsOutputError+Customization.swift") { writer -> + writer.addImport(SwiftDependency.CLIENT_RUNTIME.target) + renderCustomInvalidBatchError(writer) + renderInvalidChangeBatch(writer) + } + } + + private fun renderCustomInvalidBatchError(writer: SwiftWriter) { + writer.openBlock("struct CustomInvalidBatchError: Decodable {", "}") { + writer.openBlock("struct Message: Decodable {", "}") { + writer.write("let message: String") + writer.openBlock("enum CodingKeys: String, CodingKey {", "}") { + writer.write("case message = \"Message\"") + } + } + writer.write("let requestId: String") + writer.write("let messages: [String]?") + writer.openBlock("enum CodingKeys: String, CodingKey {", "}") { + writer.write("case messages = \"Messages\"") + writer.write("case requestId = \"RequestId\"") + } + writer.openBlock("init(from decoder: Decoder) throws {", "}") { + writer.write("let container = try decoder.container(keyedBy: CodingKeys.self)") + writer.write("self.requestId = try container.decode(String.self, forKey: .requestId)") + writer.write("let messages = try container.decodeIfPresent([Message].self, forKey: .messages)") + writer.write("self.messages = messages?.map(\\.message)") + } + writer.openBlock("static func makeFromHttpResponse(_ httpResponse: ClientRuntime.HttpResponse) -> CustomInvalidBatchError? {", "}") { + writer.openBlock("guard let data = httpResponse.body.toBytes()?.getData() else {", "}") { + writer.write("return nil") + } + writer.write("return try? XMLDecoder().decode(CustomInvalidBatchError.self, from: data)") + } + } + + } + + private fun renderInvalidChangeBatch(writer: SwiftWriter) { + writer.openBlock("extension InvalidChangeBatch {", "}") { + writer.openBlock("init(customError: CustomInvalidBatchError, headers: Headers?, statusCode: HttpStatusCode?) {", "}") { + writer.write("self.init(messages: customError.messages)") + writer.write("self._requestID = customError.requestId") + writer.write("self._headers = headers") + writer.write("self._statusCode = statusCode") + } + } + } +} \ No newline at end of file diff --git a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/customization/route53/Route53ModelUtils.kt b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/customization/route53/Route53ModelUtils.kt new file mode 100644 index 00000000000..5915b208103 --- /dev/null +++ b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/customization/route53/Route53ModelUtils.kt @@ -0,0 +1,7 @@ +package software.amazon.smithy.aws.swift.codegen.customization.route53 + +import software.amazon.smithy.aws.swift.codegen.sdkId +import software.amazon.smithy.model.shapes.ServiceShape + +val ServiceShape.isRoute53: Boolean + get() = sdkId.lowercase() == "route53" \ No newline at end of file diff --git a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/customization/route53/Route53TrimHostedZone.kt b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/customization/route53/Route53TrimHostedZone.kt index 3685b933eb4..da0f9053cc6 100644 --- a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/customization/route53/Route53TrimHostedZone.kt +++ b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/customization/route53/Route53TrimHostedZone.kt @@ -12,13 +12,13 @@ import software.amazon.smithy.swift.codegen.integration.ProtocolGenerator import software.amazon.smithy.swift.codegen.integration.SwiftIntegration import software.amazon.smithy.swift.codegen.integration.middlewares.handlers.MiddlewareShapeUtils import software.amazon.smithy.swift.codegen.middleware.OperationMiddleware +import software.amazon.smithy.swift.codegen.model.expectShape +import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.swift.codegen.model.hasTrait -private val Route53ShapeId: ShapeId = ShapeId.from("com.amazonaws.route53#AWSDnsV20130401") - class Route53TrimHostedZone : SwiftIntegration { override fun enabledForService(model: Model, settings: SwiftSettings): Boolean { - return settings.service == Route53ShapeId + return model.expectShape(settings.service).isRoute53 } override fun preprocessModel(model: Model, settings: SwiftSettings): Model { return ModelTransformer.create().mapShapes(model) { diff --git a/codegen/smithy-aws-swift-codegen/src/main/resources/META-INF/services/software.amazon.smithy.swift.codegen.integration.SwiftIntegration b/codegen/smithy-aws-swift-codegen/src/main/resources/META-INF/services/software.amazon.smithy.swift.codegen.integration.SwiftIntegration index 3ad0aead2b3..c188fb99c68 100644 --- a/codegen/smithy-aws-swift-codegen/src/main/resources/META-INF/services/software.amazon.smithy.swift.codegen.integration.SwiftIntegration +++ b/codegen/smithy-aws-swift-codegen/src/main/resources/META-INF/services/software.amazon.smithy.swift.codegen.integration.SwiftIntegration @@ -2,6 +2,7 @@ software.amazon.smithy.aws.swift.codegen.AddProtocols software.amazon.smithy.aws.swift.codegen.customization.s3.S3ErrorIntegration software.amazon.smithy.aws.swift.codegen.customization.s3.S3Expires software.amazon.smithy.aws.swift.codegen.customization.route53.Route53TrimHostedZone +software.amazon.smithy.aws.swift.codegen.customization.route53.Route53InvalidBatchErrorIntegration software.amazon.smithy.aws.swift.codegen.customization.apigateway.ApiGatewayAddAcceptHeader software.amazon.smithy.aws.swift.codegen.customization.glacier.GlacierAddVersionHeader software.amazon.smithy.aws.swift.codegen.customization.glacier.GlacierAccountIdDefault diff --git a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/customizations/Route53InvalidBatchErrorIntegrationTests.kt b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/customizations/Route53InvalidBatchErrorIntegrationTests.kt new file mode 100644 index 00000000000..2e73a8c9d69 --- /dev/null +++ b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/customizations/Route53InvalidBatchErrorIntegrationTests.kt @@ -0,0 +1,90 @@ +package software.amazon.smithy.aws.swift.codegen.customizations + +import io.kotest.matchers.string.shouldContainOnlyOnce +import org.junit.jupiter.api.Test +import software.amazon.smithy.aws.swift.codegen.TestContext +import software.amazon.smithy.aws.swift.codegen.TestContextGenerator +import software.amazon.smithy.aws.swift.codegen.restjson.AWSRestJson1ProtocolGenerator +import software.amazon.smithy.aws.swift.codegen.restxml.RestXmlProtocolGenerator +import software.amazon.smithy.aws.swift.codegen.shouldSyntacticSanityCheck +import software.amazon.smithy.aws.traits.protocols.RestJson1Trait +import software.amazon.smithy.aws.traits.protocols.RestXmlTrait + +class Route53InvalidBatchErrorIntegrationTests { + + @Test + fun `001 test additional structs and extensions are generated`() { + val context = setupTests("route53-invalidbatch.smithy", "com.amazonaws.route53#Route53") + val contents = TestContextGenerator.getFileContents(context.manifest, "/Example/models/ChangeResourceRecordSetsOutputError+Customization.swift") + contents.shouldSyntacticSanityCheck() + val expectedContents = + """ + struct CustomInvalidBatchError: Decodable { + struct Message: Decodable { + let message: String + enum CodingKeys: String, CodingKey { + case message = "Message" + } + } + let requestId: String + let messages: [String]? + enum CodingKeys: String, CodingKey { + case messages = "Messages" + case requestId = "RequestId" + } + init(from decoder: Decoder) throws { + let container = try decoder.container(keyedBy: CodingKeys.self) + self.requestId = try container.decode(String.self, forKey: .requestId) + let messages = try container.decodeIfPresent([Message].self, forKey: .messages) + self.messages = messages?.map(\.message) + } + static func makeFromHttpResponse(_ httpResponse: ClientRuntime.HttpResponse) -> CustomInvalidBatchError? { + guard let data = httpResponse.body.toBytes()?.getData() else { + return nil + } + return try? XMLDecoder().decode(CustomInvalidBatchError.self, from: data) + } + } + extension InvalidChangeBatch { + init(customError: CustomInvalidBatchError, headers: Headers?, statusCode: HttpStatusCode?) { + self.init(messages: customError.messages) + self._requestID = customError.requestId + self._headers = headers + self._statusCode = statusCode + } + } + """.trimIndent() + contents.shouldContainOnlyOnce(expectedContents) + } + + @Test + fun `002 test ChangeResourceRecordSetsOutputError+HttpResponseBinding is customized`() { + val context = setupTests("route53-invalidbatch.smithy", "com.amazonaws.route53#Route53") + val contents = TestContextGenerator.getFileContents(context.manifest, "/Example/models/ChangeResourceRecordSetsOutputError+HttpResponseBinding.swift") + contents.shouldSyntacticSanityCheck() + val expectedContents = + """ + extension ChangeResourceRecordSetsOutputError: ClientRuntime.HttpResponseBinding { + public init(httpResponse: ClientRuntime.HttpResponse, decoder: ClientRuntime.ResponseDecoder? = nil) throws { + if let customBatchError = CustomInvalidBatchError.makeFromHttpResponse(httpResponse) { + let invalidChangeBatchError = InvalidChangeBatch( + customError: customBatchError, + headers: httpResponse.headers, + statusCode: httpResponse.statusCode + ) + self = .invalidChangeBatch(invalidChangeBatchError) + return + } + let errorDetails = try AWSClientRuntime.RestXMLError(httpResponse: httpResponse) + try self.init(errorType: errorDetails.errorCode, httpResponse: httpResponse, decoder: decoder, message: errorDetails.message, requestID: errorDetails.requestId) + } + } + """.trimIndent() + contents.shouldContainOnlyOnce(expectedContents) + } + + private fun setupTests(smithyFile: String, serviceShapeId: String): TestContext { + val context = TestContextGenerator.initContextFrom(smithyFile, serviceShapeId, RestXmlTrait.ID) + return context + } +} \ No newline at end of file diff --git a/codegen/smithy-aws-swift-codegen/src/test/resources/software.amazon.smithy.aws.swift.codegen/route53-invalidbatch.smithy b/codegen/smithy-aws-swift-codegen/src/test/resources/software.amazon.smithy.aws.swift.codegen/route53-invalidbatch.smithy new file mode 100644 index 00000000000..3bfd6729952 --- /dev/null +++ b/codegen/smithy-aws-swift-codegen/src/test/resources/software.amazon.smithy.aws.swift.codegen/route53-invalidbatch.smithy @@ -0,0 +1,28 @@ +$version: "1.0" +namespace com.amazonaws.route53 + +use aws.api#service +use aws.protocols#restXml + +@service(sdkId: "Route53") +@restXml +service Route53 { + version: "2019-12-16", + operations: [ChangeResourceRecordSets] +} + +@http(uri: "/ChangeResourceRecordSets", method: "POST") +operation ChangeResourceRecordSets { + input: InputOutput + output: InputOutput + errors: [InvalidChangeBatch] +} + +structure InputOutput { + foo: String +} + +@error("client") +structure InvalidChangeBatch { + message: String +} \ No newline at end of file From 6b619cb9bb106d4b6217b2c240639c6e030b7127 Mon Sep 17 00:00:00 2001 From: Ed Paulosky Date: Thu, 29 Dec 2022 17:26:23 -0500 Subject: [PATCH 13/13] ktlintformat --- .../route53/Route53InvalidBatchErrorIntegration.kt | 5 ++--- .../swift/codegen/customization/route53/Route53ModelUtils.kt | 2 +- .../codegen/customization/route53/Route53TrimHostedZone.kt | 2 +- .../Route53InvalidBatchErrorIntegrationTests.kt | 5 +---- 4 files changed, 5 insertions(+), 9 deletions(-) diff --git a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/customization/route53/Route53InvalidBatchErrorIntegration.kt b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/customization/route53/Route53InvalidBatchErrorIntegration.kt index 60c6fb7e656..6c72dd5069a 100644 --- a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/customization/route53/Route53InvalidBatchErrorIntegration.kt +++ b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/customization/route53/Route53InvalidBatchErrorIntegration.kt @@ -3,9 +3,9 @@ package software.amazon.smithy.aws.swift.codegen.customization.route53 import software.amazon.smithy.aws.swift.codegen.restxml.AWSRestXMLHttpResponseBindingErrorGenerator import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.ServiceShape -import software.amazon.smithy.swift.codegen.SwiftSettings import software.amazon.smithy.swift.codegen.SwiftDelegator import software.amazon.smithy.swift.codegen.SwiftDependency +import software.amazon.smithy.swift.codegen.SwiftSettings import software.amazon.smithy.swift.codegen.SwiftWriter import software.amazon.smithy.swift.codegen.core.CodegenContext import software.amazon.smithy.swift.codegen.integration.ProtocolGenerator @@ -75,7 +75,6 @@ class Route53InvalidBatchErrorIntegration : SwiftIntegration { writer.write("return try? XMLDecoder().decode(CustomInvalidBatchError.self, from: data)") } } - } private fun renderInvalidChangeBatch(writer: SwiftWriter) { @@ -88,4 +87,4 @@ class Route53InvalidBatchErrorIntegration : SwiftIntegration { } } } -} \ No newline at end of file +} diff --git a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/customization/route53/Route53ModelUtils.kt b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/customization/route53/Route53ModelUtils.kt index 5915b208103..0b5fa09fd7f 100644 --- a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/customization/route53/Route53ModelUtils.kt +++ b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/customization/route53/Route53ModelUtils.kt @@ -4,4 +4,4 @@ import software.amazon.smithy.aws.swift.codegen.sdkId import software.amazon.smithy.model.shapes.ServiceShape val ServiceShape.isRoute53: Boolean - get() = sdkId.lowercase() == "route53" \ No newline at end of file + get() = sdkId.lowercase() == "route53" diff --git a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/customization/route53/Route53TrimHostedZone.kt b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/customization/route53/Route53TrimHostedZone.kt index da0f9053cc6..a7297795d68 100644 --- a/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/customization/route53/Route53TrimHostedZone.kt +++ b/codegen/smithy-aws-swift-codegen/src/main/kotlin/software/amazon/smithy/aws/swift/codegen/customization/route53/Route53TrimHostedZone.kt @@ -3,6 +3,7 @@ package software.amazon.smithy.aws.swift.codegen.customization.route53 import software.amazon.smithy.model.Model import software.amazon.smithy.model.shapes.MemberShape import software.amazon.smithy.model.shapes.OperationShape +import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.model.shapes.Shape import software.amazon.smithy.model.shapes.ShapeId import software.amazon.smithy.model.traits.HttpLabelTrait @@ -13,7 +14,6 @@ import software.amazon.smithy.swift.codegen.integration.SwiftIntegration import software.amazon.smithy.swift.codegen.integration.middlewares.handlers.MiddlewareShapeUtils import software.amazon.smithy.swift.codegen.middleware.OperationMiddleware import software.amazon.smithy.swift.codegen.model.expectShape -import software.amazon.smithy.model.shapes.ServiceShape import software.amazon.smithy.swift.codegen.model.hasTrait class Route53TrimHostedZone : SwiftIntegration { diff --git a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/customizations/Route53InvalidBatchErrorIntegrationTests.kt b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/customizations/Route53InvalidBatchErrorIntegrationTests.kt index 2e73a8c9d69..ea023757dfa 100644 --- a/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/customizations/Route53InvalidBatchErrorIntegrationTests.kt +++ b/codegen/smithy-aws-swift-codegen/src/test/kotlin/software/amazon/smithy/aws/swift/codegen/customizations/Route53InvalidBatchErrorIntegrationTests.kt @@ -4,10 +4,7 @@ import io.kotest.matchers.string.shouldContainOnlyOnce import org.junit.jupiter.api.Test import software.amazon.smithy.aws.swift.codegen.TestContext import software.amazon.smithy.aws.swift.codegen.TestContextGenerator -import software.amazon.smithy.aws.swift.codegen.restjson.AWSRestJson1ProtocolGenerator -import software.amazon.smithy.aws.swift.codegen.restxml.RestXmlProtocolGenerator import software.amazon.smithy.aws.swift.codegen.shouldSyntacticSanityCheck -import software.amazon.smithy.aws.traits.protocols.RestJson1Trait import software.amazon.smithy.aws.traits.protocols.RestXmlTrait class Route53InvalidBatchErrorIntegrationTests { @@ -87,4 +84,4 @@ class Route53InvalidBatchErrorIntegrationTests { val context = TestContextGenerator.initContextFrom(smithyFile, serviceShapeId, RestXmlTrait.ID) return context } -} \ No newline at end of file +}