Skip to content

Commit 2df8770

Browse files
committed
lint
1 parent 6929c32 commit 2df8770

File tree

2 files changed

+19
-27
lines changed

2 files changed

+19
-27
lines changed

codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/customization/EnvironmentTokenCustomization.kt

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,16 @@ package aws.sdk.kotlin.codegen.customization
66

77
import aws.sdk.kotlin.codegen.ServiceClientCompanionObjectWriter
88
import software.amazon.smithy.kotlin.codegen.KotlinSettings
9-
import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration
10-
import software.amazon.smithy.model.Model
11-
import software.amazon.smithy.model.shapes.ServiceShape
12-
import software.amazon.smithy.kotlin.codegen.core.CodegenContext
13-
import software.amazon.smithy.kotlin.codegen.core.KotlinDelegator
14-
import software.amazon.smithy.kotlin.codegen.core.KotlinWriter
15-
import software.amazon.smithy.kotlin.codegen.core.RuntimeTypes
16-
import software.amazon.smithy.kotlin.codegen.core.closeAndOpenBlock
17-
import software.amazon.smithy.kotlin.codegen.core.getContextValue
9+
import software.amazon.smithy.kotlin.codegen.core.*
1810
import software.amazon.smithy.kotlin.codegen.integration.AppendingSectionWriter
11+
import software.amazon.smithy.kotlin.codegen.integration.KotlinIntegration
1912
import software.amazon.smithy.kotlin.codegen.integration.SectionWriterBinding
2013
import software.amazon.smithy.kotlin.codegen.model.buildSymbol
2114
import software.amazon.smithy.kotlin.codegen.model.expectShape
22-
import software.amazon.smithy.kotlin.codegen.rendering.ServiceClientGenerator
2315
import software.amazon.smithy.kotlin.codegen.model.knowledge.AwsSignatureVersion4
24-
import kotlin.text.removeSuffix
16+
import software.amazon.smithy.kotlin.codegen.rendering.ServiceClientGenerator
17+
import software.amazon.smithy.model.Model
18+
import software.amazon.smithy.model.shapes.ServiceShape
2519

2620
/**
2721
* Customization that support sourcing Bearer tokens from an environment variable
@@ -47,12 +41,12 @@ class EnvironmentTokenCustomization : KotlinIntegration {
4741

4842
override fun writeAdditionalFiles(ctx: CodegenContext, delegator: KotlinDelegator) {
4943
val serviceShape = ctx.model.expectShape<ServiceShape>(ctx.settings.service)
50-
val serviceName = ctx.symbolProvider.toSymbol(serviceShape).name.removeSuffix("Client")
44+
val serviceName = ctx.symbolProvider.toSymbol(serviceShape).name.removeSuffix("Client")
5145
val packageName = ctx.settings.pkg.name
5246

5347
delegator.useFileWriter(
5448
"Finalize${serviceName}EnvironmentTokenConfig.kt",
55-
"${packageName}.auth"
49+
"$packageName.auth",
5650
) { writer ->
5751
renderEnvironmentTokenConfig(
5852
writer,
@@ -75,11 +69,11 @@ class EnvironmentTokenCustomization : KotlinIntegration {
7569
writer.apply {
7670
openBlock(
7771
"internal fun finalize#LEnvironmentTokenConfig(",
78-
serviceName
72+
serviceName,
7973
)
8074
write(
8175
"builder: #T.Builder,",
82-
serviceSymbol
76+
serviceSymbol,
8377
)
8478
write(
8579
"provider: #T = #T.System",
@@ -92,7 +86,7 @@ class EnvironmentTokenCustomization : KotlinIntegration {
9286
// The customization do nothing if environment variable is not set
9387
openBlock(
9488
"if (provider.getenv(#S) != null) {",
95-
envVarName
89+
envVarName,
9690
)
9791

9892
// Configure auth scheme preference if customer hasn't specify one
@@ -119,7 +113,7 @@ class EnvironmentTokenCustomization : KotlinIntegration {
119113

120114
write(
121115
"builder.config.bearerTokenProvider = " +
122-
"builder.config.bearerTokenProvider ?: configureEnvironmentTokenProvider(provider)",
116+
"builder.config.bearerTokenProvider ?: configureEnvironmentTokenProvider(provider)",
123117
)
124118

125119
closeBlock("}")
@@ -142,26 +136,26 @@ class EnvironmentTokenCustomization : KotlinIntegration {
142136
openBlock(
143137
"override suspend fun resolve(attributes: #T): #T {",
144138
RuntimeTypes.Core.Collections.Attributes,
145-
RuntimeTypes.Auth.HttpAuth.BearerToken
139+
RuntimeTypes.Auth.HttpAuth.BearerToken,
146140
)
147141

148142
// Check environment variable on each resolve call
149143
write(
150144
"val bearerToken = provider.getenv(#S) ?: error(#S)",
151145
envVarName,
152-
"$envVarName environment variable is not set"
146+
"$envVarName environment variable is not set",
153147
)
154148

155149
openBlock("return object : BearerToken {")
156150

157151
write("override val token: String = bearerToken")
158152
write(
159153
"override val attributes: Attributes = #T()",
160-
RuntimeTypes.Core.Collections.emptyAttributes
154+
RuntimeTypes.Core.Collections.emptyAttributes,
161155
)
162156
write(
163157
"override val expiration: #T? = null",
164-
RuntimeTypes.Core.Instant
158+
RuntimeTypes.Core.Instant,
165159
)
166160

167161
closeBlock("}")

services/bedrock/e2eTest/src/BedrockEnvironmentTokenTest.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,10 @@ class BedrockEnvironmentTokenTest {
121121
val client = BedrockClient.fromEnvironment {
122122
region = "us-west-2"
123123
bearerTokenProvider = object : BearerTokenProvider {
124-
override suspend fun resolve(attributes: Attributes): BearerToken {
125-
return object : BearerToken {
126-
override val token: String = "different-bedrock-token"
127-
override val attributes: Attributes = emptyAttributes()
128-
override val expiration: Instant? = null
129-
}
124+
override suspend fun resolve(attributes: Attributes): BearerToken = object : BearerToken {
125+
override val token: String = "different-bedrock-token"
126+
override val attributes: Attributes = emptyAttributes()
127+
override val expiration: Instant? = null
130128
}
131129
}
132130
}

0 commit comments

Comments
 (0)