Skip to content

Commit

Permalink
Merge branch 'main' into jbe/delete_release_workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
jbelkins authored Aug 10, 2023
2 parents 11357da + 2f1f59a commit e7cdebf
Show file tree
Hide file tree
Showing 343 changed files with 133,244 additions and 43,323 deletions.
5 changes: 4 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func addProtocolTests() {
// MARK: - Generated

addDependencies(
clientRuntimeVersion: "0.24.0",
clientRuntimeVersion: "0.26.0",
crtVersion: "0.12.0"
)

Expand Down Expand Up @@ -295,6 +295,7 @@ let serviceTargets: [String] = [
"AWSElasticLoadBalancingv2",
"AWSElasticTranscoder",
"AWSElasticsearchService",
"AWSEntityResolution",
"AWSEventBridge",
"AWSEvidently",
"AWSFMS",
Expand Down Expand Up @@ -380,6 +381,7 @@ let serviceTargets: [String] = [
"AWSMacie",
"AWSMacie2",
"AWSManagedBlockchain",
"AWSManagedBlockchainQuery",
"AWSMarketplaceCatalog",
"AWSMarketplaceCommerceAnalytics",
"AWSMarketplaceEntitlementService",
Expand All @@ -393,6 +395,7 @@ let serviceTargets: [String] = [
"AWSMediaStore",
"AWSMediaStoreData",
"AWSMediaTailor",
"AWSMedicalImaging",
"AWSMemoryDB",
"AWSMgn",
"AWSMigrationHub",
Expand Down
2 changes: 1 addition & 1 deletion Package.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.20.0
0.22.0
48 changes: 44 additions & 4 deletions Sources/Core/AWSClientRuntime/AWSClientConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public class AWSClientConfiguration<ServiceSpecificConfiguration: AWSServiceSpec

/// Internal designated init
/// All convenience inits should call this.
init(
private init(
// these params have no labels to distinguish this init from the similar convenience inits below
_ credentialsProvider: AWSClientRuntime.CredentialsProviding,
_ endpoint: Swift.String?,
Expand Down Expand Up @@ -147,7 +147,8 @@ extension AWSClientConfiguration {
signingRegion: Swift.String? = nil,
useDualStack: Swift.Bool? = nil,
useFIPS: Swift.Bool? = nil,
retryStrategyOptions: RetryStrategyOptions? = nil
retryMode: AWSRetryMode? = nil,
maxAttempts: Int? = nil
) async throws {
let fileBasedConfig = try await CRTFileBasedConfiguration.makeAsync()
let resolvedRegionResolver = try regionResolver ?? DefaultRegionResolver { _, _ in fileBasedConfig }
Expand All @@ -163,6 +164,12 @@ extension AWSClientConfiguration {
} else {
resolvedCredentialsProvider = try DefaultChainCredentialsProvider(fileBasedConfig: fileBasedConfig)
}
let retryStrategyOptions = Self.retryStrategyOptions(
retryMode: retryMode,
maxAttempts: maxAttempts,
profileName: nil,
fileBasedConfig: fileBasedConfig
)
try self.init(
resolvedCredentialsProvider,
endpoint,
Expand All @@ -185,15 +192,22 @@ extension AWSClientConfiguration {
signingRegion: Swift.String? = nil,
useDualStack: Swift.Bool? = nil,
useFIPS: Swift.Bool? = nil,
retryStrategyOptions: RetryStrategyOptions? = nil
retryMode: AWSRetryMode? = nil,
maxAttempts: Int? = nil
) throws {
let fileBasedConfig = try CRTFileBasedConfiguration.make()
let resolvedCredentialsProvider: CredentialsProviding
if let credentialsProvider = credentialsProvider {
resolvedCredentialsProvider = credentialsProvider
} else {
let fileBasedConfig = try CRTFileBasedConfiguration.make()
resolvedCredentialsProvider = try DefaultChainCredentialsProvider(fileBasedConfig: fileBasedConfig)
}
let retryStrategyOptions = Self.retryStrategyOptions(
retryMode: retryMode,
maxAttempts: maxAttempts,
profileName: nil,
fileBasedConfig: fileBasedConfig
)
try self.init(
resolvedCredentialsProvider,
endpoint,
Expand All @@ -210,4 +224,30 @@ extension AWSClientConfiguration {
public var partitionID: String? {
return "\(serviceSpecific.clientName) - \(region ?? "")"
}

private static func retryStrategyOptions(
retryMode: AWSRetryMode?,
maxAttempts: Int?,
profileName: String?,
fileBasedConfig: FileBasedConfiguration
) -> RetryStrategyOptions {
let resolvedRetryMode = AWSRetryConfig.retryMode(
configValue: retryMode,
profileName: profileName,
fileBasedConfig: fileBasedConfig
)
let resolvedMaxAttempts = AWSRetryConfig.maxAttempts(
configValue: maxAttempts,
profileName: profileName,
fileBasedConfig: fileBasedConfig
)
let resolvedRateLimitingMode: RetryStrategyOptions.RateLimitingMode
switch resolvedRetryMode {
case .legacy, .standard:
resolvedRateLimitingMode = .standard
case .adaptive:
resolvedRateLimitingMode = .adaptive
}
return RetryStrategyOptions(maxRetriesBase: resolvedMaxAttempts - 1, rateLimitingMode: resolvedRateLimitingMode)
}
}
59 changes: 59 additions & 0 deletions Sources/Core/AWSClientRuntime/Config/FieldResolver.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

import class Foundation.ProcessInfo

/// Resolves a configuration field for an AWS SDK feature.
struct FieldResolver<T> {
let configValue: T?
let envVarName: String?
let configFieldName: String?
let fileBasedConfig: FileBasedConfiguration
let profileName: String?
let converter: (String) -> T?

init(configValue: T?,
envVarName: String?,
configFieldName: String?,
fileBasedConfig: FileBasedConfiguration,
profileName: String?,
converter: @escaping (String) -> T?
) {
self.configValue = configValue
self.envVarName = envVarName
self.configFieldName = configFieldName
self.fileBasedConfig = fileBasedConfig
self.profileName = profileName
self.converter = converter
}

/// Resolves a configuration field for an AWS SDK feature.
///
/// Resolves the field in the following order:
/// - If `configValue` is provided, it is used.
/// - If an environment var named `envVarName` is set, its value is used to create a value.
/// - If a config field is set in the config file for the current profile, its value is used to create a value.
/// - Finally, if none of the above yield a value, `nil` is returned.
var value: T? {
let env = ProcessInfo.processInfo.environment
if let value = configValue {
return value
}
if let envVarName = envVarName, let envValue = env[envVarName], let value = converter(envValue) {
return value
}
if let configFieldName = configFieldName {
let key = FileBasedConfigurationKey(rawValue: configFieldName)
let envProfileName = env["AWS_PROFILE"]
let sectionName = profileName ?? envProfileName ?? "default"
if let configValue = fileBasedConfig.section(for: sectionName)?.string(for: key) {
return converter(configValue)
}
}
return nil
}
}
55 changes: 55 additions & 0 deletions Sources/Core/AWSClientRuntime/Retry/AWSRetryConfig.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

import struct ClientRuntime.RetryStrategyOptions

enum AWSRetryConfig {

/// Determines the retry mode to be used from the given config. If none can be determined, `legacy` will be used as a default.
/// - Parameters:
/// - configValue: The retry mode passed at client construction, or `nil` if none was passed.
/// - profileName: The profile name passed at client construction. If `nil` is passed, the SDK will resolve the profile to be used.
/// - fileBasedConfig: The file-based config from which to load configuration, if needed.
/// - Returns: The retry mode that was resolved.
static func retryMode(
configValue: AWSRetryMode?,
profileName: String?,
fileBasedConfig: FileBasedConfiguration
) -> AWSRetryMode {
return FieldResolver(
configValue: configValue,
envVarName: "AWS_RETRY_MODE",
configFieldName: "retry_mode",
fileBasedConfig: fileBasedConfig,
profileName: profileName,
converter: { AWSRetryMode(rawValue: $0) }
).value ?? .legacy
}

/// Determines the max attempts (for retry purposes) to be used from the given config. If none can be determined, `3` will be used as a default.
///
/// Max attempts must be a positive, nonzero integer.
/// - Parameters:
/// - configValue: The max attempts passed at client construction, or `nil` if none was passed.
/// - profileName: The profile name passed at client construction. If `nil` is passed, the SDK will resolve the profile to be used.
/// - fileBasedConfig: The file-based config from which to load configuration, if needed.
/// - Returns: The max attempts that was resolved.
static func maxAttempts(
configValue: Int?,
profileName: String?,
fileBasedConfig: FileBasedConfiguration
) -> Int {
return FieldResolver(
configValue: configValue,
envVarName: "AWS_MAX_ATTEMPTS",
configFieldName: "max_attempts",
fileBasedConfig: fileBasedConfig,
profileName: profileName,
converter: { Int($0) }
).value ?? 3
}
}
28 changes: 28 additions & 0 deletions Sources/Core/AWSClientRuntime/Retry/AWSRetryMode.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

import Foundation

/// The mode of operation for the SDK's retry mechanism.
///
/// This may be specified using the `AWS_RETRY_MODE` environment var, or the `retry_mode` field of the AWS config file.
public enum AWSRetryMode: String {

/// Use the retry behavior that this SDK implemented before the "Retry Behavior 2.0" spec.
/// For the Swift SDK, this is the same behavior as standard.
case legacy

/// Use "Standard" retry behavior. Initial requests are always made immediately, but retries
/// are delayed using exponential backoff. Retries are performed up to the specified maximum
/// number, but may be further limited by a token system.
case standard

/// Use "Adaptive" retry behavior. Like "Standard" but requests may be additionally delayed
/// according to a rate limiting scheme that is designed to reduce congestion when throttling
/// is taking place.
case adaptive
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ extension AmplifyUIBuilderClient: AmplifyUIBuilderClientProtocol {
return result
}

/// Creates a new form for an Amplify.
/// Creates a new form for an Amplify app.
public func createForm(input: CreateFormInput) async throws -> CreateFormOutputResponse
{
let context = ClientRuntime.HttpContextBuilder()
Expand Down Expand Up @@ -812,7 +812,7 @@ extension AmplifyUIBuilderClient: AmplifyUIBuilderClientProtocol {
return result
}

/// Starts a code generation job for for a specified Amplify app and backend environment.
/// Starts a code generation job for a specified Amplify app and backend environment.
public func startCodegenJob(input: StartCodegenJobInput) async throws -> StartCodegenJobOutputResponse
{
let context = ClientRuntime.HttpContextBuilder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ClientRuntime
public protocol AmplifyUIBuilderClientProtocol {
/// Creates a new component for an Amplify app.
func createComponent(input: CreateComponentInput) async throws -> CreateComponentOutputResponse
/// Creates a new form for an Amplify.
/// Creates a new form for an Amplify app.
func createForm(input: CreateFormInput) async throws -> CreateFormOutputResponse
/// Creates a theme to apply to the components in an Amplify app.
func createTheme(input: CreateThemeInput) async throws -> CreateThemeOutputResponse
Expand Down Expand Up @@ -46,7 +46,7 @@ public protocol AmplifyUIBuilderClientProtocol {
func putMetadataFlag(input: PutMetadataFlagInput) async throws -> PutMetadataFlagOutputResponse
/// Refreshes a previously issued access token that might have expired.
func refreshToken(input: RefreshTokenInput) async throws -> RefreshTokenOutputResponse
/// Starts a code generation job for for a specified Amplify app and backend environment.
/// Starts a code generation job for a specified Amplify app and backend environment.
func startCodegenJob(input: StartCodegenJobInput) async throws -> StartCodegenJobOutputResponse
/// Updates an existing component.
func updateComponent(input: UpdateComponentInput) async throws -> UpdateComponentOutputResponse
Expand Down
Loading

0 comments on commit e7cdebf

Please sign in to comment.