Skip to content

Commit

Permalink
Merge BundleRegionProvider deletion.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sichan Yoo committed Jan 12, 2024
2 parents ee558c8 + f05c7ef commit be8c9bd
Show file tree
Hide file tree
Showing 13 changed files with 40 additions and 107 deletions.
19 changes: 2 additions & 17 deletions .spi.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
version: 1
builder:
configs:
- platform: macosXcodebuild
target: AWSSTS
- platform: ios
target: AWSSTS
- platform: linux
swift_version: '5.7'
image: registry.gitlab.com/finestructure/spi-images:basic-5.7-latest
target: AWSSTS
- platform: linux
swift_version: '5.8'
image: registry.gitlab.com/finestructure/spi-images:basic-5.8-latest
target: AWSSTS
- platform: linux
swift_version: '5.9'
image: registry.gitlab.com/finestructure/spi-images:basic-5.9-latest
target: AWSSTS

- target: AWSSTS
scheme: AWSSTS
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ class AWSMediaConvertTests: XCTestCase {
let input2 = GetJobTemplateInput(name: name)
let output2 = try await client.getJobTemplate(input: input2)

// Verify the name of the retrieved template is the same as the
XCTAssertEqual(output2.jobTemplate?.name, name)
// Verify the name of the created & retrieved templates is the same as the original
XCTAssertEqual(output1.jobTemplate?.name, name)
XCTAssertEqual(output1.jobTemplate?.name, output2.jobTemplate?.name)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import AWSClientRuntime
import AwsCommonRuntimeKit
import ClientRuntime

public class MockHttpClientEngine: HttpClientEngine {
public class MockHttpClientEngine: HTTPClient {

// Public initializer
public init() {}
Expand All @@ -33,7 +33,7 @@ public class MockHttpClientEngine: HttpClientEngine {
)
}

public func execute(request: SdkHttpRequest) async throws -> HttpResponse {
public func send(request: SdkHttpRequest) async throws -> HttpResponse {
return successHttpResponse(request: request)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import XCTest
import AWSS3
import ClientRuntime
@testable import ClientRuntime

final class S3StreamTests: S3XCTestCase {
let objectName = "hello-world"
Expand Down Expand Up @@ -43,7 +43,7 @@ final class S3StreamTests: S3XCTestCase {
func test_putObject_givenStreamBody() async throws {
let audioURL = Bundle.module.url(forResource: objectName, withExtension: nil)!
let fileHandle = FileHandle(forReadingAtPath: audioURL.relativePath)!
let fileByteStream = try ByteStream.data(try fileHandle.readToEnd() ?? Data())
let fileByteStream = ByteStream.stream(FileStream(fileHandle: fileHandle))
let input = PutObjectInput(body: fileByteStream, bucket: bucketName, key: objectName)
let output = try await client.putObject(input: input)
XCTAssertNotNil(output)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,20 @@ import AWSTranscribeStreaming
final class TranscribeStreamingTests: XCTestCase {

func testStartStreamTranscription() async throws {

// The heelo-swift.wav resource is an audio file that contains an automated voice
// saying the words "Hello transcribed streaming from Swift S. D. K.".
// It is 2.976 seconds in duration.
let audioURL = Bundle.module.url(forResource: "hello-swift", withExtension: "wav")!
let audioData = try Data(contentsOf: audioURL)

// A delay will be imposed between chunks to keep the audio streaming to the Teranscribe
// service at approximately real-time.
let duration = 2.976
let chunkSize = 4096
let audioDataSize = audioData.count
let dataRate = Double(audioDataSize) / duration
let delay = Double(chunkSize) / dataRate

let client = try TranscribeStreamingClient(region: "us-west-2")

Expand All @@ -26,6 +35,7 @@ final class TranscribeStreamingTests: XCTestCase {
var currentEnd = min(chunkSize, audioDataSize - currentStart)

while currentStart < audioDataSize {
if currentStart != 0 { try await Task.sleep(nanoseconds: UInt64(delay * 1_000_000_000)) }
let dataChunk = audioData[currentStart ..< currentEnd]

let audioEvent = TranscribeStreamingClientTypes.AudioStream.audioevent(.init(audioChunk: dataChunk))
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ func addResolvedTargets() {
// MARK: - Generated

addDependencies(
clientRuntimeVersion: "0.37.0",
crtVersion: "0.20.0"
clientRuntimeVersion: "0.38.0",
crtVersion: "0.22.0"
)

// Uncomment this line to exclude runtime unit tests
Expand Down
32 changes: 12 additions & 20 deletions Sources/Core/AWSClientRuntime/AWSClientConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ public class AWSClientConfiguration<ServiceSpecificConfiguration: AWSServiceSpec
/// If no decoder is provided, one will be provided by the SDK.
public var decoder: ResponseDecoder?

/// The HTTP client engine to be used for HTTP requests.
/// The HTTP client to be used for SDK HTTP requests.
///
/// If none is provided, AWS provides its own HTTP engine for use.
public var httpClientEngine: HttpClientEngine
/// If none is provided, AWS SDK for Swift selects its own HTTP client for use:
/// - On Mac and Linux, a AWS-provided HTTP client is used for the best stability and performance with heavy AWS workloads.
/// - On iOS, tvOS, watchOS, and visionOS, a `URLSession`-based client is used for maximum compatibility and performance on Apple devices.
public var httpClientEngine: HTTPClient

/// Configuration for the HTTP client.
public var httpClientConfiguration: HttpClientConfiguration
Expand Down Expand Up @@ -102,11 +104,6 @@ public class AWSClientConfiguration<ServiceSpecificConfiguration: AWSServiceSpec
/// This structure is custom code-generated for each AWS service.
public var serviceSpecific: ServiceSpecificConfiguration

/// The timeout for a request in milliseconds
///
/// If none is provided the client will use default values based on the platform.
public var connectTimeoutMs: UInt32?

/// Internal designated init
/// All convenience inits should call this.
private init(
Expand All @@ -121,7 +118,7 @@ public class AWSClientConfiguration<ServiceSpecificConfiguration: AWSServiceSpec
_ retryStrategyOptions: RetryStrategyOptions?,
_ appID: String?,
_ awsRetryMode: AWSRetryMode,
_ connectTimeoutMs: UInt32? = nil
_ httpClientConfiguration: HttpClientConfiguration?
) throws {
typealias RuntimeConfigType =
DefaultSDKRuntimeConfiguration<DefaultRetryStrategy, DefaultRetryErrorInfoProvider>
Expand All @@ -134,13 +131,8 @@ public class AWSClientConfiguration<ServiceSpecificConfiguration: AWSServiceSpec
self.useDualStack = useDualStack
self.useFIPS = useFIPS
self.clientLogMode = RuntimeConfigType.defaultClientLogMode
self.connectTimeoutMs = connectTimeoutMs
self.httpClientConfiguration = RuntimeConfigType.defaultHttpClientConfiguration
if let connectTimeoutMs = self.connectTimeoutMs {
self.httpClientEngine = RuntimeConfigType.httpClientEngineWithTimeout(timeoutMs: connectTimeoutMs)
} else {
self.httpClientEngine = RuntimeConfigType.defaultHttpClientEngine
}
self.httpClientConfiguration = httpClientConfiguration ?? RuntimeConfigType.defaultHttpClientConfiguration
self.httpClientEngine = RuntimeConfigType.makeClient(httpClientConfiguration: self.httpClientConfiguration)
self.idempotencyTokenGenerator = RuntimeConfigType.defaultIdempotencyTokenGenerator
self.logger = RuntimeConfigType.defaultLogger(clientName: self.serviceSpecific.clientName)
self.retryStrategyOptions = retryStrategyOptions ?? RuntimeConfigType.defaultRetryStrategyOptions
Expand Down Expand Up @@ -174,7 +166,7 @@ extension AWSClientConfiguration {
retryMode: AWSRetryMode? = nil,
maxAttempts: Int? = nil,
appID: String? = nil,
connectTimeoutMs: UInt32? = nil
httpClientConfiguration: HttpClientConfiguration? = nil
) async throws {
let fileBasedConfig = try await CRTFileBasedConfiguration.makeAsync()
let resolvedRegionResolver = try regionResolver ?? DefaultRegionResolver { _, _ in fileBasedConfig }
Expand Down Expand Up @@ -213,7 +205,7 @@ extension AWSClientConfiguration {
retryStrategyOptions,
resolvedAppID,
resolvedAWSRetryMode,
connectTimeoutMs
httpClientConfiguration
)
}

Expand All @@ -228,7 +220,7 @@ extension AWSClientConfiguration {
retryMode: AWSRetryMode? = nil,
maxAttempts: Int? = nil,
appID: String? = nil,
connectTimeoutMs: UInt32? = nil
httpClientConfiguration: HttpClientConfiguration? = nil
) throws {
let fileBasedConfig = try CRTFileBasedConfiguration.make()
let resolvedCredentialsProvider: CredentialsProviding
Expand Down Expand Up @@ -260,7 +252,7 @@ extension AWSClientConfiguration {
retryStrategyOptions,
resolvedAppID,
resolvedAWSRetryMode,
connectTimeoutMs
httpClientConfiguration
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public struct Sha256TreeHashMiddleware<OperationStackOutput>: Middleware {
return try await next.handle(context: context, input: input)
}
if !request.headers.exists(name: X_AMZ_CONTENT_SHA256_HEADER_NAME) {
let sha256 = try data.sha256().encodeToHexString()
let sha256 = try data.computeSHA256().encodeToHexString()
input.withHeader(name: X_AMZ_CONTENT_SHA256_HEADER_NAME, value: sha256)
}
case .stream(let stream):
Expand Down Expand Up @@ -66,8 +66,8 @@ public struct Sha256TreeHashMiddleware<OperationStackOutput>: Middleware {
/// See http://docs.aws.amazon.com/amazonglacier/latest/dev/checksum-calculations.html for more information.
private func computeHashes(data: Data) throws -> (String?, String?) {
let ONE_MB = 1024 * 1024
let hashes: [[UInt8]] = try data.chunked(size: ONE_MB).map { try $0.sha256().bytes() }
return try (data.sha256().encodeToHexString(), computeTreeHash(hashes: hashes))
let hashes: [[UInt8]] = try data.chunked(size: ONE_MB).map { try $0.computeSHA256().bytes() }
return try (data.computeSHA256().encodeToHexString(), computeTreeHash(hashes: hashes))
}

/// Builds a tree hash root node given a slice of hashes. Glacier tree hash to be derived from SHA256 hashes
Expand All @@ -87,7 +87,7 @@ public struct Sha256TreeHashMiddleware<OperationStackOutput>: Middleware {
concatenatedLevelHash.append(contentsOf: previousLevelHashes[index])
concatenatedLevelHash.append(contentsOf: previousLevelHashes[index + 1])
let data = Data(concatenatedLevelHash)
currentLevelHashes.append(try data.sha256().bytes())
currentLevelHashes.append(try data.computeSHA256().bytes())

} else {
currentLevelHashes.append(previousLevelHashes[index])
Expand Down
46 changes: 0 additions & 46 deletions Sources/Core/AWSClientRuntime/Regions/BundleRegionProvider.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public struct DefaultRegionResolver: RegionResolver {

public init(fileBasedConfigurationProvider: @escaping FileBasedConfigurationProviding) throws {
self.providers = [
BundleRegionProvider(),
EnvironmentRegionProvider(),
ProfileRegionProvider(fileBasedConfigurationProvider: fileBasedConfigurationProvider),
try IMDSRegionProvider()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,6 @@ class AWSClientConfigurationTests: XCTestCase {
let subject = try await Subject(region: region, appID: appID)
XCTAssertEqual(subject.appID, appID)
}

// MARK: - Timeout

func test_sync_configureTimeoutOptionsFromParams() throws {
let customTimeout: UInt32 = 10_000
let subject = try Subject(region: region, connectTimeoutMs: customTimeout)
XCTAssertEqual(subject.connectTimeoutMs, customTimeout)
}
}

struct TestAWSServiceSpecificConfiguration: AWSServiceSpecificConfiguration {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Sigv4SigningTests: XCTestCase {

let signingConfig = try! await context.makeEventStreamSigningConfig(date: epoch.withoutFractionalSeconds())

let prevSignature = try! "last message sts".data(using: .utf8)!.sha256().encodeToHexString()
let prevSignature = try! "last message sts".data(using: .utf8)!.computeSHA256().encodeToHexString()

let messagePayload = try! encoder.encode(message: message)

Expand Down
4 changes: 2 additions & 2 deletions packageDependencies.plist
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
<key>awsCRTSwiftBranch</key>
<string>main</string>
<key>awsCRTSwiftVersion</key>
<string>0.20.0</string>
<string>0.22.0</string>
<key>clientRuntimeBranch</key>
<string>main</string>
<key>clientRuntimeVersion</key>
<string>0.37.0</string>
<string>0.38.0</string>
</dict>
</plist>

0 comments on commit be8c9bd

Please sign in to comment.