From 1638da03e85fab2d3bda058408001c816d558678 Mon Sep 17 00:00:00 2001 From: Adam Fowler Date: Tue, 3 Nov 2020 13:39:04 +0000 Subject: [PATCH] Logger Eventloop parameter ordering (#399) * Reorder public function parameters Logger and EventLoop Place Logger before EventLoop. Will make moving to BaggageContext easier * Re-order parameters in paginate command closure --- Sources/SotoCore/AWSClient+Paginate.swift | 36 +++++++++++------------ Sources/SotoCore/AWSClient.swift | 18 ++++++------ Tests/SotoCoreTests/AWSClientTests.swift | 4 +-- Tests/SotoCoreTests/PaginateTests.swift | 22 +++++++------- 4 files changed, 40 insertions(+), 40 deletions(-) diff --git a/Sources/SotoCore/AWSClient+Paginate.swift b/Sources/SotoCore/AWSClient+Paginate.swift index 2b01f0de1..5d9e53254 100644 --- a/Sources/SotoCore/AWSClient+Paginate.swift +++ b/Sources/SotoCore/AWSClient+Paginate.swift @@ -40,17 +40,17 @@ extension AWSClient { public func paginate( input: Input, initialValue: Result, - command: @escaping (Input, EventLoop?, Logger) -> EventLoopFuture, + command: @escaping (Input, Logger, EventLoop?) -> EventLoopFuture, tokenKey: KeyPath, - on eventLoop: EventLoop? = nil, logger: Logger = AWSClient.loggingDisabled, + on eventLoop: EventLoop? = nil, onPage: @escaping (Result, Output, EventLoop) -> EventLoopFuture<(Bool, Result)> ) -> EventLoopFuture { let eventLoop = eventLoop ?? eventLoopGroup.next() let promise = eventLoop.makePromise(of: Result.self) func paginatePart(input: Input, currentValue: Result) { - let responseFuture = command(input, eventLoop, logger) + let responseFuture = command(input, logger, eventLoop) .flatMap { response in return onPage(currentValue, response, eventLoop) .map { continuePaginate, result -> Void in @@ -85,13 +85,13 @@ extension AWSClient { /// - onPage: closure called with each block of entries. Returns boolean indicating whether we should continue. public func paginate( input: Input, - command: @escaping (Input, EventLoop?, Logger) -> EventLoopFuture, + command: @escaping (Input, Logger, EventLoop?) -> EventLoopFuture, tokenKey: KeyPath, - on eventLoop: EventLoop? = nil, logger: Logger = AWSClient.loggingDisabled, + on eventLoop: EventLoop? = nil, onPage: @escaping (Output, EventLoop) -> EventLoopFuture ) -> EventLoopFuture { - self.paginate(input: input, initialValue: (), command: command, tokenKey: tokenKey, on: eventLoop, logger: logger) { _, output, eventLoop in + self.paginate(input: input, initialValue: (), command: command, tokenKey: tokenKey, logger: logger, on: eventLoop) { _, output, eventLoop in return onPage(output, eventLoop).map { rt in (rt, ()) } } } @@ -114,18 +114,18 @@ extension AWSClient { public func paginate( input: Input, initialValue: Result, - command: @escaping (Input, EventLoop?, Logger) -> EventLoopFuture, + command: @escaping (Input, Logger, EventLoop?) -> EventLoopFuture, tokenKey: KeyPath, moreResultsKey: KeyPath, - on eventLoop: EventLoop? = nil, logger: Logger = AWSClient.loggingDisabled, + on eventLoop: EventLoop? = nil, onPage: @escaping (Result, Output, EventLoop) -> EventLoopFuture<(Bool, Result)> ) -> EventLoopFuture { let eventLoop = eventLoop ?? eventLoopGroup.next() let promise = eventLoop.makePromise(of: Result.self) func paginatePart(input: Input, currentValue: Result) { - let responseFuture = command(input, eventLoop, logger) + let responseFuture = command(input, logger, eventLoop) .flatMap { response in return onPage(currentValue, response, eventLoop) .map { continuePaginate, result -> Void in @@ -162,14 +162,14 @@ extension AWSClient { /// - onPage: closure called with each block of entries. Returns boolean indicating whether we should continue. public func paginate( input: Input, - command: @escaping (Input, EventLoop?, Logger) -> EventLoopFuture, + command: @escaping (Input, Logger, EventLoop?) -> EventLoopFuture, tokenKey: KeyPath, moreResultsKey: KeyPath, - on eventLoop: EventLoop? = nil, logger: Logger = AWSClient.loggingDisabled, + on eventLoop: EventLoop? = nil, onPage: @escaping (Output, EventLoop) -> EventLoopFuture ) -> EventLoopFuture { - self.paginate(input: input, initialValue: (), command: command, tokenKey: tokenKey, moreResultsKey: moreResultsKey, on: eventLoop, logger: logger) { _, output, eventLoop in + self.paginate(input: input, initialValue: (), command: command, tokenKey: tokenKey, moreResultsKey: moreResultsKey, logger: logger, on: eventLoop) { _, output, eventLoop in return onPage(output, eventLoop).map { rt in (rt, ()) } } } @@ -192,18 +192,18 @@ extension AWSClient { public func paginate( input: Input, initialValue: Result, - command: @escaping (Input, EventLoop?, Logger) -> EventLoopFuture, + command: @escaping (Input, Logger, EventLoop?) -> EventLoopFuture, tokenKey: KeyPath, moreResultsKey: KeyPath, - on eventLoop: EventLoop? = nil, logger: Logger = AWSClient.loggingDisabled, + on eventLoop: EventLoop? = nil, onPage: @escaping (Result, Output, EventLoop) -> EventLoopFuture<(Bool, Result)> ) -> EventLoopFuture { let eventLoop = eventLoop ?? eventLoopGroup.next() let promise = eventLoop.makePromise(of: Result.self) func paginatePart(input: Input, currentValue: Result) { - let responseFuture = command(input, eventLoop, logger) + let responseFuture = command(input, logger, eventLoop) .flatMap { response in return onPage(currentValue, response, eventLoop) .map { continuePaginate, result -> Void in @@ -240,14 +240,14 @@ extension AWSClient { /// - onPage: closure called with each block of entries. Returns boolean indicating whether we should continue. public func paginate( input: Input, - command: @escaping (Input, EventLoop?, Logger) -> EventLoopFuture, + command: @escaping (Input, Logger, EventLoop?) -> EventLoopFuture, tokenKey: KeyPath, moreResultsKey: KeyPath, - on eventLoop: EventLoop? = nil, logger: Logger = AWSClient.loggingDisabled, + on eventLoop: EventLoop? = nil, onPage: @escaping (Output, EventLoop) -> EventLoopFuture ) -> EventLoopFuture { - self.paginate(input: input, initialValue: (), command: command, tokenKey: tokenKey, moreResultsKey: moreResultsKey, on: eventLoop, logger: logger) { _, output, eventLoop in + self.paginate(input: input, initialValue: (), command: command, tokenKey: tokenKey, moreResultsKey: moreResultsKey, logger: logger, on: eventLoop) { _, output, eventLoop in return onPage(output, eventLoop).map { rt in (rt, ()) } } } diff --git a/Sources/SotoCore/AWSClient.swift b/Sources/SotoCore/AWSClient.swift index 28faef292..64ff56030 100644 --- a/Sources/SotoCore/AWSClient.swift +++ b/Sources/SotoCore/AWSClient.swift @@ -243,8 +243,8 @@ extension AWSClient { httpMethod: HTTPMethod, serviceConfig: AWSServiceConfig, input: Input, - on eventLoop: EventLoop? = nil, - logger: Logger = AWSClient.loggingDisabled + logger: Logger = AWSClient.loggingDisabled, + on eventLoop: EventLoop? = nil ) -> EventLoopFuture { return execute( operation: operationName, @@ -283,8 +283,8 @@ extension AWSClient { path: String, httpMethod: HTTPMethod, serviceConfig: AWSServiceConfig, - on eventLoop: EventLoop? = nil, - logger: Logger = AWSClient.loggingDisabled + logger: Logger = AWSClient.loggingDisabled, + on eventLoop: EventLoop? = nil ) -> EventLoopFuture { return execute( operation: operationName, @@ -322,8 +322,8 @@ extension AWSClient { path: String, httpMethod: HTTPMethod, serviceConfig: AWSServiceConfig, - on eventLoop: EventLoop? = nil, - logger: Logger = AWSClient.loggingDisabled + logger: Logger = AWSClient.loggingDisabled, + on eventLoop: EventLoop? = nil ) -> EventLoopFuture { return execute( operation: operationName, @@ -363,8 +363,8 @@ extension AWSClient { httpMethod: HTTPMethod, serviceConfig: AWSServiceConfig, input: Input, - on eventLoop: EventLoop? = nil, - logger: Logger = AWSClient.loggingDisabled + logger: Logger = AWSClient.loggingDisabled, + on eventLoop: EventLoop? = nil ) -> EventLoopFuture { return execute( operation: operationName, @@ -405,8 +405,8 @@ extension AWSClient { httpMethod: HTTPMethod, serviceConfig: AWSServiceConfig, input: Input, - on eventLoop: EventLoop? = nil, logger: Logger = AWSClient.loggingDisabled, + on eventLoop: EventLoop? = nil, stream: @escaping AWSHTTPClient.ResponseStream ) -> EventLoopFuture { return execute( diff --git a/Tests/SotoCoreTests/AWSClientTests.swift b/Tests/SotoCoreTests/AWSClientTests.swift index 0b8f8deb2..963e6d506 100644 --- a/Tests/SotoCoreTests/AWSClientTests.swift +++ b/Tests/SotoCoreTests/AWSClientTests.swift @@ -638,8 +638,8 @@ class AWSClientTests: XCTestCase { path: "/", httpMethod: .POST, serviceConfig: config, - on: eventLoop, - logger: TestEnvironment.logger + logger: TestEnvironment.logger, + on: eventLoop ) try awsServer.processRaw { _ in diff --git a/Tests/SotoCoreTests/PaginateTests.swift b/Tests/SotoCoreTests/PaginateTests.swift index fbade5e8b..bacf09910 100644 --- a/Tests/SotoCoreTests/PaginateTests.swift +++ b/Tests/SotoCoreTests/PaginateTests.swift @@ -66,15 +66,15 @@ class PaginateTests: XCTestCase { let outputToken: Int? } - func counter(_ input: CounterInput, on eventLoop: EventLoop?, logger: Logger) -> EventLoopFuture { + func counter(_ input: CounterInput, logger: Logger, on eventLoop: EventLoop?) -> EventLoopFuture { return self.client.execute( operation: "TestOperation", path: "/", httpMethod: .POST, serviceConfig: self.config, input: input, - on: eventLoop, - logger: logger + logger: logger, + on: eventLoop ) } @@ -152,15 +152,15 @@ class PaginateTests: XCTestCase { let moreResults: Bool } - func stringList(_ input: StringListInput, on eventLoop: EventLoop? = nil, logger: Logger) -> EventLoopFuture { + func stringList(_ input: StringListInput, logger: Logger, on eventLoop: EventLoop? = nil) -> EventLoopFuture { return self.client.execute( operation: "TestOperation", path: "/", httpMethod: .POST, serviceConfig: self.config, input: input, - on: eventLoop, - logger: logger + logger: logger, + on: eventLoop ) } @@ -170,21 +170,21 @@ class PaginateTests: XCTestCase { command: self.stringList, tokenKey: \StringListOutput.outputToken, moreResultsKey: \StringListOutput.moreResults, - on: eventLoop, logger: TestEnvironment.logger, + on: eventLoop, onPage: onPage ) } - func stringList2(_ input: StringListInput, on eventLoop: EventLoop? = nil, logger: Logger) -> EventLoopFuture { + func stringList2(_ input: StringListInput, logger: Logger, on eventLoop: EventLoop? = nil) -> EventLoopFuture { return self.client.execute( operation: "TestOperation", path: "/", httpMethod: .POST, serviceConfig: self.config, input: input, - on: eventLoop, - logger: logger + logger: logger, + on: eventLoop ) } @@ -195,8 +195,8 @@ class PaginateTests: XCTestCase { command: self.stringList2, tokenKey: \StringList2Output.outputToken, moreResultsKey: \StringList2Output.moreResults, - on: eventLoop, logger: TestEnvironment.logger, + on: eventLoop, onPage: onPage ) }