Skip to content

Commit

Permalink
feat: apply clock skew interceptor (smithy-lang#1065)
Browse files Browse the repository at this point in the history
  • Loading branch information
lauzadis authored Oct 17, 2023
1 parent 82b71fa commit a932537
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
*/
package aws.sdk.kotlin.codegen

import software.amazon.smithy.kotlin.codegen.core.KotlinWriter
import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes
import software.amazon.smithy.kotlin.codegen.core.getContextValue
import software.amazon.smithy.kotlin.codegen.core.withBlock
import software.amazon.smithy.kotlin.codegen.core.*
import software.amazon.smithy.kotlin.codegen.integration.SectionWriter
import software.amazon.smithy.kotlin.codegen.lang.KotlinTypes
import software.amazon.smithy.kotlin.codegen.rendering.ServiceClientGenerator
Expand Down Expand Up @@ -49,8 +46,8 @@ class ServiceClientCompanionObjectWriter(
RuntimeTypes.Core.Utils.LazyAsyncValue,
AwsRuntimeTypes.Config.Profile.AwsSharedConfig,
) {
declareSection(ServiceClientGenerator.Sections.FinalizeConfig)
writeResolveEndpointUrl()

extendFinalizeConfig?.let {
write("")
it()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
package aws.sdk.kotlin.codegen.customization

import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes
import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration
import software.amazon.smithy.kotlin.codegen.integration.SectionWriter
import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding
import software.amazon.smithy.kotlin.codegen.rendering.ServiceClientGenerator

/**
* Adds a section writer which applies an interceptor that detects and corrects clock skew
*/
class ClockSkew : KotlinIntegration {
override val sectionWriters: List<SectionWriterBinding>
get() = listOf(SectionWriterBinding(ServiceClientGenerator.Sections.FinalizeConfig, clockSkewSectionWriter))

private val clockSkewSectionWriter = SectionWriter { writer, _ ->
val interceptorSymbol = RuntimeTypes.AwsProtocolCore.ClockSkewInterceptor
writer.write("builder.config.interceptors.add(0, #T())", interceptorSymbol)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@ aws.sdk.kotlin.codegen.customization.s3control.HostPrefixFilter
aws.sdk.kotlin.codegen.customization.s3control.ClientConfigIntegration
aws.sdk.kotlin.codegen.protocols.endpoints.BindAwsEndpointBuiltins
aws.sdk.kotlin.codegen.customization.s3.HostPrefixRequestRouteFilter
aws.sdk.kotlin.codegen.customization.s3.UnwrappedXmlOutputIntegration
aws.sdk.kotlin.codegen.customization.s3.UnwrappedXmlOutputIntegration
aws.sdk.kotlin.codegen.customization.ClockSkew

0 comments on commit a932537

Please sign in to comment.