-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #85 from amzn/aws_client_protocol_async_await_support
Experimental async/await support. ReportingConfiguration documentation.
- Loading branch information
Showing
8 changed files
with
252 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
Sources/_SmokeAWSHttpConcurrency/AWSClientProtocol.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
// | ||
// AWSClientProtocol.swift | ||
// | ||
|
||
#if compiler(>=5.5) && $AsyncAwait | ||
|
||
import SmokeHTTPClient | ||
import SmokeAWSCore | ||
import NIO | ||
import NIOHTTP1 | ||
import NIOTransportServices | ||
import AsyncHTTPClient | ||
import SmokeAWSHttp | ||
import _SmokeHTTPClientConcurrency | ||
|
||
public extension AWSClientProtocol { | ||
func executeWithoutOutput<InvocationReportingType: HTTPClientInvocationReporting, | ||
InputType: HTTPRequestInputProtocol, ErrorType: ConvertableError>( | ||
httpClient: HTTPOperationsClient, | ||
endpointPath: String = "/", | ||
httpMethod: HTTPMethod = .POST, | ||
requestInput: InputType, | ||
operation: String, | ||
reporting: InvocationReportingType, | ||
signAllHeaders: Bool = false, | ||
errorType: ErrorType.Type) async throws { | ||
let handlerDelegate = AWSClientInvocationDelegate( | ||
credentialsProvider: credentialsProvider, | ||
awsRegion: awsRegion, | ||
service: service, | ||
operation: operation, | ||
target: target, | ||
signAllHeaders: signAllHeaders) | ||
|
||
let invocationContext = HTTPClientInvocationContext(reporting: reporting, | ||
handlerDelegate: handlerDelegate) | ||
|
||
do { | ||
return try await httpClient.executeRetriableWithoutOutput( | ||
endpointPath: endpointPath, | ||
httpMethod: httpMethod, | ||
input: requestInput, | ||
invocationContext: invocationContext, | ||
retryConfiguration: retryConfiguration, | ||
retryOnError: retryOnErrorProvider) | ||
} catch { | ||
let typedError: ErrorType = error.asTypedError() | ||
throw typedError | ||
} | ||
} | ||
|
||
func executeWithOutput<OutputType: HTTPResponseOutputProtocol, InvocationReportingType: HTTPClientInvocationReporting, | ||
InputType: HTTPRequestInputProtocol, ErrorType: ConvertableError>( | ||
httpClient: HTTPOperationsClient, | ||
endpointPath: String = "/", | ||
httpMethod: HTTPMethod = .POST, | ||
requestInput: InputType, | ||
operation: String, | ||
reporting: InvocationReportingType, | ||
signAllHeaders: Bool = false, | ||
errorType: ErrorType.Type) async throws -> OutputType { | ||
let handlerDelegate = AWSClientInvocationDelegate( | ||
credentialsProvider: credentialsProvider, | ||
awsRegion: awsRegion, | ||
service: service, | ||
operation: operation, | ||
target: target, | ||
signAllHeaders: signAllHeaders) | ||
|
||
let invocationContext = HTTPClientInvocationContext(reporting: reporting, | ||
handlerDelegate: handlerDelegate) | ||
|
||
do { | ||
return try await httpClient.executeRetriableWithOutput( | ||
endpointPath: endpointPath, | ||
httpMethod: httpMethod, | ||
input: requestInput, | ||
invocationContext: invocationContext, | ||
retryConfiguration: retryConfiguration, | ||
retryOnError: retryOnErrorProvider) | ||
} catch { | ||
let typedError: ErrorType = error.asTypedError() | ||
throw typedError | ||
} | ||
} | ||
} | ||
|
||
public struct AWSClientHelper { | ||
public static func getEventLoop(eventLoopGroupProvider: HTTPClient.EventLoopGroupProvider) -> EventLoopGroup { | ||
switch eventLoopGroupProvider { | ||
case .shared(let group): | ||
return group | ||
case .createNew: | ||
#if canImport(Network) | ||
if #available(OSX 10.14, iOS 12.0, tvOS 12.0, watchOS 6.0, *) { | ||
return NIOTSEventLoopGroup() | ||
} else { | ||
return MultiThreadedEventLoopGroup(numberOfThreads: 1) | ||
} | ||
#else | ||
return MultiThreadedEventLoopGroup(numberOfThreads: 1) | ||
#endif | ||
} | ||
} | ||
} | ||
|
||
#endif |
85 changes: 85 additions & 0 deletions
85
Sources/_SmokeAWSHttpConcurrency/AWSQueryClientProtocol.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// | ||
// AWSClientProtocol.swift | ||
// | ||
|
||
#if compiler(>=5.5) && $AsyncAwait | ||
|
||
import SmokeHTTPClient | ||
import SmokeAWSCore | ||
import NIO | ||
import SmokeAWSHttp | ||
import _SmokeHTTPClientConcurrency | ||
|
||
public extension AWSQueryClientProtocol { | ||
func executeWithoutOutput<InvocationReportingType: HTTPClientInvocationReporting, | ||
WrappedInputType: HTTPRequestInputProtocol, ErrorType: ConvertableError>( | ||
httpClient: HTTPOperationsClient, | ||
wrappedInput: WrappedInputType, | ||
action: String, | ||
reporting: InvocationReportingType, | ||
errorType: ErrorType.Type) async throws { | ||
let handlerDelegate = AWSClientInvocationDelegate( | ||
credentialsProvider: credentialsProvider, | ||
awsRegion: awsRegion, | ||
service: service, | ||
target: target) | ||
|
||
let invocationContext = HTTPClientInvocationContext(reporting: reporting, | ||
handlerDelegate: handlerDelegate) | ||
|
||
let requestInput = QueryWrapperHTTPRequestInput( | ||
wrappedInput: wrappedInput, | ||
action: action, | ||
version: apiVersion) | ||
|
||
do { | ||
return try await httpClient.executeRetriableWithoutOutput( | ||
endpointPath: "/", | ||
httpMethod: .POST, | ||
input: requestInput, | ||
invocationContext: invocationContext, | ||
retryConfiguration: retryConfiguration, | ||
retryOnError: retryOnErrorProvider) | ||
} catch { | ||
let typedError: ErrorType = error.asTypedError() | ||
throw typedError | ||
} | ||
} | ||
|
||
func executeWithOutput<OutputType: HTTPResponseOutputProtocol, InvocationReportingType: HTTPClientInvocationReporting, | ||
WrappedInputType: HTTPRequestInputProtocol, ErrorType: ConvertableError>( | ||
httpClient: HTTPOperationsClient, | ||
wrappedInput: WrappedInputType, | ||
action: String, | ||
reporting: InvocationReportingType, | ||
errorType: ErrorType.Type) async throws -> OutputType { | ||
let handlerDelegate = AWSClientInvocationDelegate( | ||
credentialsProvider: credentialsProvider, | ||
awsRegion: awsRegion, | ||
service: service, | ||
target: target) | ||
|
||
let invocationContext = HTTPClientInvocationContext(reporting: reporting, | ||
handlerDelegate: handlerDelegate) | ||
|
||
let requestInput = QueryWrapperHTTPRequestInput( | ||
wrappedInput: wrappedInput, | ||
action: action, | ||
version: apiVersion) | ||
|
||
do { | ||
return try await httpClient.executeRetriableWithOutput( | ||
endpointPath: "/", | ||
httpMethod: .POST, | ||
input: requestInput, | ||
invocationContext: invocationContext, | ||
retryConfiguration: retryConfiguration, | ||
retryOnError: retryOnErrorProvider) | ||
} catch { | ||
let typedError: ErrorType = error.asTypedError() | ||
throw typedError | ||
} | ||
} | ||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters