From a73e420a184974045e0235e976029a832b2495c0 Mon Sep 17 00:00:00 2001 From: Konstantin Novichikhin Date: Thu, 25 Jan 2024 14:34:02 -0500 Subject: [PATCH] Update CloudWatch client to send payload in POST body instead of URL (#146) --- .../CloudWatchClient/AWSCloudWatchClient.swift | 6 +++--- .../AWSCloudWatchClientGenerator.swift | 4 ++-- .../CloudWatchModel/CloudWatchModelErrors.swift | 15 +++++++++++++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Sources/CloudWatchClient/AWSCloudWatchClient.swift b/Sources/CloudWatchClient/AWSCloudWatchClient.swift index 1a31f9b..49db90b 100644 --- a/Sources/CloudWatchClient/AWSCloudWatchClient.swift +++ b/Sources/CloudWatchClient/AWSCloudWatchClient.swift @@ -43,7 +43,7 @@ public enum CloudWatchClientError: Swift.Error { public func isRetriable() -> Bool? { switch self { - case .limitExceededException, .limitExceededFault: + case .limitExceededException, .limitExceededFault, .throttling: return true default: return nil @@ -86,7 +86,7 @@ public struct AWSCloudWatchClient = SmokeAWSClientReportingConfiguration() ) { let useTLS = requiresTLS ?? AWSHTTPClientDelegate.requiresTLS(forEndpointPort: endpointPort) - let clientDelegate = XMLAWSHttpClientDelegate(requiresTLS: useTLS, + let clientDelegate = FormEncodedXMLAWSHttpClientDelegate(requiresTLS: useTLS, outputListDecodingStrategy: .collapseListUsingItemTag("member"), inputQueryListEncodingStrategy: .expandListWithIndexAndItemTag(itemTag: "member")) diff --git a/Sources/CloudWatchClient/AWSCloudWatchClientGenerator.swift b/Sources/CloudWatchClient/AWSCloudWatchClientGenerator.swift index 09f1c32..b90783a 100644 --- a/Sources/CloudWatchClient/AWSCloudWatchClientGenerator.swift +++ b/Sources/CloudWatchClient/AWSCloudWatchClientGenerator.swift @@ -60,7 +60,7 @@ public struct AWSCloudWatchClientGenerator { endpointPort: Int = 443, requiresTLS: Bool? = nil, service: String = "monitoring", - contentType: String = "application/octet-stream", + contentType: String = "application/x-www-form-urlencoded; charset=utf-8", apiVersion: String = "2010-08-01", connectionTimeoutSeconds: Int64 = 10, retryConfiguration: HTTPClientRetryConfiguration = .default, @@ -69,7 +69,7 @@ public struct AWSCloudWatchClientGenerator { reportingConfiguration: SmokeAWSClientReportingConfiguration = SmokeAWSClientReportingConfiguration() ) { let useTLS = requiresTLS ?? AWSHTTPClientDelegate.requiresTLS(forEndpointPort: endpointPort) - let clientDelegate = XMLAWSHttpClientDelegate(requiresTLS: useTLS, + let clientDelegate = FormEncodedXMLAWSHttpClientDelegate(requiresTLS: useTLS, outputListDecodingStrategy: .collapseListUsingItemTag("member"), inputQueryListEncodingStrategy: .expandListWithIndexAndItemTag(itemTag: "member")) diff --git a/Sources/CloudWatchModel/CloudWatchModelErrors.swift b/Sources/CloudWatchModel/CloudWatchModelErrors.swift index f14daf4..7ff1ec6 100644 --- a/Sources/CloudWatchModel/CloudWatchModelErrors.swift +++ b/Sources/CloudWatchModel/CloudWatchModelErrors.swift @@ -46,8 +46,19 @@ private let limitExceededFaultIdentity = "LimitExceeded" private let missingRequiredParameterIdentity = "MissingParameter" private let resourceNotFoundIdentity = "ResourceNotFound" private let resourceNotFoundExceptionIdentity = "ResourceNotFoundException" +private let throttlingIdentity = "ThrottlingException" private let __accessDeniedIdentity = "AccessDenied" +public struct CloudWatchErrorPayload: Codable { + public let type: String + public let message: String + + enum CodingKeys: String, CodingKey { + case type = "Code" + case message = "Message" + } +} + public enum CloudWatchError: Swift.Error, Decodable { case concurrentModification(ConcurrentModificationException) case dashboardInvalidInput(DashboardInvalidInputError) @@ -62,6 +73,7 @@ public enum CloudWatchError: Swift.Error, Decodable { case missingRequiredParameter(MissingRequiredParameterException) case resourceNotFound(ResourceNotFound) case resourceNotFoundException(ResourceNotFoundException) + case throttling(CloudWatchErrorPayload) case accessDenied(message: String?) case validationError(reason: String) case unrecognizedError(String, String?) @@ -120,6 +132,9 @@ public enum CloudWatchError: Swift.Error, Decodable { case resourceNotFoundExceptionIdentity: let errorPayload = try ResourceNotFoundException(from: decoder) self = CloudWatchError.resourceNotFoundException(errorPayload) + case throttlingIdentity: + let errorPayload = try CloudWatchErrorPayload(from: decoder) + self = CloudWatchError.throttling(errorPayload) case __accessDeniedIdentity: self = .accessDenied(message: errorMessage) default: