Skip to content

Commit 8d89323

Browse files
committed
Fix runtime warnings
1 parent 68d2277 commit 8d89323

File tree

8 files changed

+22
-9
lines changed

8 files changed

+22
-9
lines changed

aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/auth/credentials/ImdsCredentialsProvider.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ public class ImdsCredentialsProvider(
132132
private suspend fun loadProfile() = try {
133133
client.value.get(CREDENTIALS_BASE_PATH)
134134
} catch (ex: EC2MetadataError) {
135-
if (ex.statusCode == HttpStatusCode.NotFound.value) {
135+
if (ex.status == HttpStatusCode.NotFound) {
136136
coroutineContext.info<ImdsCredentialsProvider> {
137137
"Received 404 from IMDS when loading profile information. Hint: This instance may not have an " +
138138
"IAM role associated."
@@ -142,7 +142,7 @@ public class ImdsCredentialsProvider(
142142
}
143143

144144
private suspend fun useCachedCredentials(ex: Exception): Credentials? = when {
145-
ex is IOException || ex is EC2MetadataError && ex.statusCode == HttpStatusCode.InternalServerError.value -> {
145+
ex is IOException || ex is EC2MetadataError && ex.status == HttpStatusCode.InternalServerError -> {
146146
mu.withLock {
147147
previousCredentials?.apply { nextRefresh = clock.now() + DEFAULT_CREDENTIALS_REFRESH_SECONDS.seconds }
148148
}

aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/config/endpoints/AccountIdEndpointMode.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,4 @@ public fun AccountIdEndpointMode.toBusinessMetric(): BusinessMetric = when (this
3535
AccountIdEndpointMode.PREFERRED -> SmithyBusinessMetric.ACCOUNT_ID_MODE_PREFERRED
3636
AccountIdEndpointMode.DISABLED -> SmithyBusinessMetric.ACCOUNT_ID_MODE_DISABLED
3737
AccountIdEndpointMode.REQUIRED -> SmithyBusinessMetric.ACCOUNT_ID_MODE_REQUIRED
38-
else -> throw IllegalStateException("Unexpected AccountIdEndpointMode value: ${this::class.simpleName}")
3938
}

aws-runtime/aws-config/common/src/aws/sdk/kotlin/runtime/config/imds/TokenMiddleware.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ internal class TokenMiddleware(
6666
return try {
6767
when (call.response.status) {
6868
HttpStatusCode.OK -> {
69-
val ttl = call.response.headers[X_AWS_EC2_METADATA_TOKEN_TTL_SECONDS]?.toLong() ?: throw EC2MetadataError(200, "No TTL provided in IMDS response")
70-
val token = call.response.body.readAll() ?: throw EC2MetadataError(200, "No token provided in IMDS response")
69+
val ttl = call.response.headers[X_AWS_EC2_METADATA_TOKEN_TTL_SECONDS]?.toLong() ?: throw EC2MetadataError(call.response.status, "No TTL provided in IMDS response")
70+
val token = call.response.body.readAll() ?: throw EC2MetadataError(call.response.status, "No token provided in IMDS response")
7171
val expires = clock.now() + ttl.seconds
7272
Token(token, expires)
7373
}
@@ -76,7 +76,7 @@ internal class TokenMiddleware(
7676
HttpStatusCode.Forbidden -> "Request forbidden: IMDS is disabled or the caller has insufficient permissions."
7777
else -> "Failed to retrieve IMDS token"
7878
}
79-
throw EC2MetadataError(call.response.status.value, message)
79+
throw EC2MetadataError(call.response.status, message)
8080
}
8181
}
8282
} finally {

aws-runtime/aws-config/common/test/aws/sdk/kotlin/runtime/config/imds/ImdsClientTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ class ImdsClientTest {
200200
client.get("/latest/metadata")
201201
}
202202

203-
assertEquals(HttpStatusCode.Forbidden.value, ex.statusCode)
203+
assertEquals(HttpStatusCode.Forbidden, ex.status)
204204
connection.assertRequests()
205205
}
206206

build.gradle.kts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import aws.sdk.kotlin.gradle.dsl.configureLinting
66
import aws.sdk.kotlin.gradle.dsl.configureNexus
77
import aws.sdk.kotlin.gradle.util.typedProp
8+
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
89

910
buildscript {
1011
// NOTE: buildscript classpath for the root project is the parent classloader for the subprojects, we
@@ -38,6 +39,12 @@ val testJavaVersion = typedProp<String>("test.java.version")?.let {
3839
}
3940

4041
allprojects {
42+
tasks.withType<KotlinCompile> {
43+
compilerOptions {
44+
allWarningsAsErrors = true
45+
}
46+
}
47+
4148
if (testJavaVersion != null) {
4249
tasks.withType<Test> {
4350
val toolchains = project.extensions.getByType<JavaToolchainService>()

codegen/aws-sdk-codegen/src/main/kotlin/aws/sdk/kotlin/codegen/ServiceClientCompanionObjectWriter.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,6 @@ internal fun String.toEndpointUrlConfigNames(): EndpointUrlConfigNames = Endpoin
7373
// for our client names
7474
// e.g. sdkId "Elasticsearch Service" -> client name "ElasticsearchClient", prop "aws.endpointUrlElasticsearch"
7575
private object JvmSystemPropertySuffix : StringTransformer {
76-
override fun transform(id: String): String =
77-
id.toPascalCase().removeSuffix("Service")
76+
override fun transform(input: String): String =
77+
input.toPascalCase().removeSuffix("Service")
7878
}

hll/build.gradle.kts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ subprojects {
7070
optinAnnotations.forEach(languageSettings::optIn)
7171
}
7272

73+
named("commonMain") {
74+
dependencies {
75+
api(project(":aws-runtime:aws-core")) // for InternalSdkApi annotation
76+
}
77+
}
78+
7379
named("commonTest") {
7480
dependencies {
7581
implementation(libraries.kotest.assertions.core)

services/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ subprojects {
129129

130130
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
131131
compilerOptions {
132+
allWarningsAsErrors.set(false) // FIXME Tons of errors occur in generated code. Can we work around errors from deprecated service fields / APIs?
132133
jvmTarget.set(JvmTarget.JVM_1_8) // fixes outgoing variant metadata: https://github.com/smithy-lang/smithy-kotlin/issues/258
133134
freeCompilerArgs.add("-Xjdk-release=1.8")
134135
}

0 commit comments

Comments
 (0)