From 7093ea60e7428130f8dff9484ee956a3016e45c1 Mon Sep 17 00:00:00 2001 From: Russell Cohen Date: Wed, 20 Dec 2023 10:38:49 -0500 Subject: [PATCH] Various missing precommit updates --- .../workflows/credentials-verification.yml | 64 +++++++++--------- aws/SDK_CHANGELOG.next.json | 2 +- .../amazon/smithy/rustsdk/SdkSettings.kt | 1 + .../rustsdk/endpoints/AwsEndpointsStdLib.kt | 23 +++---- .../amazon/smithy/rustsdk/TestUtil.kt | 57 ++++++++-------- .../generators/ServiceConfigGenerator.kt | 66 +++++++++---------- .../generators/ServiceConfigGeneratorTest.kt | 28 ++++---- 7 files changed, 122 insertions(+), 119 deletions(-) diff --git a/.github/workflows/credentials-verification.yml b/.github/workflows/credentials-verification.yml index 3b70e74fb..9d05a1508 100644 --- a/.github/workflows/credentials-verification.yml +++ b/.github/workflows/credentials-verification.yml @@ -2,7 +2,7 @@ name: Daily credentials verification on: schedule: # Runs 00:00 UTC every day - - cron: "0 0 * * *" + - cron: 0 0 * * * workflow_dispatch: jobs: @@ -11,41 +11,41 @@ jobs: name: Verify Crates.io Token runs-on: ubuntu-latest steps: - - name: Checkout smithy-rs - uses: actions/checkout@v3 - - name: Verify Crates.io Token - shell: bash - env: - RELEASE_AUTOMATION_BOT_CRATESIO_TOKEN: ${{ secrets.RELEASE_AUTOMATION_BOT_CRATESIO_TOKEN }} - run: | - cargo login -- "${RELEASE_AUTOMATION_BOT_CRATESIO_TOKEN}" - echo "Checking cargo auth token..." - # "cargo login" only saves a token and does not actually use it, so we use "cargo yank" to verify the token. - # This version has already been yanked, so it is safe to execute the command below repeatedly. - # This command succeeds if we have a token with permission to yank the crate. - cargo yank aws-sigv4 --version 0.55.0 - - name: Notify Slack on Failure - if: failure() - env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} - run: | - curl -X POST "${SLACK_WEBHOOK_URL}" -H 'Content-type: application/json' \ - --data '{"workflow_msg":"⚠️ Invalid crates.io token. Create a new token as soon as possible!"}' + - name: Checkout smithy-rs + uses: actions/checkout@v3 + - name: Verify Crates.io Token + shell: bash + env: + RELEASE_AUTOMATION_BOT_CRATESIO_TOKEN: ${{ secrets.RELEASE_AUTOMATION_BOT_CRATESIO_TOKEN }} + run: | + cargo login -- "${RELEASE_AUTOMATION_BOT_CRATESIO_TOKEN}" + echo "Checking cargo auth token..." + # "cargo login" only saves a token and does not actually use it, so we use "cargo yank" to verify the token. + # This version has already been yanked, so it is safe to execute the command below repeatedly. + # This command succeeds if we have a token with permission to yank the crate. + cargo yank aws-sigv4 --version 0.55.0 + - name: Notify Slack on Failure + if: failure() + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + run: | + curl -X POST "${SLACK_WEBHOOK_URL}" -H 'Content-type: application/json' \ + --data '{"workflow_msg":"⚠️ Invalid crates.io token. Create a new token as soon as possible!"}' # Verifies the token used to perform actions on the repository on behalf of the bot user verify-personal-access-token: name: Verify Personal Access Token runs-on: ubuntu-latest steps: - - name: Checkout smithy-rs + - name: Checkout smithy-rs # To test the validity of the personal access token, we only need to perform checkout with the specified token. - uses: actions/checkout@v3 - with: - token: ${{ secrets.RELEASE_AUTOMATION_BOT_PAT }} - - name: Notify Slack on Failure - if: failure() - env: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} - run: | - curl -X POST "${SLACK_WEBHOOK_URL}" -H 'Content-type: application/json' \ - --data '{"workflow_msg":"⚠️ Invalid GitHub personal access token. Create a new token as soon as possible!"}' + uses: actions/checkout@v3 + with: + token: ${{ secrets.RELEASE_AUTOMATION_BOT_PAT }} + - name: Notify Slack on Failure + if: failure() + env: + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + run: | + curl -X POST "${SLACK_WEBHOOK_URL}" -H 'Content-type: application/json' \ + --data '{"workflow_msg":"⚠️ Invalid GitHub personal access token. Create a new token as soon as possible!"}' diff --git a/aws/SDK_CHANGELOG.next.json b/aws/SDK_CHANGELOG.next.json index 89f683749..8e14e4d03 100644 --- a/aws/SDK_CHANGELOG.next.json +++ b/aws/SDK_CHANGELOG.next.json @@ -169,4 +169,4 @@ } ], "aws-sdk-model": [] -} \ No newline at end of file +} diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SdkSettings.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SdkSettings.kt index 859df771c..6623d6761 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SdkSettings.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/SdkSettings.kt @@ -35,6 +35,7 @@ class SdkSettings private constructor(private val awsSdk: ObjectNode?) { ) } } + companion object { fun from(coreRustSettings: CoreRustSettings): SdkSettings { val settings = SdkSettings(coreRustSettings.customizationConfig?.getObjectMember("awsSdk")?.orNull()) diff --git a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/endpoints/AwsEndpointsStdLib.kt b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/endpoints/AwsEndpointsStdLib.kt index 942381f52..f96e54102 100644 --- a/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/endpoints/AwsEndpointsStdLib.kt +++ b/aws/sdk-codegen/src/main/kotlin/software/amazon/smithy/rustsdk/endpoints/AwsEndpointsStdLib.kt @@ -30,19 +30,20 @@ class AwsEndpointsStdLib() : ClientCodegenDecorator { private fun partitionMetadata(sdkSettings: SdkSettings): ObjectNode { if (partitionsCache == null) { - val partitionsJson = when (val path = sdkSettings.partitionsConfigPath) { - null -> { - if (sdkSettings.awsSdkBuild) { - PANIC("cannot use hardcoded partitions in AWS SDK build") - } - ( - javaClass.getResource("/default-partitions.json") - ?: throw IllegalStateException("Failed to find default-partitions.json in the JAR") + val partitionsJson = + when (val path = sdkSettings.partitionsConfigPath) { + null -> { + if (sdkSettings.awsSdkBuild) { + PANIC("cannot use hardcoded partitions in AWS SDK build") + } + ( + javaClass.getResource("/default-partitions.json") + ?: throw IllegalStateException("Failed to find default-partitions.json in the JAR") ).readText() - } + } - else -> path.readText() - } + else -> path.readText() + } partitionsCache = Node.parse(partitionsJson).expectObjectNode() } return partitionsCache!! diff --git a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/TestUtil.kt b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/TestUtil.kt index d852ac043..0da78519c 100644 --- a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/TestUtil.kt +++ b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/TestUtil.kt @@ -43,34 +43,35 @@ fun awsSdkIntegrationTest( model: Model, params: IntegrationTestParams = awsIntegrationTestParams(), test: (ClientCodegenContext, RustCrate) -> Unit = { _, _ -> }, -) = - clientIntegrationTest( - model, - params, - test = test, - ) +) = clientIntegrationTest( + model, + params, + test = test, +) -fun awsIntegrationTestParams() = IntegrationTestParams( - cargoCommand = "cargo test --features test-util behavior-version-latest", - runtimeConfig = AwsTestRuntimeConfig, - additionalSettings = ObjectNode.builder().withMember( - "customizationConfig", - ObjectNode.builder() - .withMember( - "awsSdk", +fun awsIntegrationTestParams() = + IntegrationTestParams( + cargoCommand = "cargo test --features test-util behavior-version-latest", + runtimeConfig = AwsTestRuntimeConfig, + additionalSettings = + ObjectNode.builder().withMember( + "customizationConfig", ObjectNode.builder() - .withMember("awsSdkBuild", true) - .withMember("suppressReadme", true) - .withMember("integrationTestPath", "../sdk/integration-tests") - .withMember("partitionsConfigPath", "../sdk/aws-models/sdk-partitions.json") - .build(), - ).build(), + .withMember( + "awsSdk", + ObjectNode.builder() + .withMember("awsSdkBuild", true) + .withMember("suppressReadme", true) + .withMember("integrationTestPath", "../sdk/integration-tests") + .withMember("partitionsConfigPath", "../sdk/aws-models/sdk-partitions.json") + .build(), + ).build(), + ) + .withMember( + "codegen", + ObjectNode.builder() + .withMember("includeFluentClient", false) + .withMember("includeEndpointUrlConfig", false) + .build(), + ).build(), ) - .withMember( - "codegen", - ObjectNode.builder() - .withMember("includeFluentClient", false) - .withMember("includeEndpointUrlConfig", false) - .build(), - ).build(), -) diff --git a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServiceConfigGenerator.kt b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServiceConfigGenerator.kt index 56a662348..81bcbaaf4 100644 --- a/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServiceConfigGenerator.kt +++ b/codegen-server/src/main/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServiceConfigGenerator.kt @@ -303,10 +303,10 @@ class ServiceConfigGenerator( writable { rustTemplate( """ - if !self.${it.requiredBuilderFlagName()} { - return #{Err}(${serviceName}ConfigError::${it.requiredErrorVariant()}); - } - """, + if !self.${it.requiredBuilderFlagName()} { + return #{Err}(${serviceName}ConfigError::${it.requiredErrorVariant()}); + } + """, *codegenScope, ) } @@ -335,19 +335,19 @@ class ServiceConfigGenerator( writable { rust( """ - ##[error("service is not fully configured; invoke `${it.name}` on the config builder")] - ${it.requiredErrorVariant()}, - """, + ##[error("service is not fully configured; invoke `${it.name}` on the config builder")] + ${it.requiredErrorVariant()}, + """, ) } } rustTemplate( """ - ##[derive(Debug, #{ThisError}::Error)] - pub enum ${serviceName}ConfigError { - #{Variants:W} - } - """, + ##[derive(Debug, #{ThisError}::Error)] + pub enum ${serviceName}ConfigError { + #{Variants:W} + } + """, "ThisError" to ServerCargoDependency.ThisError.toType(), "Variants" to variants.join("\n"), ) @@ -406,12 +406,12 @@ class ServiceConfigGenerator( writable { rustTemplate( """ - ${serviceName}ConfigBuilder< - #{LayersReturnTy:W}, - #{HttpPluginsReturnTy:W}, - #{ModelPluginsReturnTy:W}, - > - """, + ${serviceName}ConfigBuilder< + #{LayersReturnTy:W}, + #{HttpPluginsReturnTy:W}, + #{ModelPluginsReturnTy:W}, + > + """, "LayersReturnTy" to layersReturnTy, "HttpPluginsReturnTy" to httpPluginsReturnTy, "ModelPluginsReturnTy" to modelPluginsReturnTy, @@ -435,12 +435,12 @@ class ServiceConfigGenerator( docs(it.docs) rustBlockTemplate( """ - pub fn ${it.name}#{ParamBindingsGenericsWritable}( - ##[allow(unused_mut)] - mut self, - #{ParamBindings:W} - ) -> #{ReturnTy:W} - """, + pub fn ${it.name}#{ParamBindingsGenericsWritable}( + ##[allow(unused_mut)] + mut self, + #{ParamBindings:W} + ) -> #{ReturnTy:W} + """, "ReturnTy" to returnTy, "ParamBindings" to paramBindings, "ParamBindingsGenericsWritable" to paramBindingsGenericsWritable, @@ -482,9 +482,9 @@ class ServiceConfigGenerator( writable { rustBlockTemplate( """ - /// Build the configuration. - pub fn build(self) -> #{BuilderBuildReturnTy:W} - """, + /// Build the configuration. + pub fn build(self) -> #{BuilderBuildReturnTy:W} + """, "BuilderBuildReturnTy" to builderBuildReturnType(), ) { rustTemplate( @@ -495,12 +495,12 @@ class ServiceConfigGenerator( conditionalBlock("Ok(", ")", isBuilderFallible) { rust( """ - super::${serviceName}Config { - layers: self.layers, - http_plugins: self.http_plugins, - model_plugins: self.model_plugins, - } - """, + super::${serviceName}Config { + layers: self.layers, + http_plugins: self.http_plugins, + model_plugins: self.model_plugins, + } + """, ) } } diff --git a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServiceConfigGeneratorTest.kt b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServiceConfigGeneratorTest.kt index a744e5379..fcb61ae53 100644 --- a/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServiceConfigGeneratorTest.kt +++ b/codegen-server/src/test/kotlin/software/amazon/smithy/rust/codegen/server/smithy/generators/ServiceConfigGeneratorTest.kt @@ -57,16 +57,16 @@ internal class ServiceConfigGeneratorTest { writable { rustTemplate( """ - if authorizer != 69 { - return Err(std::io::Error::new(std::io::ErrorKind::Other, "failure 1")); - } - - if auth_spec.len() != 69 && generic_list.len() != 69 { - return Err(std::io::Error::new(std::io::ErrorKind::Other, "failure 2")); - } - let authn_plugin = #{SmithyHttpServer}::plugin::IdentityPlugin; - let authz_plugin = #{SmithyHttpServer}::plugin::IdentityPlugin; - """, + if authorizer != 69 { + return Err(std::io::Error::new(std::io::ErrorKind::Other, "failure 1")); + } + + if auth_spec.len() != 69 && generic_list.len() != 69 { + return Err(std::io::Error::new(std::io::ErrorKind::Other, "failure 2")); + } + let authn_plugin = #{SmithyHttpServer}::plugin::IdentityPlugin; + let authz_plugin = #{SmithyHttpServer}::plugin::IdentityPlugin; + """, *codegenScope, ) }, @@ -186,10 +186,10 @@ internal class ServiceConfigGeneratorTest { writable { rustTemplate( """ - let layer1 = #{Identity}::new(); - let layer2 = #{Identity}::new(); - let layer3 = #{Identity}::new(); - """, + let layer1 = #{Identity}::new(); + let layer2 = #{Identity}::new(); + let layer3 = #{Identity}::new(); + """, *codegenScope, ) }, -- GitLab