Skip to content

Commit

Permalink
feat: Modularize Smithy waiters (#1572)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbelkins authored Jun 14, 2024
1 parent 6da9ae3 commit 49c7b5f
Show file tree
Hide file tree
Showing 57 changed files with 1,897 additions and 1,888 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ extension Target.Dependency {
static var smithyIdentityAPI: Self { .product(name: "SmithyIdentityAPI", package: "smithy-swift") }
static var smithyRetries: Self { .product(name: "SmithyRetries", package: "smithy-swift") }
static var smithyRetriesAPI: Self { .product(name: "SmithyRetriesAPI", package: "smithy-swift") }
static var smithyWaitersAPI: Self { .product(name: "SmithyWaitersAPI", package: "smithy-swift") }
static var smithyTestUtils: Self { .product(name: "SmithyTestUtil", package: "smithy-swift") }
}

Expand Down Expand Up @@ -185,6 +186,7 @@ let serviceTargetDependencies: [Target.Dependency] = [
.smithyEventStreamsAuthAPI,
.smithyEventStreams,
.smithyChecksumsAPI,
.smithyWaitersAPI,
.awsSDKCommon,
.awsSDKIdentity,
.awsSDKHTTPAuth,
Expand Down Expand Up @@ -323,7 +325,7 @@ func addProtocolTests() {
)
let testTarget = protocolTest.buildOnly ? nil : Target.testTarget(
name: "\(protocolTest.name)Tests",
dependencies: [.smithyTestUtils, .byNameItem(name: protocolTest.name, condition: nil)],
dependencies: [.smithyTestUtils, .smithyWaitersAPI, .byNameItem(name: protocolTest.name, condition: nil)],
path: "\(protocolTest.testPath ?? protocolTest.sourcePath)/swift-codegen/Tests/\(protocolTest.name)Tests"
)
package.targets += [target, testTarget].compactMap { $0 }
Expand All @@ -333,4 +335,4 @@ func addProtocolTests() {
func addResolvedTargets() {
enabledServices.union(integrationTestServices).forEach(addServiceTarget)
enabledServiceUnitTests.forEach(addServiceUnitTestTarget)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import XCTest
import AWSKinesis
import ClientRuntime
import AWSClientRuntime
import SmithyWaitersAPI

class KinesisTests: XCTestCase {

Expand Down
5 changes: 4 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ extension Target.Dependency {
static var smithyIdentityAPI: Self { .product(name: "SmithyIdentityAPI", package: "smithy-swift") }
static var smithyRetries: Self { .product(name: "SmithyRetries", package: "smithy-swift") }
static var smithyRetriesAPI: Self { .product(name: "SmithyRetriesAPI", package: "smithy-swift") }
static var smithyWaitersAPI: Self { .product(name: "SmithyWaitersAPI", package: "smithy-swift") }
static var smithyTestUtils: Self { .product(name: "SmithyTestUtil", package: "smithy-swift") }
}

Expand Down Expand Up @@ -185,6 +186,7 @@ let serviceTargetDependencies: [Target.Dependency] = [
.smithyEventStreamsAuthAPI,
.smithyEventStreams,
.smithyChecksumsAPI,
.smithyWaitersAPI,
.awsSDKCommon,
.awsSDKIdentity,
.awsSDKHTTPAuth,
Expand Down Expand Up @@ -323,7 +325,7 @@ func addProtocolTests() {
)
let testTarget = protocolTest.buildOnly ? nil : Target.testTarget(
name: "\(protocolTest.name)Tests",
dependencies: [.smithyTestUtils, .byNameItem(name: protocolTest.name, condition: nil)],
dependencies: [.smithyTestUtils, .smithyWaitersAPI, .byNameItem(name: protocolTest.name, condition: nil)],
path: "\(protocolTest.testPath ?? protocolTest.sourcePath)/swift-codegen/Tests/\(protocolTest.name)Tests"
)
package.targets += [target, testTarget].compactMap { $0 }
Expand All @@ -335,6 +337,7 @@ func addResolvedTargets() {
enabledServiceUnitTests.forEach(addServiceUnitTestTarget)
}


// MARK: - Generated

addDependencies(
Expand Down
26 changes: 13 additions & 13 deletions Sources/Services/AWSACM/Sources/AWSACM/Waiters.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// Code generated by smithy-swift-codegen. DO NOT EDIT!

import class ClientRuntime.Waiter
import enum ClientRuntime.JMESUtils
import class SmithyWaitersAPI.Waiter
import enum SmithyWaitersAPI.JMESUtils
import protocol ClientRuntime.ServiceError
import struct ClientRuntime.WaiterConfiguration
import struct ClientRuntime.WaiterOptions
import struct ClientRuntime.WaiterOutcome
import struct SmithyWaitersAPI.WaiterConfiguration
import struct SmithyWaitersAPI.WaiterOptions
import struct SmithyWaitersAPI.WaiterOutcome

extension ACMClient {

static func certificateValidatedWaiterConfig() throws -> ClientRuntime.WaiterConfiguration<DescribeCertificateInput, DescribeCertificateOutput> {
let acceptors: [ClientRuntime.WaiterConfiguration<DescribeCertificateInput, DescribeCertificateOutput>.Acceptor] = [
static func certificateValidatedWaiterConfig() throws -> SmithyWaitersAPI.WaiterConfiguration<DescribeCertificateInput, DescribeCertificateOutput> {
let acceptors: [SmithyWaitersAPI.WaiterConfiguration<DescribeCertificateInput, DescribeCertificateOutput>.Acceptor] = [
.init(state: .success, matcher: { (input: DescribeCertificateInput, result: Swift.Result<DescribeCertificateOutput, Swift.Error>) -> Bool in
// JMESPath expression: "Certificate.DomainValidationOptions[].ValidationStatus"
// JMESPath comparator: "allStringEquals"
Expand All @@ -22,7 +22,7 @@ extension ACMClient {
let validationStatus = original.validationStatus
return validationStatus
}
return (projection?.count ?? 0) > 1 && (projection?.allSatisfy { ClientRuntime.JMESUtils.compare($0, ==, "SUCCESS") } ?? false)
return (projection?.count ?? 0) > 1 && (projection?.allSatisfy { SmithyWaitersAPI.JMESUtils.compare($0, ==, "SUCCESS") } ?? false)
}),
.init(state: .retry, matcher: { (input: DescribeCertificateInput, result: Swift.Result<DescribeCertificateOutput, Swift.Error>) -> Bool in
// JMESPath expression: "Certificate.DomainValidationOptions[].ValidationStatus"
Expand All @@ -35,7 +35,7 @@ extension ACMClient {
let validationStatus = original.validationStatus
return validationStatus
}
return projection?.contains(where: { ClientRuntime.JMESUtils.compare($0, ==, "PENDING_VALIDATION") }) ?? false
return projection?.contains(where: { SmithyWaitersAPI.JMESUtils.compare($0, ==, "PENDING_VALIDATION") }) ?? false
}),
.init(state: .failure, matcher: { (input: DescribeCertificateInput, result: Swift.Result<DescribeCertificateOutput, Swift.Error>) -> Bool in
// JMESPath expression: "Certificate.Status"
Expand All @@ -44,14 +44,14 @@ extension ACMClient {
guard case .success(let output) = result else { return false }
let certificate = output.certificate
let status = certificate?.status
return ClientRuntime.JMESUtils.compare(status, ==, "FAILED")
return SmithyWaitersAPI.JMESUtils.compare(status, ==, "FAILED")
}),
.init(state: .failure, matcher: { (input: DescribeCertificateInput, result: Swift.Result<DescribeCertificateOutput, Swift.Error>) -> Bool in
guard case .failure(let error) = result else { return false }
return (error as? ClientRuntime.ServiceError)?.typeName == "ResourceNotFoundException"
}),
]
return try ClientRuntime.WaiterConfiguration<DescribeCertificateInput, DescribeCertificateOutput>(acceptors: acceptors, minDelay: 60.0, maxDelay: 120.0)
return try SmithyWaitersAPI.WaiterConfiguration<DescribeCertificateInput, DescribeCertificateOutput>(acceptors: acceptors, minDelay: 60.0, maxDelay: 120.0)
}

/// Initiates waiting for the CertificateValidated event on the describeCertificate operation.
Expand All @@ -65,8 +65,8 @@ extension ACMClient {
/// - Throws: `WaiterFailureError` if the waiter fails due to matching an `Acceptor` with state `failure`
/// or there is an error not handled by any `Acceptor.`
/// `WaiterTimeoutError` if the waiter times out.
public func waitUntilCertificateValidated(options: ClientRuntime.WaiterOptions, input: DescribeCertificateInput) async throws -> ClientRuntime.WaiterOutcome<DescribeCertificateOutput> {
let waiter = ClientRuntime.Waiter(config: try Self.certificateValidatedWaiterConfig(), operation: self.describeCertificate(input:))
public func waitUntilCertificateValidated(options: SmithyWaitersAPI.WaiterOptions, input: DescribeCertificateInput) async throws -> SmithyWaitersAPI.WaiterOutcome<DescribeCertificateOutput> {
let waiter = SmithyWaitersAPI.Waiter(config: try Self.certificateValidatedWaiterConfig(), operation: self.describeCertificate(input:))
return try await waiter.waitUntil(options: options, input: input)
}
}
44 changes: 22 additions & 22 deletions Sources/Services/AWSACMPCA/Sources/AWSACMPCA/Waiters.swift
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
// Code generated by smithy-swift-codegen. DO NOT EDIT!

import class ClientRuntime.Waiter
import enum ClientRuntime.JMESUtils
import class SmithyWaitersAPI.Waiter
import enum SmithyWaitersAPI.JMESUtils
import protocol ClientRuntime.ServiceError
import struct ClientRuntime.WaiterConfiguration
import struct ClientRuntime.WaiterOptions
import struct ClientRuntime.WaiterOutcome
import struct SmithyWaitersAPI.WaiterConfiguration
import struct SmithyWaitersAPI.WaiterOptions
import struct SmithyWaitersAPI.WaiterOutcome

extension ACMPCAClient {

static func auditReportCreatedWaiterConfig() throws -> ClientRuntime.WaiterConfiguration<DescribeCertificateAuthorityAuditReportInput, DescribeCertificateAuthorityAuditReportOutput> {
let acceptors: [ClientRuntime.WaiterConfiguration<DescribeCertificateAuthorityAuditReportInput, DescribeCertificateAuthorityAuditReportOutput>.Acceptor] = [
static func auditReportCreatedWaiterConfig() throws -> SmithyWaitersAPI.WaiterConfiguration<DescribeCertificateAuthorityAuditReportInput, DescribeCertificateAuthorityAuditReportOutput> {
let acceptors: [SmithyWaitersAPI.WaiterConfiguration<DescribeCertificateAuthorityAuditReportInput, DescribeCertificateAuthorityAuditReportOutput>.Acceptor] = [
.init(state: .success, matcher: { (input: DescribeCertificateAuthorityAuditReportInput, result: Swift.Result<DescribeCertificateAuthorityAuditReportOutput, Swift.Error>) -> Bool in
// JMESPath expression: "AuditReportStatus"
// JMESPath comparator: "stringEquals"
// JMESPath expected value: "SUCCESS"
guard case .success(let output) = result else { return false }
let auditReportStatus = output.auditReportStatus
return ClientRuntime.JMESUtils.compare(auditReportStatus, ==, "SUCCESS")
return SmithyWaitersAPI.JMESUtils.compare(auditReportStatus, ==, "SUCCESS")
}),
.init(state: .failure, matcher: { (input: DescribeCertificateAuthorityAuditReportInput, result: Swift.Result<DescribeCertificateAuthorityAuditReportOutput, Swift.Error>) -> Bool in
// JMESPath expression: "AuditReportStatus"
// JMESPath comparator: "stringEquals"
// JMESPath expected value: "FAILED"
guard case .success(let output) = result else { return false }
let auditReportStatus = output.auditReportStatus
return ClientRuntime.JMESUtils.compare(auditReportStatus, ==, "FAILED")
return SmithyWaitersAPI.JMESUtils.compare(auditReportStatus, ==, "FAILED")
}),
.init(state: .failure, matcher: { (input: DescribeCertificateAuthorityAuditReportInput, result: Swift.Result<DescribeCertificateAuthorityAuditReportOutput, Swift.Error>) -> Bool in
guard case .failure(let error) = result else { return false }
return (error as? ClientRuntime.ServiceError)?.typeName == "AccessDeniedException"
}),
]
return try ClientRuntime.WaiterConfiguration<DescribeCertificateAuthorityAuditReportInput, DescribeCertificateAuthorityAuditReportOutput>(acceptors: acceptors, minDelay: 3.0, maxDelay: 120.0)
return try SmithyWaitersAPI.WaiterConfiguration<DescribeCertificateAuthorityAuditReportInput, DescribeCertificateAuthorityAuditReportOutput>(acceptors: acceptors, minDelay: 3.0, maxDelay: 120.0)
}

/// Initiates waiting for the AuditReportCreated event on the describeCertificateAuthorityAuditReport operation.
Expand All @@ -46,13 +46,13 @@ extension ACMPCAClient {
/// - Throws: `WaiterFailureError` if the waiter fails due to matching an `Acceptor` with state `failure`
/// or there is an error not handled by any `Acceptor.`
/// `WaiterTimeoutError` if the waiter times out.
public func waitUntilAuditReportCreated(options: ClientRuntime.WaiterOptions, input: DescribeCertificateAuthorityAuditReportInput) async throws -> ClientRuntime.WaiterOutcome<DescribeCertificateAuthorityAuditReportOutput> {
let waiter = ClientRuntime.Waiter(config: try Self.auditReportCreatedWaiterConfig(), operation: self.describeCertificateAuthorityAuditReport(input:))
public func waitUntilAuditReportCreated(options: SmithyWaitersAPI.WaiterOptions, input: DescribeCertificateAuthorityAuditReportInput) async throws -> SmithyWaitersAPI.WaiterOutcome<DescribeCertificateAuthorityAuditReportOutput> {
let waiter = SmithyWaitersAPI.Waiter(config: try Self.auditReportCreatedWaiterConfig(), operation: self.describeCertificateAuthorityAuditReport(input:))
return try await waiter.waitUntil(options: options, input: input)
}

static func certificateIssuedWaiterConfig() throws -> ClientRuntime.WaiterConfiguration<GetCertificateInput, GetCertificateOutput> {
let acceptors: [ClientRuntime.WaiterConfiguration<GetCertificateInput, GetCertificateOutput>.Acceptor] = [
static func certificateIssuedWaiterConfig() throws -> SmithyWaitersAPI.WaiterConfiguration<GetCertificateInput, GetCertificateOutput> {
let acceptors: [SmithyWaitersAPI.WaiterConfiguration<GetCertificateInput, GetCertificateOutput>.Acceptor] = [
.init(state: .success, matcher: { (input: GetCertificateInput, result: Swift.Result<GetCertificateOutput, Swift.Error>) -> Bool in
switch result {
case .success: return true
Expand All @@ -68,7 +68,7 @@ extension ACMPCAClient {
return (error as? ClientRuntime.ServiceError)?.typeName == "AccessDeniedException"
}),
]
return try ClientRuntime.WaiterConfiguration<GetCertificateInput, GetCertificateOutput>(acceptors: acceptors, minDelay: 1.0, maxDelay: 120.0)
return try SmithyWaitersAPI.WaiterConfiguration<GetCertificateInput, GetCertificateOutput>(acceptors: acceptors, minDelay: 1.0, maxDelay: 120.0)
}

/// Initiates waiting for the CertificateIssued event on the getCertificate operation.
Expand All @@ -82,13 +82,13 @@ extension ACMPCAClient {
/// - Throws: `WaiterFailureError` if the waiter fails due to matching an `Acceptor` with state `failure`
/// or there is an error not handled by any `Acceptor.`
/// `WaiterTimeoutError` if the waiter times out.
public func waitUntilCertificateIssued(options: ClientRuntime.WaiterOptions, input: GetCertificateInput) async throws -> ClientRuntime.WaiterOutcome<GetCertificateOutput> {
let waiter = ClientRuntime.Waiter(config: try Self.certificateIssuedWaiterConfig(), operation: self.getCertificate(input:))
public func waitUntilCertificateIssued(options: SmithyWaitersAPI.WaiterOptions, input: GetCertificateInput) async throws -> SmithyWaitersAPI.WaiterOutcome<GetCertificateOutput> {
let waiter = SmithyWaitersAPI.Waiter(config: try Self.certificateIssuedWaiterConfig(), operation: self.getCertificate(input:))
return try await waiter.waitUntil(options: options, input: input)
}

static func certificateAuthorityCSRCreatedWaiterConfig() throws -> ClientRuntime.WaiterConfiguration<GetCertificateAuthorityCsrInput, GetCertificateAuthorityCsrOutput> {
let acceptors: [ClientRuntime.WaiterConfiguration<GetCertificateAuthorityCsrInput, GetCertificateAuthorityCsrOutput>.Acceptor] = [
static func certificateAuthorityCSRCreatedWaiterConfig() throws -> SmithyWaitersAPI.WaiterConfiguration<GetCertificateAuthorityCsrInput, GetCertificateAuthorityCsrOutput> {
let acceptors: [SmithyWaitersAPI.WaiterConfiguration<GetCertificateAuthorityCsrInput, GetCertificateAuthorityCsrOutput>.Acceptor] = [
.init(state: .success, matcher: { (input: GetCertificateAuthorityCsrInput, result: Swift.Result<GetCertificateAuthorityCsrOutput, Swift.Error>) -> Bool in
switch result {
case .success: return true
Expand All @@ -104,7 +104,7 @@ extension ACMPCAClient {
return (error as? ClientRuntime.ServiceError)?.typeName == "AccessDeniedException"
}),
]
return try ClientRuntime.WaiterConfiguration<GetCertificateAuthorityCsrInput, GetCertificateAuthorityCsrOutput>(acceptors: acceptors, minDelay: 3.0, maxDelay: 120.0)
return try SmithyWaitersAPI.WaiterConfiguration<GetCertificateAuthorityCsrInput, GetCertificateAuthorityCsrOutput>(acceptors: acceptors, minDelay: 3.0, maxDelay: 120.0)
}

/// Initiates waiting for the CertificateAuthorityCSRCreated event on the getCertificateAuthorityCsr operation.
Expand All @@ -118,8 +118,8 @@ extension ACMPCAClient {
/// - Throws: `WaiterFailureError` if the waiter fails due to matching an `Acceptor` with state `failure`
/// or there is an error not handled by any `Acceptor.`
/// `WaiterTimeoutError` if the waiter times out.
public func waitUntilCertificateAuthorityCSRCreated(options: ClientRuntime.WaiterOptions, input: GetCertificateAuthorityCsrInput) async throws -> ClientRuntime.WaiterOutcome<GetCertificateAuthorityCsrOutput> {
let waiter = ClientRuntime.Waiter(config: try Self.certificateAuthorityCSRCreatedWaiterConfig(), operation: self.getCertificateAuthorityCsr(input:))
public func waitUntilCertificateAuthorityCSRCreated(options: SmithyWaitersAPI.WaiterOptions, input: GetCertificateAuthorityCsrInput) async throws -> SmithyWaitersAPI.WaiterOutcome<GetCertificateAuthorityCsrOutput> {
let waiter = SmithyWaitersAPI.Waiter(config: try Self.certificateAuthorityCSRCreatedWaiterConfig(), operation: self.getCertificateAuthorityCsr(input:))
return try await waiter.waitUntil(options: options, input: input)
}
}
Loading

0 comments on commit 49c7b5f

Please sign in to comment.