Skip to content

Commit

Permalink
Source sdk-partitions from the models instead of hardcoding (#3292)
Browse files Browse the repository at this point in the history
  • Loading branch information
aws-sdk-rust-ci authored Dec 20, 2023
2 parents f84f9ba + fc3ba64 commit cfd8942
Show file tree
Hide file tree
Showing 29 changed files with 13,842 additions and 6,357 deletions.
64 changes: 32 additions & 32 deletions .github/workflows/credentials-verification.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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!"}'
6 changes: 6 additions & 0 deletions CHANGELOG.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ references = ["smithy-rs#3252", "smithy-rs#3312"]
meta = { "breaking" = false, "tada" = false, "bug" = true }
author = "milesziemer"

[[smithy-rs]]
message = """`requireEndpointResolver: false` is no longer required to remove the need for an endpoint resolver. Instead, `"awsSdkBuilder"` (default false), now _removes_ that requirement."""
references = ["smithy-rs#3292"]
meta = { "breaking" = false, "tada" = false, "bug" = false }
author = "rcoh"

[[aws-sdk-rust]]
message = "Fix bug in `CredentialsProcess` provider where `expiry` was incorrectly treated as a required field."
references = ["smithy-rs#3335", "aws-sdk-rust#1021"]
Expand Down
2 changes: 1 addition & 1 deletion aws/SDK_CHANGELOG.next.json
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,4 @@
}
],
"aws-sdk-model": []
}
}
8 changes: 0 additions & 8 deletions aws/sdk-adhoc-test/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@ fun baseTest(service: String, module: String, imports: List<String> = listOf()):
"includeFluentClient": false,
"nullabilityCheckMode": "${getNullabilityCheckMode()}"
""",
extraConfig = """
, "customizationConfig": {
"awsSdk": {
"generateReadme": false,
"requireEndpointResolver": false
}
}
""",
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,87 @@ import software.amazon.smithy.rust.codegen.core.smithy.CoreRustSettings
import software.amazon.smithy.rust.codegen.core.util.orNull
import java.nio.file.Path
import java.nio.file.Paths
import java.util.logging.Logger

/**
* SDK-specific settings within the Rust codegen `customizationConfig.awsSdk` object.
*/
class SdkSettings private constructor(private val awsSdk: ObjectNode?) {
private fun warnOnUnusedProperties() {
if (awsSdk == null) {
return
}
val logger = Logger.getLogger("SdkSettings")
if (awsSdk.getMember("generateReadme").isPresent) {
logger.warning(
"`generateReadme` parameter is now ignored. Readmes are now only generated when " +
"`awsSdkBuild` is set to `true`. You can use `suppressReadme` to explicitly suppress the readme in that case.",
)
}

if (awsSdk.getMember("requireEndpointResolver").isPresent) {
logger.warning(
"`requireEndpointResolver` is no a no-op and you may remove it from your configuration. " +
"An endpoint resolver is only required when `awsSdkBuild` is set to true.",
)
}
}

companion object {
fun from(coreRustSettings: CoreRustSettings): SdkSettings =
SdkSettings(coreRustSettings.customizationConfig?.getObjectMember("awsSdk")?.orNull())
fun from(coreRustSettings: CoreRustSettings): SdkSettings {
val settings = SdkSettings(coreRustSettings.customizationConfig?.getObjectMember("awsSdk")?.orNull())
if (shouldPrintWarning()) {
settings.warnOnUnusedProperties()
warningPrinted()
}
return settings
}

@Volatile
var warningPrinted = false

private fun warningPrinted() {
synchronized(this) {
this.warningPrinted = true
}
}

private fun shouldPrintWarning(): Boolean {
synchronized(this) {
return !this.warningPrinted
}
}
}

/** Path to the `sdk-default-configuration.json` config file */
val defaultsConfigPath: Path?
get() =
awsSdk?.getStringMember("defaultConfigPath")?.orNull()?.value.let { Paths.get(it) }

/** Path to the `sdk-endpoints.json` configuration */
val endpointsConfigPath: Path?
get() =
awsSdk?.getStringMember("endpointsConfigPath")?.orNull()?.value?.let { Paths.get(it) }

/** Path to the `default-partitions.json` configuration */
val partitionsConfigPath: Path?
get() =
awsSdk?.getStringMember("partitionsConfigPath")?.orNull()?.value?.let { Paths.get(it) }

val awsSdkBuild: Boolean
get() = awsSdk?.getBooleanMember("awsSdkBuild")?.orNull()?.value ?: false

/** Path to AWS SDK integration tests */
val integrationTestPath: String
get() =
awsSdk?.getStringMember("integrationTestPath")?.orNull()?.value ?: "aws/sdk/integration-tests"

/** Version number of the `aws-config` crate */
/** Version number of the `aws-config` crate. This is used to set the dev-dependency when generating readme's */
val awsConfigVersion: String?
get() =
awsSdk?.getStringMember("awsConfigVersion")?.orNull()?.value

/** Whether to generate a README */
val generateReadme: Boolean
get() =
awsSdk?.getBooleanMember("generateReadme")?.orNull()?.value ?: false
get() = awsSdkBuild && !(awsSdk?.getBooleanMember("suppressReadme")?.orNull()?.value ?: false)

val requireEndpointResolver: Boolean
get() = awsSdk?.getBooleanMember("requireEndpointResolver")?.orNull()?.value ?: true
get() = awsSdkBuild
}

fun ClientCodegenContext.sdkSettings() = SdkSettings.from(this.settings)
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegen
import software.amazon.smithy.rust.codegen.client.smithy.endpoint.EndpointCustomization
import software.amazon.smithy.rust.codegen.client.smithy.endpoint.generators.CustomRuntimeFunction
import software.amazon.smithy.rust.codegen.client.smithy.endpoint.rulesgen.awsStandardLib
import software.amazon.smithy.rust.codegen.core.util.PANIC
import software.amazon.smithy.rustsdk.SdkSettings
import kotlin.io.path.readText

Expand All @@ -31,11 +32,15 @@ class AwsEndpointsStdLib() : ClientCodegenDecorator {
if (partitionsCache == null) {
val partitionsJson =
when (val path = sdkSettings.partitionsConfigPath) {
null ->
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()
}
Expand Down
105 changes: 0 additions & 105 deletions aws/sdk-codegen/src/main/resources/default-partitions.json

This file was deleted.

1 change: 1 addition & 0 deletions aws/sdk-codegen/src/main/resources/default-partitions.json
44 changes: 0 additions & 44 deletions aws/sdk-codegen/src/main/resources/default-sdk-endpoints.json

This file was deleted.

Loading

0 comments on commit cfd8942

Please sign in to comment.