Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Modularize event streams & event streams auth #741

Merged
merged 30 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f3a5979
Split event streams-related modules out from ClientRuntime
jbelkins May 24, 2024
43724ef
Merge remote-tracking branch 'origin/main' into jbe/modularize_event_…
jbelkins May 24, 2024
e802518
Move AWSSigningAlgorithm out of smithy-swift
jbelkins May 24, 2024
1ceb2af
ClientRuntime builds & tests pass
jbelkins May 25, 2024
1d76efb
All Swift tests pass except WeatherSDK
jbelkins May 27, 2024
2186d53
Clean up SdkHttpRequestBuilder access
jbelkins May 27, 2024
c28efb4
WeatherSDK regenerated, builds, tests pass
jbelkins May 27, 2024
faa8961
Protocol tests pass
jbelkins May 28, 2024
35772ab
Fix lint
jbelkins May 28, 2024
5ab04b4
SDK builds
jbelkins May 29, 2024
79c4d37
Fix ktlint
jbelkins May 29, 2024
f0a8aa3
Fix smithy-swift codegen tests
jbelkins May 29, 2024
2a9dc54
Regenerate WeatherSDK
jbelkins May 29, 2024
6ac0242
Fix types in initial event generator
jbelkins May 29, 2024
623e2a3
Fix protocol tests
jbelkins May 29, 2024
3f74ad2
Fix event streams tests
jbelkins May 29, 2024
e15f2b8
Add signingalgorithm extensions to Context
jbelkins May 29, 2024
4fbb5fa
Fix integration tests; code cleanup
jbelkins May 29, 2024
6088055
Fix SmithyEventStreamsTests
jbelkins May 29, 2024
d54e356
Code cleanup
jbelkins May 29, 2024
7c9e8d6
Merge branch 'main' into jbe/modularize_event_streams
jbelkins May 29, 2024
a4ac939
Change scheme name for CI
jbelkins May 29, 2024
e0a5dc3
Remove signing region accessor from SmithyHTTPAPI
jbelkins May 30, 2024
039fb4b
Merge branch 'main' into jbe/modularize_event_streams
jbelkins May 30, 2024
bb2e6cb
Merge remote-tracking branch 'origin/main' into jbe/modularize_event_…
jbelkins May 31, 2024
75d973b
Incorporate requests/responses, fix tests & lint
jbelkins May 31, 2024
c3d4eba
Adapt symbols to new declaration format
jbelkins May 31, 2024
c86e96a
Convert SigningAlgorithm back to a custom type
jbelkins May 31, 2024
cd615c3
Fix SPI imports
jbelkins May 31, 2024
6e347fe
Fix ktlint
jbelkins May 31, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ jobs:
cd ../aws-sdk-swift
set -o pipefail && \
NSUnbufferedIO=YES xcodebuild \
-scheme aws-sdk-swift \
-scheme aws-sdk-swift-Package \
-destination '${{ matrix.destination }}' \
test 2>&1 \
| xcbeautify
Expand Down
64 changes: 60 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,51 @@ let package = Package(
.watchOS(.v6)
],
products: [
.library(name: "Smithy", targets: ["Smithy"]),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: It might be better to name this something like SmithyCommon

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not currently sure about this module's name and exact scope... this is intended to be things that Smithy uses across all modules.

I might break it down further though to have such modules for clients and for models, since it seems some smithy-swift customers use them separately.

I'd like to leave it for now, and we can revisit it later in modularization.

.library(name: "ClientRuntime", targets: ["ClientRuntime"]),
.library(name: "SmithyRetriesAPI", targets: ["SmithyRetriesAPI"]),
.library(name: "SmithyRetries", targets: ["SmithyRetries"]),
.library(name: "SmithyReadWrite", targets: ["SmithyReadWrite"]),
.library(name: "SmithyXML", targets: ["SmithyXML"]),
.library(name: "SmithyJSON", targets: ["SmithyJSON"]),
.library(name: "SmithyFormURL", targets: ["SmithyFormURL"]),
.library(name: "SmithyIdentityAPI", targets: ["SmithyIdentityAPI"]),
.library(name: "SmithyHTTPAPI", targets: ["SmithyHTTPAPI"]),
.library(name: "SmithyHTTPAuthAPI", targets: ["SmithyHTTPAuthAPI"]),
.library(name: "SmithyEventStreamsAPI", targets: ["SmithyEventStreamsAPI"]),
.library(name: "SmithyEventStreamsAuthAPI", targets: ["SmithyEventStreamsAuthAPI"]),
.library(name: "SmithyEventStreams", targets: ["SmithyEventStreams"]),
.library(name: "SmithyChecksumsAPI", targets: ["SmithyChecksumsAPI"]),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Several new modules added for Smithy modularization.

.library(name: "SmithyTestUtil", targets: ["SmithyTestUtil"]),
],
dependencies: [
.package(url: "https://github.com/awslabs/aws-crt-swift.git", exact: "0.30.0"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"),
],
targets: [
.target(
name: "Smithy",
dependencies: [
.product(name: "Logging", package: "swift-log"),
]
),
.target(
name: "ClientRuntime",
dependencies: [
"Smithy",
"SmithyRetriesAPI",
"SmithyRetries",
"SmithyXML",
"SmithyJSON",
"SmithyFormURL",
"SmithyIdentityAPI",
"SmithyHTTPAPI",
"SmithyHTTPAuthAPI",
"SmithyEventStreamsAPI",
"SmithyEventStreams",
"SmithyEventStreamsAuthAPI",
"SmithyChecksumsAPI",
.product(name: "AwsCommonRuntimeKit", package: "aws-crt-swift"),
.product(name: "Logging", package: "swift-log"),
],
resources: [
.copy("PrivacyInfo.xcprivacy")
Expand All @@ -72,9 +93,7 @@ let package = Package(
),
.target(
name: "SmithyReadWrite",
dependencies: [
"SmithyTimestamps"
]
dependencies: ["SmithyTimestamps"]
),
.target(
name: "SmithyXML",
Expand Down Expand Up @@ -106,6 +125,39 @@ let package = Package(
name: "SmithyTestUtil",
dependencies: ["ClientRuntime"]
),
.target(
name: "SmithyIdentityAPI",
dependencies: ["Smithy"]
),
.target(
name: "SmithyHTTPAPI",
dependencies: ["Smithy"]
),
.target(
name: "SmithyHTTPAuthAPI",
dependencies: ["Smithy", "SmithyHTTPAPI"]
),
.target(
name: "SmithyEventStreamsAPI",
dependencies: ["Smithy"]
),
.target(
name: "SmithyEventStreamsAuthAPI",
dependencies: ["Smithy", "SmithyEventStreamsAPI"]
),
.target(
name: "SmithyEventStreams",
dependencies: [
"Smithy",
"SmithyEventStreamsAPI",
"SmithyEventStreamsAuthAPI",
.product(name: "AwsCommonRuntimeKit", package: "aws-crt-swift")
]
),
.target(
name: "SmithyChecksumsAPI",
dependencies: ["Smithy"]
),
.testTarget(
name: "ClientRuntimeTests",
dependencies: ["ClientRuntime", "SmithyTestUtil"],
Expand All @@ -131,6 +183,10 @@ let package = Package(
name: "SmithyTestUtilTests",
dependencies: ["SmithyTestUtil"]
),
.testTarget(
name: "SmithyEventStreamsTests",
dependencies: ["SmithyEventStreams"]
),
].compactMap { $0 }
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,19 @@
// SPDX-License-Identifier: Apache-2.0
//

import struct Smithy.Attributes
import struct Smithy.AttributeKey
import protocol SmithyIdentityAPI.IdentityResolver
import protocol SmithyIdentityAPI.IdentityResolverConfiguration

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many files contain superficial changes like this, that are related to modularizing the project:

  • moved or renamed file
  • changed or added imports
  • changed namespaces on types
  • changed visibility of methods or types (i.e. marking them "public")

I won't comment on these types of changes, since they happen frequently in this PR.

public struct DefaultIdentityResolverConfiguration: IdentityResolverConfiguration {
let identityResolvers: Attributes

public init(configuredIdResolvers: Attributes) {
self.identityResolvers = configuredIdResolvers
}

func getIdentityResolver(schemeID: String) throws -> (any IdentityResolver)? {
public func getIdentityResolver(schemeID: String) throws -> (any IdentityResolver)? {
return self.identityResolvers.get(key: AttributeKey<any IdentityResolver>(name: schemeID))
}
}
30 changes: 0 additions & 30 deletions Sources/ClientRuntime/Auth/HTTPAuthAPI/Signer.swift

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
// SPDX-License-Identifier: Apache-2.0
//

import protocol SmithyHTTPAPI.HTTPClient
import protocol SmithyHTTPAuthAPI.AuthScheme
import protocol SmithyHTTPAuthAPI.AuthSchemeResolver

public protocol DefaultHttpClientConfiguration: ClientConfiguration {

/// The HTTP client to be used for the target platform, configured with the supplied configuration.
Expand All @@ -19,10 +23,10 @@ public protocol DefaultHttpClientConfiguration: ClientConfiguration {
/// List of auth schemes to use for client calls.
///
/// Defaults to auth schemes defined on the Smithy service model.
var authSchemes: [ClientRuntime.AuthScheme]? { get set }
var authSchemes: [AuthScheme]? { get set }

/// The auth scheme resolver to use for resolving auth scheme.
///
/// Defaults to a auth scheme resolver generated based on Smithy service model.
var authSchemeResolver: ClientRuntime.AuthSchemeResolver { get set }
var authSchemeResolver: AuthSchemeResolver { get set }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
// SPDX-License-Identifier: Apache-2.0
//

import class Smithy.Context
import protocol SmithyHTTPAPI.HTTPClient
import enum Smithy.ClientError
import struct SmithyHTTPAuthAPI.AuthOption
import protocol SmithyHTTPAuthAPI.AuthSchemeResolver
import protocol SmithyHTTPAuthAPI.AuthSchemeResolverParameters
import protocol SmithyRetriesAPI.RetryStrategy
import protocol SmithyRetriesAPI.RetryErrorInfoProvider
import struct SmithyRetriesAPI.RetryStrategyOptions
Expand Down Expand Up @@ -86,7 +92,7 @@
static func makeClient(
httpClientConfiguration: HttpClientConfiguration = defaultHttpClientConfiguration
) -> HTTPClient {
#if os(iOS) || os(tvOS) || os(watchOS) || os(visionOS) || os(macOS)

Check warning on line 95 in Sources/ClientRuntime/Config/DefaultSDKRuntimeConfiguration.swift

View workflow job for this annotation

GitHub Actions / downstream (macos-13-xlarge, Xcode_14.1, platform=OS X)

unknown operating system for build configuration 'os'

Check warning on line 95 in Sources/ClientRuntime/Config/DefaultSDKRuntimeConfiguration.swift

View workflow job for this annotation

GitHub Actions / downstream (macos-13-xlarge, Xcode_14.1, platform=OS X)

unknown operating system for build configuration 'os'

Check warning on line 95 in Sources/ClientRuntime/Config/DefaultSDKRuntimeConfiguration.swift

View workflow job for this annotation

GitHub Actions / downstream (macos-13-xlarge, Xcode_14.1, platform=iOS Simulator,OS=16.1,name=iPhone 14)

unknown operating system for build configuration 'os'

Check warning on line 95 in Sources/ClientRuntime/Config/DefaultSDKRuntimeConfiguration.swift

View workflow job for this annotation

GitHub Actions / downstream (macos-13-xlarge, Xcode_14.1, platform=iOS Simulator,OS=16.1,name=iPhone 14)

unknown operating system for build configuration 'os'

Check warning on line 95 in Sources/ClientRuntime/Config/DefaultSDKRuntimeConfiguration.swift

View workflow job for this annotation

GitHub Actions / downstream (macos-13-xlarge, Xcode_14.1, platform=tvOS Simulator,OS=16.1,name=Apple TV 4K (3rd ge...

unknown operating system for build configuration 'os'

Check warning on line 95 in Sources/ClientRuntime/Config/DefaultSDKRuntimeConfiguration.swift

View workflow job for this annotation

GitHub Actions / downstream (macos-13-xlarge, Xcode_14.1, platform=tvOS Simulator,OS=16.1,name=Apple TV 4K (3rd ge...

unknown operating system for build configuration 'os'
return URLSessionHTTPClient(httpClientConfiguration: httpClientConfiguration)
#else
let connectTimeoutMs = httpClientConfiguration.connectTimeout.map { UInt32($0 * 1000) }
Expand Down Expand Up @@ -137,7 +143,7 @@
return []
}

public func constructParameters(context: HttpContext) throws -> AuthSchemeResolverParameters {
public func constructParameters(context: Context) throws -> AuthSchemeResolverParameters {
guard let opName = context.getOperation() else {
throw ClientError.dataNotFound(
"Operation name not configured in middleware context for auth scheme resolver params construction.")
Expand Down
3 changes: 3 additions & 0 deletions Sources/ClientRuntime/Endpoints/ServiceEndpointMetadata.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
// SPDX-License-Identifier: Apache-2.0
//

import enum SmithyHTTPAPI.ProtocolType
import struct SmithyHTTPAPI.Endpoint

public struct ServiceEndpointMetadata {
public let defaultProtocol = ProtocolType.https.rawValue
public let defaultSigner = "v4"
Expand Down
2 changes: 2 additions & 0 deletions Sources/ClientRuntime/Endpoints/SmithyEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// SPDX-License-Identifier: Apache-2.0
//

import struct SmithyHTTPAPI.Endpoint

/**
A structure used by the service client to determine the endpoint.
The SDK will automatically resolve endpoints per API client using an internal resolver.
Expand Down
10 changes: 0 additions & 10 deletions Sources/ClientRuntime/EventStream/MessageEncoderStream.swift

This file was deleted.

28 changes: 28 additions & 0 deletions Sources/ClientRuntime/Idempotency/Context+Idempotency.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 struct Smithy.AttributeKey
import class Smithy.Context
import class Smithy.ContextBuilder
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idempotency-related accessors that were broken out from the old HttpContext


extension Context {

public func getIdempotencyTokenGenerator() -> IdempotencyTokenGenerator {
return attributes.get(key: idempotencyTokenGeneratorKey)!
}
}

extension ContextBuilder {

@discardableResult
public func withIdempotencyTokenGenerator(value: IdempotencyTokenGenerator) -> Self {
self.attributes.set(key: idempotencyTokenGeneratorKey, value: value)
return self
}
}

private let idempotencyTokenGeneratorKey = AttributeKey<IdempotencyTokenGenerator>(name: "IdempotencyTokenGeneratorKey")
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,26 @@
// SPDX-License-Identifier: Apache-2.0
//

public struct IdempotencyTokenMiddleware<OperationStackInput, OperationStackOutput>: ClientRuntime.Middleware {
import protocol Smithy.HasAttributes
import class Smithy.Context

public struct IdempotencyTokenMiddleware<OperationStackInput, OperationStackOutput>: Middleware {
public let id: Swift.String = "IdempotencyTokenMiddleware"
private let keyPath: WritableKeyPath<OperationStackInput, String?>

public init(keyPath: WritableKeyPath<OperationStackInput, String?>) {
self.keyPath = keyPath
}

public func handle<H>(context: Context,
public func handle<H>(context: Smithy.Context,
input: MInput,
next: H) async throws -> MOutput
where H: Handler, Self.MInput == H.Input, Self.MOutput == H.Output, Self.Context == H.Context {
where H: Handler, Self.MInput == H.Input, Self.MOutput == H.Output {
let withToken = addToken(input: input, attributes: context)
return try await next.handle(context: context, input: withToken)
}

private func addToken(input: OperationStackInput, attributes: HttpContext) -> OperationStackInput {
private func addToken(input: OperationStackInput, attributes: Smithy.Context) -> OperationStackInput {
var copiedInput = input
if input[keyPath: keyPath] == nil {
let idempotencyTokenGenerator = attributes.getIdempotencyTokenGenerator()
Expand All @@ -32,7 +35,7 @@ public struct IdempotencyTokenMiddleware<OperationStackInput, OperationStackOutp

public typealias MInput = OperationStackInput
public typealias MOutput = OperationOutput<OperationStackOutput>
public typealias Context = HttpContext
public typealias Context = Smithy.Context
}

extension IdempotencyTokenMiddleware: HttpInterceptor {
Expand Down
4 changes: 4 additions & 0 deletions Sources/ClientRuntime/Interceptor/AnyInterceptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
// SPDX-License-Identifier: Apache-2.0
//

import protocol Smithy.RequestMessage
import protocol Smithy.ResponseMessage
import protocol Smithy.HasAttributes

/// Type-erased, concrete interceptor.
///
/// In order to have multiple interceptors hooked into a single operation, we
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
// SPDX-License-Identifier: Apache-2.0
//

import protocol Smithy.RequestMessage
import protocol Smithy.ResponseMessage
import protocol Smithy.HasAttributes

/// Default implementation for all interceptor context types.
///
/// This object will be created before operation execution, and passed through each interceptor
Expand Down
20 changes: 20 additions & 0 deletions Sources/ClientRuntime/Interceptor/HasAttributes+Logger.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

import protocol Smithy.HasAttributes
import protocol Smithy.LogAgent
import struct Smithy.AttributeKey

extension HasAttributes {

var logger: LogAgent? {
get { get(key: loggerKey) }
set { set(key: loggerKey, value: newValue) }
}
}

private let loggerKey = AttributeKey<LogAgent>(name: "loggerKey")
6 changes: 5 additions & 1 deletion Sources/ClientRuntime/Interceptor/HttpInterceptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
// SPDX-License-Identifier: Apache-2.0
//

import class Smithy.Context
import class SmithyHTTPAPI.SdkHttpRequest
import class SmithyHTTPAPI.HttpResponse

public protocol HttpInterceptor<InputType, OutputType>: Interceptor
where
RequestType == SdkHttpRequest,
ResponseType == HttpResponse,
AttributesType == HttpContext {}
AttributesType == Smithy.Context {}
4 changes: 4 additions & 0 deletions Sources/ClientRuntime/Interceptor/Interceptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
// SPDX-License-Identifier: Apache-2.0
//

import protocol Smithy.RequestMessage
import protocol Smithy.ResponseMessage
import protocol Smithy.HasAttributes

/// An interceptor allows injecting code into the SDK's request execution pipeline.
public protocol Interceptor<InputType, OutputType, RequestType, ResponseType, AttributesType> {

Expand Down
4 changes: 4 additions & 0 deletions Sources/ClientRuntime/Interceptor/InterceptorContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
// SPDX-License-Identifier: Apache-2.0
//

import protocol Smithy.RequestMessage
import protocol Smithy.ResponseMessage
import protocol Smithy.HasAttributes

/// The base type of all context objects passed to `Interceptor` methods.
public protocol InterceptorContext: AnyObject {

Expand Down
Loading
Loading