Skip to content

Commit

Permalink
ktlint
Browse files Browse the repository at this point in the history
  • Loading branch information
lauzadis committed Feb 20, 2024
1 parent ec1dabb commit fdfc475
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,30 @@ import software.amazon.smithy.model.transform.ModelTransformer
* 4. Disable all checksums for s3:UploadPart
*/
class S3ExpressIntegration : KotlinIntegration {
override fun enabledForService(model: Model, settings: KotlinSettings) = model.expectShape<ServiceShape>(settings.service).isS3
override fun enabledForService(model: Model, settings: KotlinSettings) =
model.expectShape<ServiceShape>(settings.service).isS3

/**
* Add a synthetic SigV4 S3 Express auth trait
*/
override fun preprocessModel(model: Model, settings: KotlinSettings): Model {
return ModelTransformer.create().mapShapes(model) { shape ->
override fun preprocessModel(model: Model, settings: KotlinSettings): Model =
ModelTransformer.create().mapShapes(model) { shape ->
when {
shape.isServiceShape -> {
val builder = (shape as ServiceShape).toBuilder()

builder.addTrait(SigV4S3ExpressAuthTrait())

val authTrait = AuthTrait(mutableSetOf(SigV4S3ExpressAuthTrait.ID) + shape.expectTrait(AuthTrait::class.java).valueSet)
val authTrait =
AuthTrait(mutableSetOf(SigV4S3ExpressAuthTrait.ID) + shape.expectTrait(AuthTrait::class.java).valueSet)
builder.addTrait(authTrait)

builder.build()
}

else -> shape
}
}
}

override fun customizeMiddleware(ctx: ProtocolGenerator.GenerationContext, resolved: List<ProtocolMiddleware>) =
resolved + listOf(
Expand All @@ -69,7 +71,8 @@ class S3ExpressIntegration : KotlinIntegration {
private val AddClientToExecutionContext = object : ProtocolMiddleware {
override val name: String = "AddClientToExecutionContext"

override fun isEnabledFor(ctx: ProtocolGenerator.GenerationContext, op: OperationShape): Boolean = ctx.model.expectShape<ServiceShape>(ctx.settings.service).isS3
override fun isEnabledFor(ctx: ProtocolGenerator.GenerationContext, op: OperationShape): Boolean =
ctx.model.expectShape<ServiceShape>(ctx.settings.service).isS3

override fun render(ctx: ProtocolGenerator.GenerationContext, op: OperationShape, writer: KotlinWriter) {
val attributesSymbol = buildSymbol {
Expand Down Expand Up @@ -123,7 +126,8 @@ class S3ExpressIntegration : KotlinIntegration {
// S3 models a header name x-amz-sdk-checksum-algorithm representing the name of the checksum algorithm used
val checksumHeaderName = checksumAlgorithmMember?.getTrait<HttpHeaderTrait>()?.value

val checksumRequired = op.hasTrait<HttpChecksumRequiredTrait>() || httpChecksumTrait?.isRequestChecksumRequired == true
val checksumRequired =
op.hasTrait<HttpChecksumRequiredTrait>() || httpChecksumTrait?.isRequestChecksumRequired == true

if (checksumRequired) {
writer.write("op.interceptors.add(#T(${checksumHeaderName?.dq() ?: ""}))", interceptorSymbol)
Expand All @@ -134,7 +138,8 @@ class S3ExpressIntegration : KotlinIntegration {
private val UploadPartDisableChecksum = object : ProtocolMiddleware {
override val name: String = "UploadPartDisableChecksum"

override fun isEnabledFor(ctx: ProtocolGenerator.GenerationContext, op: OperationShape): Boolean = op.isS3UploadPart
override fun isEnabledFor(ctx: ProtocolGenerator.GenerationContext, op: OperationShape): Boolean =
op.isS3UploadPart

override fun render(ctx: ProtocolGenerator.GenerationContext, op: OperationShape, writer: KotlinWriter) {
val interceptorSymbol = buildSymbol {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
import software.amazon.smithy.model.node.Node
import software.amazon.smithy.model.shapes.ShapeId
import software.amazon.smithy.model.traits.AbstractTrait
Expand All @@ -11,4 +15,4 @@ internal class SigV4S3ExpressAuthTrait : AbstractTrait(ID, Node.objectNode()) {
}
override fun createNode(): Node = Node.objectNode()
override fun isSynthetic(): Boolean = true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
*/
package aws.sdk.kotlin.services.s3.express

import aws.sdk.kotlin.services.s3.*
import aws.sdk.kotlin.services.s3.S3Attributes
import aws.sdk.kotlin.services.s3.S3Client
import aws.sdk.kotlin.services.s3.*
import aws.smithy.kotlin.runtime.ExperimentalApi
import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials
import aws.smithy.kotlin.runtime.collections.Attributes
Expand Down Expand Up @@ -109,7 +109,6 @@ internal class DefaultS3ExpressCredentialsProvider(
} catch (e: Exception) {
logger.warn(e) { "Failed to refresh credentials for ${entry.key.bucket}" }
}

}
}

Expand Down Expand Up @@ -139,7 +138,7 @@ internal class DefaultS3ExpressCredentialsProvider(
secretAccessKey = credentials.secretAccessKey,
sessionToken = credentials.sessionToken,
expiration = credentials.expiration,
providerName = CREDENTIALS_PROVIDER_NAME ,
providerName = CREDENTIALS_PROVIDER_NAME,
),
expirationTimeMark,
)
Expand All @@ -153,7 +152,6 @@ internal class DefaultS3ExpressCredentialsProvider(
}
}


/**
* Get the [Duration] between [this] TimeMark and an [other] TimeMark
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,9 @@
*/
package aws.sdk.kotlin.services.s3.express

import aws.sdk.kotlin.services.s3.*
import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials
import aws.smithy.kotlin.runtime.collections.LruCache
import aws.smithy.kotlin.runtime.io.Closeable
import aws.smithy.kotlin.runtime.telemetry.TelemetryProviderContext
import aws.smithy.kotlin.runtime.telemetry.logging.logger
import aws.smithy.kotlin.runtime.time.Clock
import aws.smithy.kotlin.runtime.time.until
import kotlinx.coroutines.*
import kotlin.coroutines.CoroutineContext
import kotlin.time.Duration
import kotlin.time.Duration.Companion.minutes
import kotlin.time.Duration.Companion.seconds
import kotlin.time.TimeMark
import kotlin.time.TimeSource

private const val DEFAULT_S3_EXPRESS_CACHE_SIZE: Int = 100

Expand All @@ -29,7 +17,7 @@ internal class S3ExpressCredentialsCache {

suspend fun put(key: S3ExpressCredentialsCacheKey, value: S3ExpressCredentialsCacheValue) = lru.put(key, value)

suspend fun remove(key: S3ExpressCredentialsCacheKey) : S3ExpressCredentialsCacheValue? = lru.remove(key)
suspend fun remove(key: S3ExpressCredentialsCacheKey): S3ExpressCredentialsCacheValue? = lru.remove(key)

public val size: Int
get() = lru.size
Expand All @@ -53,4 +41,4 @@ internal data class S3ExpressCredentialsCacheValue(
*/
internal data class ExpiringValue<T> (val value: T, val expiresAt: TimeMark)

internal val ExpiringValue<Credentials>.isExpired: Boolean get() = (expiresAt + REFRESH_BUFFER).hasPassedNow()
internal val ExpiringValue<Credentials>.isExpired: Boolean get() = (expiresAt + REFRESH_BUFFER).hasPassedNow()
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ package aws.sdk.kotlin.services.s3.express
import aws.smithy.kotlin.runtime.auth.awscredentials.Credentials
import kotlinx.coroutines.test.runTest
import kotlin.test.*
import kotlin.time.TestTimeSource
import kotlin.time.Duration.Companion.seconds
import kotlin.time.TestTimeSource

public class S3ExpressCredentialsCacheTest {
@Test
Expand Down

0 comments on commit fdfc475

Please sign in to comment.