-
Notifications
You must be signed in to change notification settings - Fork 30
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
Conversation
.library(name: "SmithyEventStreamsAPI", targets: ["SmithyEventStreamsAPI"]), | ||
.library(name: "SmithyEventStreamsAuthAPI", targets: ["SmithyEventStreamsAuthAPI"]), | ||
.library(name: "SmithyEventStreams", targets: ["SmithyEventStreams"]), | ||
.library(name: "SmithyChecksumsAPI", targets: ["SmithyChecksumsAPI"]), |
There was a problem hiding this comment.
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 | ||
|
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
// All Rights Reserved. | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// |
There was a problem hiding this comment.
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 | ||
// |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this 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"]), |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 @@ | |||
// |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
)
/// 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() | ||
} | ||
} |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this 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
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.
SmithyEventStreamsAPI
for types supporting event streams.SmithyEventStreamsAuthAPI
for types supporting message signing interfaces.SmithyEventStreams
for the parts ofSmithyEventStreamsAPI
that have CRT dependencies.Other changes:
HttpContext
has been renamed toContext
and moved to a newSmithy
module for lightweight sharing across modules.Attributes
andAttributeKey
types have been moved as well.context
are provided in their place.ClientRuntime
typealiases of Foundation types have been removed, and the corresponding Foundation types are used directly.Middleware
andHandler
no longer have a Context associated type, since theContext
type is used for all cases.Scope
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.