Skip to content

Conversation

jbelkins
Copy link
Contributor

@jbelkins jbelkins commented Sep 26, 2025

Description of changes

smithy-lang/smithy-swift#968 (the companion to this PR) implements clock skew interfaces and infrastructure.

This PR replaces some "generic Smithy" implementation of clock skew with behaviors specialized for AWS.

  • AWSClockSkewProvider calculates clock skew based on characteristics of AWS-specific modeled errors. Codegen changes install this provider in the orchestrator for AWS operation invocations.
  • The AWS-specific AWSSigV4Signer and various token providers are modified for changes to signing of HTTP requests made in the companion PR.

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.

.SmithyIdentity,
.SmithyRetriesAPI,
.SmithyRetries,
.SmithyTimestamps,
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 new AWS-specific clock skew provider uses SmithyTimestamps to read the date header in HTTP responses, hence the dependency is added.

runtimeSymbol("UnknownAWSHTTPServiceError", SwiftDeclaration.STRUCT, listOf("UnknownAWSHTTPServiceError"))
val AWSServiceError = runtimeSymbol("AWSServiceError", SwiftDeclaration.PROTOCOL)
val Sha256TreeHashMiddleware = runtimeSymbol("Sha256TreeHashMiddleware", SwiftDeclaration.STRUCT)
val AWSClockSkewProvider = runtimeSymbol("AWSClockSkewProvider", SwiftDeclaration.ENUM)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

SwiftSymbol for the AWS-specific clock skew provider.


override val clockSkewProviderSymbol: Symbol
get() = AWSClientRuntimeTypes.Core.AWSClockSkewProvider

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Overrides the clock skew provider to use the AWS-specific implementation.

builder.interceptors.add(ClientRuntime.ContentLengthMiddleware<NoInputAndOutputInput, NoInputAndOutputOutput>())
builder.deserialize(ClientRuntime.DeserializeMiddleware<NoInputAndOutputOutput>(NoInputAndOutputOutput.httpOutput(from:), NoInputAndOutputOutputError.httpError(from:)))
builder.interceptors.add(ClientRuntime.LoggerMiddleware<NoInputAndOutputInput, NoInputAndOutputOutput>(clientLogMode: config.clientLogMode))
builder.clockSkewProvider(AWSClientRuntime.AWSClockSkewProvider.clockSkew(request:response:error: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.

Here & below, expectations for several tests are changed to accommodate new codegen.

@_spi(SmithyTimestamps) import struct SmithyTimestamps.TimestampFormatter

public enum AWSClockSkewProvider {

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 AWS-specific clock skew provider.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No further explanation, see inline code comments.

} else {
throw TestHTTPError(statusCode: response.statusCode)
}
})
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 test file changed comparable to the retry integration tests in smithy-swift.

import class Smithy.Context
import class Smithy.ContextBuilder
import class SmithyHTTPAPI.HTTPRequest
import class SmithyHTTPAPI.HTTPResponse
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 & the next few below demonstrate the changes to code-generated clients.

builder.interceptors.add(ClientRuntime.ContentLengthMiddleware<NoInputAndOutputInput, NoInputAndOutputOutput>())
builder.deserialize(ClientRuntime.DeserializeMiddleware<NoInputAndOutputOutput>(NoInputAndOutputOutput.httpOutput(from:), NoInputAndOutputOutputError.httpError(from:)))
builder.interceptors.add(ClientRuntime.LoggerMiddleware<NoInputAndOutputInput, NoInputAndOutputOutput>(clientLogMode: config.clientLogMode))
builder.clockSkewProvider(AWSClientRuntime.AWSClockSkewProvider.provider())
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here & below, test expectations are updated for clock skew codegen.

(Not sure why the change in escaping of $ but it works... I suspect it's a change in IntelliJ copy/paste of Kotlin strings.)

requestBuilder.withQueryItem(URIQueryItem(name: "DBUser", value: username))

let signedAt = Date()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

AuthTokenGenerator modified to provide signedAt to signer.

import SmithyHTTPAPI
@_spi(SmithyTimestamps) import SmithyTimestamps

class AWSClockSkewProviderTests: XCTestCase {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tests for the behavior of the clock skew provider above.

)
}

var signingConfig = try constructSigningConfig(identity: identity, signingProperties: signingProperties)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

AWSSigV4Signer changed comparably to the one in smithy-swift, to set signedAt.

.SmithyIdentity,
.SmithyRetriesAPI,
.SmithyRetries,
.SmithyTimestamps,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

See Package.Base.swift at top; this file's just generated from that.

@jbelkins jbelkins marked this pull request as ready for review October 3, 2025 15:42
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.

Just needs Package.version.next unstaged, but otherwise everything lgtm

@jbelkins jbelkins merged commit 36d15bf into main Oct 7, 2025
31 checks passed
@jbelkins jbelkins deleted the jbe/clock_skew branch October 7, 2025 21:06
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