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

Conversation

jbelkins
Copy link
Contributor

@jbelkins jbelkins commented May 29, 2024

Issue #

awslabs/aws-sdk-swift#1384 (Modularize Event Streams)
awslabs/aws-sdk-swift#1385 (Modularize Event Streams Auth)

Description of changes

Event streams are modularized per SRA. Corresponding modules are created in the SDK for event streams as well. Other modules have been created and types have been moved into them, but may not be complete.

  • Creates the following modules:
    • SmithyEventStreamsAPI for types supporting event streams.
    • SmithyEventStreamsAuthAPI for types supporting message signing interfaces.
    • SmithyEventStreams for the parts of SmithyEventStreamsAPI that have CRT dependencies.

Other changes:

  • HttpContext has been renamed to Context and moved to a new Smithy module for lightweight sharing across modules.
    • Attributes and AttributeKey types have been moved as well.
    • Specific attribute keys have been moved to various modules, and have been made private. Public accessors on context are provided in their place.
  • The ClientRuntime typealiases of Foundation types have been removed, and the corresponding Foundation types are used directly.
  • Middleware and Handler no longer have a Context associated type, since the Context type is used for all cases.

Scope

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

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

.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.

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.

import class Smithy.Context
import class Smithy.ContextBuilder

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.

Broke these idempotency-related context extensions out to their own file.

@jbelkins jbelkins changed the title Jbe/modularize event streams feat!: Modularize event streams & event streams auth May 29, 2024
// All Rights Reserved.
//
// 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.

Moved to the SmithyHTTPAuthAPI module

// All Rights Reserved.
//
// 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.

Moved to the SmithyEventStreamsAPI module


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

import AwsCommonRuntimeKit

public enum HashError: Error {
case invalidInput
case hashingFailed(reason: String)
}

public enum ChecksumAlgorithm {
case crc32, crc32c, sha1, sha256, md5
extension ChecksumAlgorithm {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

ChecksumAlgorithm itself was moved out to SmithyHTTPAuthAPI. This extension remains here because it is dependent on CRT.

Copy link
Contributor

Choose a reason for hiding this comment

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

SEP says to place checksum things that depend on CRT into its own module, "checksums-crt" module. With our naming pattern, it would be SmithyChecksumsCRT. What was the reason for keeping this in ClientRuntime?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1 to Chan's comment on moving them to their own module, but agree with keep ChecksumsCRT module in ClientRuntime as checksums themselves aren't AWS specific concepts

* SPDX-License-Identifier: Apache-2.0.
*/

import AwsCommonRuntimeKit
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 was split into ClientError in the Smithy module, and HTTPClientError in the SmithyHTTPAPI module (for the path & query cases.)

//

/// Errors that may occur when creating a HTTP request.
public enum HTTPClientError: Error {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Split these errors off of ClientError because these are HTTP-specific.

@@ -233,25 +231,6 @@ extension Header: Comparable {
}
}

extension Headers {
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 CRT-dependent extension stayed behind.

@@ -35,33 +36,3 @@ extension HttpResponse: CustomDebugStringConvertible {
return "\nStatus Code: \(statusCode.description) \n \(headers)"
}
}

extension HttpResponse: WireDataProviding {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These extensions stayed behind in ClientRuntime.

@@ -67,56 +73,6 @@ public final class SdkHttpRequest: RequestMessage {
}
}

extension SdkHttpRequest {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

CRT-specific code stayed behind.

import class SmithyHTTPAPI.SdkHttpRequestBuilder
import protocol SmithyIdentityAPI.Identity

public protocol 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.

Moved in from ClientRuntime, minus the event stream methods that were split off to MessageDataSigner.

/// A type representing AWS credentials for authenticating with an AWS service
///
/// For more information see [AWS security credentials](https://docs.aws.amazon.com/general/latest/gr/aws-security-credentials.html#AccessKeys)
public struct AWSCredentialIdentity: Identity {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved in from SDK. Despite this being SDK-specific, SRA says it belongs here.

@@ -0,0 +1,82 @@
//
// Copyright Amazon.com Inc. or its affiliates.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved in from SDK

// SPDX-License-Identifier: Apache-2.0
//

import SmithyEventStreams
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved in from SDK

//

import SmithyEventStreamsAPI
import Foundation
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved in from SDK

//

import SmithyEventStreamsAPI
import XCTest
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved in from SDK

@@ -19,6 +19,8 @@ import software.amazon.smithy.swift.codegen.model.boxed
import software.amazon.smithy.swift.codegen.model.buildSymbol
import software.amazon.smithy.swift.codegen.model.defaultValue
import software.amazon.smithy.swift.codegen.model.getTrait
import software.amazon.smithy.swift.codegen.swiftmodules.SmithyHTTPAuthAPITypes
import software.amazon.smithy.swift.codegen.swiftmodules.SmithyTypes
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Codegen changes are generally about changing types & adding imports. No further comments on codegen or codegen tests.

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.

Couple small things & questions

@@ -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.

import AwsCommonRuntimeKit

public enum HashError: Error {
case invalidInput
case hashingFailed(reason: String)
}

public enum ChecksumAlgorithm {
case crc32, crc32c, sha1, sha256, md5
extension ChecksumAlgorithm {
Copy link
Contributor

Choose a reason for hiding this comment

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

SEP says to place checksum things that depend on CRT into its own module, "checksums-crt" module. With our naming pattern, it would be SmithyChecksumsCRT. What was the reason for keeping this in ClientRuntime?

@@ -0,0 +1,62 @@
//
Copy link
Contributor

Choose a reason for hiding this comment

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

Q: This one is kept in ClientRuntime, but header+CRT is moved to new module at Sources/SmithyEventStreams/Header+CRT.swift. What's the criteria used for breaking things with CRT dependency into its own module vs keeping it in 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.

Remember: I'm not completely modularizing anything except event streams & event streams auth.

So don't sweat things that should be in HTTP, HTTPAuth, etc but didn't get moved. But if something was moved to the wrong module, we should address that now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sources/SmithyEventStreams/Header+CRT.swift is related to event streams headers, not HTTP headers.

So this file goes into SmithyEventStreams because:

  • it is event stream related
  • it has a CRT dependency (i.e. it can't go into SmithyEventStreamsAPI)

Comment on lines +12 to +22
/// Encodes a `Message` into a `Data` object
/// to be sent over the wire.
public struct DefaultMessageEncoder: MessageEncoder {
public init() {}

/// Encodes a `Message` into a `Data` object
public func encode(message: Message) throws -> Data {
let crtMessage = message.toCRTMessage()
return try crtMessage.getEncoded()
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

reminder: Extra indent for entire struct here as well, in addition to commented one in Sources/SmithyEventStreams/DefaultMessageEncoderStream.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.

Yeah, those will all be cleaned up later.

There will likely be some time spent on cleanup across the board after all the modules have been completed.

private let authSchemesKey = AttributeKey<Attributes>(name: "AuthSchemes")
private let authSchemeResolverKey = AttributeKey<AuthSchemeResolver>(name: "AuthSchemeResolver")
private let selectedAuthSchemeKey = AttributeKey<SelectedAuthScheme>(name: "SelectedAuthScheme")
private let signingAlgorithmKey = AttributeKey<SigningAlgorithm>(name: "SigningAlgorithmKey")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: There's duplicate of signingAlgorithmKey in Sources/SmithyHTTPAPI/Context+HTTP.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 has been cleared up, the other extension was deleted.

Copy link
Contributor

@dayaffe dayaffe left a comment

Choose a reason for hiding this comment

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

Approved given Checksums is moved to its own module as Chan mentioned

@sichanyoo sichanyoo self-requested a review May 31, 2024 20:58
@jbelkins jbelkins merged commit dfa21d4 into main May 31, 2024
17 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