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 #1530

Merged
merged 17 commits into from
May 31, 2024

Conversation

jbelkins
Copy link
Contributor

@jbelkins jbelkins commented May 29, 2024

Issue #

#1384 (Modularize Event Streams)
#1385 (Modularize Event Streams Auth)

Description of changes

Event streams code has been modularized by either moving it to a new module in this SDK or moving it out to smithy-swift. Several other functions (HTTPAuth, checksums, etc.) have been partially modularized along with event streams & event streams auth.

New/existing dependencies impact assessment, if applicable

No new dependencies were added to this change.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

static var smithyEventStreamsAPI: Self { .product(name: "SmithyEventStreamsAPI", package: "smithy-swift") }
static var smithyEventStreamsAuthAPI: Self { .product(name: "SmithyEventStreamsAuthAPI", package: "smithy-swift") }
static var smithyEventStreams: Self { .product(name: "SmithyEventStreams", package: "smithy-swift") }
static var smithyChecksumsAPI: Self { .product(name: "SmithyChecksumsAPI", package: "smithy-swift") }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Created several new modules in smithy-swift; they are added here as dependencies

.library(name: "AWSClientRuntime", targets: ["AWSClientRuntime"]),
.library(name: "AWSSDKEventStreamsAuth", targets: ["AWSSDKEventStreamsAuth"]),
.library(name: "AWSSDKIdentity", targets: ["AWSSDKIdentity"]),
.library(name: "AWSSDKHTTPAuth", targets: ["AWSSDKHTTPAuth"]),
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 AWS modules are added.

AWSSDKIdentity and AWSSDKHTTPAuth are likely not complete; enough types were added to them to allow event stream modularization.

@@ -105,14 +147,30 @@ func addDoccDependency() {

// MARK: - Services

let serviceTargetDependencies: [Target.Dependency] = [
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This long list is broken into a variable so it can be shared between service client targets and protocol test targets.

@@ -21,6 +21,12 @@ extension Target.Dependency {
static var clientRuntime: Self { .product(name: "ClientRuntime", package: "smithy-swift") }
static var smithyRetriesAPI: Self { .product(name: "SmithyRetriesAPI", package: "smithy-swift") }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This file is generated. See comments in the Package.Base.swift above.

@@ -5,9 +5,10 @@
// SPDX-License-Identifier: Apache-2.0
//
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, like this one, have import and type namespace adjustments. I won't comment on those every time they happen in the following files.

@@ -5,13 +5,14 @@
// SPDX-License-Identifier: Apache-2.0
//
Copy link
Contributor Author

Choose a reason for hiding this comment

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

AWSCredentialIdentity (above) was moved out to smithy-swift because SRA specifies that it should be there.

@@ -3,6 +3,7 @@
* SPDX-License-Identifier: Apache-2.0.
*/

import class SmithyHTTPAPI.HttpResponse
import ClientRuntime
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The following files (the event stream files in AWSClientRuntime) have been moved to smithy-swift since they are not actually AWS-specific.

@@ -18,8 +20,7 @@ public struct AWSS3ErrorWith200StatusXMLMiddleware<OperationStackInput, Operatio
next: H) async throws -> OperationOutput<OperationStackOutput>
where H: Handler,
Self.MInput == H.Input,
Self.MOutput == H.Output,
Self.Context == H.Context {
Self.MOutput == H.Output {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

As you will see later, Context is removed as a generic type on both the Middleware and Handler protocols, because it does not need to be specialized.

@@ -1,9 +1,12 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0.

import class Smithy.Context
Copy link
Contributor Author

Choose a reason for hiding this comment

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

HttpContext was moved into the new Smithy module and renamed to Context since it is not specific to HTTP.

@@ -22,22 +22,3 @@ extension String {
String(map { tokenNoHashCharacterSet.contains($0) ? $0 : substituteCharacter })
}
}

extension String {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This extension was moved since it is used with checksums.


extension AWSEventStream {
/// Signs a `Message` using the AWS SigV4 signing algorithm
public class AWSMessageSigner: MessageSigner {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the SigV4 signer for event streams. It is moved from AWSClientRuntime to the new AWSSDKEventStreamsAuth module.

import struct Foundation.Data
import AwsCommonRuntimeKit

extension AWSSigV4Signer: MessageDataSigner {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This extension was previously defined right on the signer. Moved it out separate so it could be packaged with event streams auth.

import SmithyEventStreams
import SmithyEventStreamsAuthAPI

extension Context {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some special functions on the Context object to support event streams auth.

import AwsCommonRuntimeKit
import ClientRuntime
import Foundation

public class AWSSigV4Signer: ClientRuntime.Signer {
public class AWSSigV4Signer: SmithyHTTPAuthAPI.Signer {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the regular signer for SigV4. It is split from AWSClientRuntime to the new AWSSDKHTTPAuth module.

@@ -127,18 +135,6 @@ public class AWSSigV4Signer: ClientRuntime.Signer {
)
}

public func signEvent(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The event signing methods on this signer were split off to an extension in the event streams auth module.

@jbelkins jbelkins changed the title Jbe/modularize event streams feat!: Modularize event streams & event streams auth May 29, 2024
@jbelkins jbelkins marked this pull request as ready for review May 29, 2024 15:19
@jbelkins jbelkins requested a review from dayaffe May 29, 2024 15:19
@jbelkins jbelkins requested a review from sichanyoo May 29, 2024 15:19
Copy link
Contributor

@sichanyoo sichanyoo left a comment

Choose a reason for hiding this comment

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

1 naming & 1 access level comment

@@ -35,7 +41,10 @@ let package = Package(
.watchOS(.v6)
],
products: [
.library(name: "AWSClientRuntime", targets: ["AWSClientRuntime"])
.library(name: "AWSClientRuntime", targets: ["AWSClientRuntime"]),
.library(name: "AWSSDKEventStreamsAuth", targets: ["AWSSDKEventStreamsAuth"]),
Copy link
Contributor

Choose a reason for hiding this comment

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

naming: For the new modules, I think it would be better to name it AWSXYZ instead of AWSSDKXYZ given SDK is redundant & AWSSDK is harder to read with 2 S's back to back

Copy link
Contributor

@dayaffe dayaffe May 31, 2024

Choose a reason for hiding this comment

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

Good with either AWS prefix or SDK prefix. My preference is actually SDK because I think it is more clear. I.e. this is our runtime / our code not something determined by AWS service teams

Copy link
Contributor

Choose a reason for hiding this comment

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

The runtime & our code are determined by AWS specifications, hence the AWS prefix suggestion.

Imo SDK by itself would be ambiguous. By itself, it doesn't carry the meaning that it's built for AWS spec.

Come to think of it though, I guess making the prefix SDK does allow users to easily distinguish SDK module imports vs Service module imports since all the service modules start with AWS.

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 used AWSSDK as the prefix for SDK runtime modules because all our service client modules are prefixed with only AWS.

For example, I can easily see an AWS service being launched with the name Identity... you can see the potential for namespace collisions.

So using AWSSDK as the prefix for runtime names helps to prevent namespace collisions between SDK components and AWS service clients.

import Foundation

/// A credential identity resolver that caches the credentials sourced from the provided resolver.
public struct CachedAWSCredentialIdentityResolver: AWSCredentialIdentityResolvedByCRT {
let crtAWSCredentialIdentityResolver: AwsCommonRuntimeKit.CredentialsProvider
public let crtAWSCredentialIdentityResolver: AwsCommonRuntimeKit.CredentialsProvider
Copy link
Contributor

Choose a reason for hiding this comment

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

Q: Why was this property made public in this and other AWS credential identity resolvers? Afaik I don't think we want to expose the underlying CRT stuff where possible

Copy link
Contributor

@dayaffe dayaffe May 31, 2024

Choose a reason for hiding this comment

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

+1 on keeping this private, if code outside needs to interact with this let's add own public methods for accomplishing that rather than utilizing it directly

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Honestly I did not look at this closely; I added public to get the code to compile.

This should be sorted out in #1382 along with the rest of the identity code.

Copy link
Contributor

Choose a reason for hiding this comment

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

👌

@sichanyoo sichanyoo self-requested a review May 31, 2024 20:59
Copy link
Contributor

@sichanyoo sichanyoo left a comment

Choose a reason for hiding this comment

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

lgtm

@jbelkins jbelkins merged commit bf8a8b3 into main May 31, 2024
29 checks passed
@jbelkins jbelkins deleted the jbe/modularize_event_streams branch May 31, 2024 21:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants