Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

misc: upgrade to ktlint v1.3.0 #1340

Merged
merged 8 commits into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/dc908f70-28c1-4d4a-ab8e-b50ea00172af.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"id": "dc908f70-28c1-4d4a-ab8e-b50ea00172af",
"type": "misc",
"description": "Upgrade to ktlint v1.3.0"
}
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
[*.{kt,kts}]
ktlint_code_style = intellij_idea

# ktlint rules to disable
ktlint_standard_no-wildcard-imports = disabled
ktlint_standard_filename = disabled
ktlint_standard_backing-property-naming = disabled

# enable trailing commas per JetBrains recommendation
# (https://kotlinlang.org/docs/coding-conventions.html#trailing-commas)
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ local.properties
services/*/generated-src
services/*/build.gradle.kts
.kotest/
*.klib
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ import aws.sdk.kotlin.runtime.ConfigurationException
/**
* No credentials were available from this [CredentialsProvider]
*/
public class CredentialsNotLoadedException(message: String?, cause: Throwable? = null) :
ClientException(message ?: "The provider could not provide credentials or required configuration was not set", cause)
public class CredentialsNotLoadedException(message: String?, cause: Throwable? = null) : ClientException(message ?: "The provider could not provide credentials or required configuration was not set", cause)

/**
* The [CredentialsProvider] was given an invalid configuration (e.g. invalid aws configuration file, invalid IMDS endpoint, etc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ internal sealed class JsonCredentialsResponse {
* }
* ```
*/
@Suppress("ktlint:standard:property-naming")
internal suspend fun deserializeJsonCredentials(deserializer: Deserializer): JsonCredentialsResponse {
val CODE_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("Code"))
val ACCESS_KEY_ID_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("AccessKeyId"))
Expand Down Expand Up @@ -140,6 +141,7 @@ internal suspend fun deserializeJsonCredentials(deserializer: Deserializer): Jso
* The difference between this and [deserializeJsonCredentials] is that process credentials _must_ provide a version field,
* the session token field is called `SessionToken` instead of `Token`, and the expiration field is optional.
*/
@Suppress("ktlint:standard:property-naming")
internal fun deserializeJsonProcessCredentials(deserializer: Deserializer): JsonCredentialsResponse {
val ACCESS_KEY_ID_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("AccessKeyId"))
val SECRET_ACCESS_KEY_ID_DESCRIPTOR = SdkFieldDescriptor(SerialKind.String, JsonSerialName("SecretAccessKey"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,7 @@ public class SsoTokenProvider(
}
}

private fun throwTokenExpired(cause: Throwable? = null): Nothing {
throw InvalidSsoTokenException("SSO token for sso-session: $ssoSessionName is expired", cause)
}
private fun throwTokenExpired(cause: Throwable? = null): Nothing = throw InvalidSsoTokenException("SSO token for sso-session: $ssoSessionName is expired", cause)

private suspend fun refreshToken(oldToken: SsoToken): SsoToken {
val telemetry = coroutineContext.telemetryProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,12 @@ public class AssumeRoleParameters(
public val sourceIdentity: String? = null,
) {
internal val convertedPolicyArns = policyArns?.map { PolicyDescriptorType { arn = it } }
internal val convertedTags = tags?.map { Tag { key = it.key; value = it.value } }
internal val convertedTags = tags?.map {
Tag {
key = it.key
value = it.value
}
}
}

// role session name must be provided to assume a role, when the user doesn't provide one we choose a name for them
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import aws.smithy.kotlin.runtime.io.SdkManagedCloseable

private class ManagedTokenProvider(
private val delegate: CloseableBearerTokenProvider,
) : SdkManagedCloseable(delegate), CloseableBearerTokenProvider by delegate
) : SdkManagedCloseable(delegate),
CloseableBearerTokenProvider by delegate

/**
* Wraps a [TokenProvider] for internal runtime management by the SDK.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import aws.smithy.kotlin.runtime.io.SdkManagedCloseable

private class ManagedCredentialsProvider(
private val delegate: CloseableCredentialsProvider,
) : SdkManagedCloseable(delegate), CloseableCredentialsProvider by delegate
) : SdkManagedCloseable(delegate),
CloseableCredentialsProvider by delegate

/**
* Wraps a [CredentialsProvider] for internal runtime management by the SDK.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public sealed class AwsConfigValue {

@InternalSdkApi
public data class Map(public val value: kotlin.collections.Map<kotlin.String, kotlin.String>) :
AwsConfigValue(), kotlin.collections.Map<kotlin.String, kotlin.String> by value {
AwsConfigValue(),
kotlin.collections.Map<kotlin.String, kotlin.String> by value {
override fun toString(): kotlin.String = value.toString()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ internal object Literals {
const val PROPERTY_SPLITTER = '='
}

internal const val helpText = "See https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html for file format details."
internal const val HELP_TEXT = "See https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html for file format details."

internal fun contextMessage(message: String, lineNumber: Int? = null): String = buildString {
append(message)
lineNumber?.let { append(" on line $lineNumber.") }
append(" $helpText")
append(" $HELP_TEXT")
}

// what constitutes a "valid" profile/property identifier is not explicitly stated in the SEP (nor is it consistent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public suspend fun resolveRetryStrategy(

return factory {
maxAttempts?.let {
if (it < 1) { throw ConfigurationException("max attempts was $it, but should be at least 1") }
if (it < 1) {
throw ConfigurationException("max attempts was $it, but should be at least 1")
}
this.maxAttempts = it
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ public expect class DefaultRegionProviderChain constructor(
platformProvider: PlatformProvider = PlatformProvider.System,
imdsClient: Lazy<InstanceMetadataProvider> = lazy { ImdsClient() },
profile: LazyAsyncValue<AwsProfile> = asyncLazy { loadAwsSharedConfig(platformProvider).activeProfile },
) : RegionProvider, Closeable
) : RegionProvider,
Closeable
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ private const val REGION_PATH: String = "/latest/meta-data/placement/region"
public class ImdsRegionProvider(
private val client: Lazy<InstanceMetadataProvider> = lazy { ImdsClient() },
private val platformProvider: PlatformEnvironProvider = PlatformProvider.System,
) : RegionProvider, Closeable {
) : RegionProvider,
Closeable {
private val resolvedRegion = asyncLazy(::loadRegion)

override suspend fun getRegion(): String? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class SsoTokenProviderTest {
@Test
fun testCacheLoadingAndRefreshTestSuite() = runTest {
// these tests are from the SEP
val testList = Json.parseToJsonElement(ssoTokenCacheBehaviorTestSuite).jsonObject["cases"]!!.jsonArray
val testList = Json.parseToJsonElement(SSO_TOKEN_CACHE_BEHAVIOR_TEST_SUITE).jsonObject["cases"]!!.jsonArray

testList.map { testCase ->
runCatching {
Expand Down Expand Up @@ -123,7 +123,7 @@ class SsoTokenProviderTest {
}

// language=JSON
private const val ssoTokenCacheBehaviorTestSuite = """
private const val SSO_TOKEN_CACHE_BEHAVIOR_TEST_SUITE = """
{
"cases": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class ImdsClientTest {

@Test
fun testConfig() = runTest {
val tests = Json.parseToJsonElement(imdsTestSuite).jsonObject["tests"]!!.jsonArray.map { ImdsConfigTest.fromJson(it.jsonObject) }
val tests = Json.parseToJsonElement(IMDS_TEST_SUITE).jsonObject["tests"]!!.jsonArray.map { ImdsConfigTest.fromJson(it.jsonObject) }
tests.forEach { test ->
val result = runCatching { check(test) }
when {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package aws.sdk.kotlin.runtime.config.imds

// language=JSON
internal const val imdsTestSuite = """
internal const val IMDS_TEST_SUITE = """
{
"tests": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package aws.sdk.kotlin.runtime.config.profile
* This test suite exercises the parser and continuation merger.
*/
// language=JSON
internal const val parserTestSuiteJson = """
internal const val PARSER_TEST_SUITE_JSON = """
{
"description": [
"These are test descriptions that describe how to convert a raw configuration and credentials file into an ",
Expand Down Expand Up @@ -843,7 +843,7 @@ internal const val parserTestSuiteJson = """
"""

// language=JSON
internal const val loaderTestSuiteJson = """
internal const val LOADER_TEST_SUITE_JSON = """
{
"description": [
"These are test descriptions that specify which files and profiles should be loaded based on the specified environment ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class DefaultRegionProviderChainTest {

@Test
fun testSuite() = runTest {
val tests = Json.parseToJsonElement(regionProviderChainTestSuite).jsonArray
val tests = Json.parseToJsonElement(REGION_PROVIDER_CHAIN_TEST_SUITE).jsonArray
.map { it.jsonObject }
.map {
val name = it["name"]!!.jsonPrimitive.content
Expand Down Expand Up @@ -77,7 +77,7 @@ fun TestInstanceMetadataProvider.Companion.fromJsonNode(obj: JsonObject): TestIn
}

// language=JSON
private const val regionProviderChainTestSuite = """
private const val REGION_PROVIDER_CHAIN_TEST_SUITE = """
[
{
"name": "no region configured",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ public actual class DefaultRegionProviderChain actual constructor(
platformProvider: PlatformProvider,
imdsClient: Lazy<InstanceMetadataProvider>,
profile: LazyAsyncValue<AwsProfile>,
) : RegionProvider,
Closeable,
RegionProviderChain(
JvmSystemPropRegionProvider(platformProvider),
EnvironmentRegionProvider(platformProvider),
ProfileRegionProvider(profile),
ImdsRegionProvider(client = imdsClient, platformProvider = platformProvider),
) {
) : RegionProviderChain(
JvmSystemPropRegionProvider(platformProvider),
EnvironmentRegionProvider(platformProvider),
ProfileRegionProvider(profile),
ImdsRegionProvider(client = imdsClient, platformProvider = platformProvider),
),
RegionProvider,
Closeable {

override fun close() {
providers.forEach { provider ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class DefaultChainCredentialsProviderTest {
private val env: Map<String, String>,
private val systemProperties: Map<String, String>,
private val fs: Filesystem,
) : PlatformProvider, Filesystem by fs {
) : PlatformProvider,
Filesystem by fs {
override fun osInfo(): OperatingSystem = OperatingSystem(OsFamily.Linux, "test")
override val isJvm: Boolean = true
override val isAndroid: Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,10 @@ private interface TestClient : SdkClient {
override fun newClient(config: Config): TestClient = DefaultTestClient(config)
}

class Config private constructor(builder: Builder) : SdkClientConfig, AwsSdkClientConfig, RetryStrategyClientConfig by builder.buildRetryStrategyClientConfig() {
class Config private constructor(builder: Builder) :
SdkClientConfig,
AwsSdkClientConfig,
RetryStrategyClientConfig by builder.buildRetryStrategyClientConfig() {
override val clientName: String = builder.clientName
override val logMode: LogMode = builder.logMode ?: LogMode.Default
override val region: String? = builder.region
Expand All @@ -131,7 +134,10 @@ private interface TestClient : SdkClient {
override val applicationId: String? = builder.applicationId

// new: inherits builder equivalents for Config base classes
class Builder : AwsSdkClientConfig.Builder, SdkClientConfig.Builder<Config>, RetryStrategyClientConfig.Builder by RetryStrategyClientConfigImpl.BuilderImpl() {
class Builder :
AwsSdkClientConfig.Builder,
SdkClientConfig.Builder<Config>,
RetryStrategyClientConfig.Builder by RetryStrategyClientConfigImpl.BuilderImpl() {
override var clientName: String = "Test"
override var logMode: LogMode? = LogMode.Default
override var region: String? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class AwsConfigLoaderTest {

@Test
fun canPassTestSuite() {
val testCases = Json.parseToJsonElement(loaderTestSuiteJson).jsonObject["tests"]!!.jsonArray
val testCases = Json.parseToJsonElement(LOADER_TEST_SUITE_JSON).jsonObject["tests"]!!.jsonArray

testCases
.map { TestCase.fromJson(it.jsonObject) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class AwsProfileParserTest {

@Test
fun canPassTestSuite() {
val testList = Json.parseToJsonElement(parserTestSuiteJson).jsonObject["tests"]!!.jsonArray
val testList = Json.parseToJsonElement(PARSER_TEST_SUITE_JSON).jsonObject["tests"]!!.jsonArray

testList
.map { TestCase.fromJson(it.jsonObject) }
Expand Down Expand Up @@ -107,14 +107,11 @@ class AwsProfileParserTest {
}
}

data class MatchConfigOutputCase(override val name: String, val configInput: String, val expectedOutput: String) :
TestCase()
data class MatchConfigOutputCase(override val name: String, val configInput: String, val expectedOutput: String) : TestCase()

data class MatchCredentialOutputCase(override val name: String, val credentialInput: String, val expectedOutput: String) :
TestCase()
data class MatchCredentialOutputCase(override val name: String, val credentialInput: String, val expectedOutput: String) : TestCase()

data class MatchConfigAndCredentialOutputCase(override val name: String, val configInput: String, val credentialInput: String, val expectedOutput: String) :
TestCase()
data class MatchConfigAndCredentialOutputCase(override val name: String, val configInput: String, val credentialInput: String, val expectedOutput: String) : TestCase()

data class MatchErrorCase(
override val name: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public actual class DefaultRegionProviderChain actual constructor(
platformProvider: PlatformProvider,
imdsClient: Lazy<InstanceMetadataProvider>,
profile: LazyAsyncValue<AwsProfile>,
) : RegionProvider, Closeable {
) : RegionProvider,
Closeable {
override suspend fun getRegion(): String? {
TODO("Not yet implemented")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ public data class AwsUserAgentMetadata(
language-metadata RWS
[env-metadata RWS]
; ordering is not strictly required in the following section
*(config-metadata RWS)
*(config-metadata RWS)
[appId]
*(feat-metadata RWS)
*(framework-metadata RWS)
*(feat-metadata RWS)
*(framework-metadata RWS)
*/
get() = buildList {
add(sdkMetadata)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ import software.amazon.smithy.model.shapes.OperationShape
import software.amazon.smithy.model.shapes.ServiceShape
import software.amazon.smithy.model.traits.HttpTrait

private const val continueProp = "continueHeaderThresholdBytes"
private const val CONTINUE_PROP = "continueHeaderThresholdBytes"

private val enableContinueProp = ConfigProperty {
name = continueProp
name = CONTINUE_PROP
symbol = KotlinTypes.Long.asNullable()
documentation = """
The minimum content length threshold (in bytes) for which to send `Expect: 100-continue` HTTP headers. PUT
Expand All @@ -37,11 +37,11 @@ private val enableContinueProp = ConfigProperty {
// Need a custom property type because property is nullable but has a non-null default
propertyType = ConfigPropertyType.Custom(
render = { _, writer ->
writer.write("public val $continueProp: Long? = builder.$continueProp")
writer.write("public val $CONTINUE_PROP: Long? = builder.$CONTINUE_PROP")
},
renderBuilder = { prop, writer ->
prop.documentation?.let(writer::dokka)
writer.write("public var $continueProp: Long? = 2 * 1024 * 1024 // 2MB")
writer.write("public var $CONTINUE_PROP: Long? = 2 * 1024 * 1024 // 2MB")
},
)
}
Expand All @@ -67,7 +67,7 @@ internal object ContinueMiddleware : ProtocolMiddleware {
op.getTrait<HttpTrait>()?.method == "PUT"

override fun render(ctx: ProtocolGenerator.GenerationContext, op: OperationShape, writer: KotlinWriter) {
writer.withBlock("config.$continueProp?.let { threshold ->", "}") {
writer.withBlock("config.$CONTINUE_PROP?.let { threshold ->", "}") {
writer.write("op.interceptors.add(#T(threshold))", RuntimeTypes.HttpClient.Interceptors.ContinueInterceptor)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ class HostPrefixRequestRouteFilter : KotlinIntegration {
override fun preprocessModel(model: Model, settings: KotlinSettings): Model {
val transformer = ModelTransformer.create()
return transformer.removeTraitsIf(model) { _, trait ->
trait is EndpointTrait && trait.hostPrefix.labels.any {
it.isLabel && it.content == "RequestRoute"
}
trait is EndpointTrait &&
trait.hostPrefix.labels.any {
it.isLabel && it.content == "RequestRoute"
}
}
}
}
Loading
Loading