Skip to content

Commit

Permalink
Source sdk-partitions from the models instead of hardcoding
Browse files Browse the repository at this point in the history
1. Update `sync-models` to sync from aws-sdk-rust. This location includes `sdk-partitions.json`
2. Update aws:sdk gradle file to properly set this variable in codegen./
3. Add an additional safeguard to ensure that the default hardcoded version is only used in tests and adhoc SDK generation.
  • Loading branch information
rcoh committed Dec 11, 2023
1 parent 093e9a2 commit ee8ed55
Show file tree
Hide file tree
Showing 21 changed files with 13,708 additions and 6,262 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,14 @@ class SdkSettings private constructor(private val awsSdk: ObjectNode?) {
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 productionSdkBuild: Boolean
get() = awsSdk?.getBooleanMember("productionSdkBuild")?.orNull()?.value ?: false

/** Path to AWS SDK integration tests */
val integrationTestPath: String
get() =
Expand Down
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 @@ -30,10 +31,15 @@ class AwsEndpointsStdLib() : ClientCodegenDecorator {
private fun partitionMetadata(sdkSettings: SdkSettings): ObjectNode {
if (partitionsCache == null) {
val partitionsJson = when (val path = sdkSettings.partitionsConfigPath) {
null -> (
javaClass.getResource("/default-partitions.json")
?: throw IllegalStateException("Failed to find default-partitions.json in the JAR")
).readText()
null -> {
if (sdkSettings.productionSdkBuild) {
PANIC("cannot use hardcoded partitions in AWS SDK production 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.

2 changes: 1 addition & 1 deletion aws/sdk/aws-models/bedrock-runtime.json
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@
"min": 1,
"max": 2048
},
"smithy.api#pattern": "^(arn:aws(-[^:]+)?:bedrock:[a-z0-9-]{1,20}:(([0-9]{12}:custom-model/[a-z0-9-]{1,63}[.]{1}[a-z0-9-]{1,63}/[a-z0-9]{12})|(:foundation-model/[a-z0-9-]{1,63}[.]{1}[a-z0-9-]{1,63}([.]?[a-z0-9-]{1,63}))|([0-9]{12}:provisioned-model/[a-z0-9]{12})))|([a-z0-9-]{1,63}[.]{1}[a-z0-9-]{1,63}([.]?[a-z0-9-]{1,63}))|(([0-9a-zA-Z][_-]?)+)$"
"smithy.api#pattern": "^(arn:aws(-[^:]+)?:bedrock:[a-z0-9-]{1,20}:(([0-9]{12}:custom-model/[a-z0-9-]{1,63}[.]{1}[a-z0-9-]{1,63}/[a-z0-9]{12})|(:foundation-model/[a-z0-9-]{1,63}[.]{1}[a-z0-9-]{1,63}([.:]?[a-z0-9-]{1,63}))|([0-9]{12}:provisioned-model/[a-z0-9]{12})))|([a-z0-9-]{1,63}[.]{1}[a-z0-9-]{1,63}([.:]?[a-z0-9-]{1,63}))|(([0-9a-zA-Z][_-]?)+)$"
}
},
"com.amazonaws.bedrockruntime#InvokeModelRequest": {
Expand Down
102 changes: 102 additions & 0 deletions aws/sdk/aws-models/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -13782,6 +13782,108 @@
"traits": {
"smithy.api#enumValue": "AWS::Batch::SchedulingPolicy"
}
},
"ACMPCACertificateAuthorityActivation": {
"target": "smithy.api#Unit",
"traits": {
"smithy.api#enumValue": "AWS::ACMPCA::CertificateAuthorityActivation"
}
},
"AppMeshGatewayRoute": {
"target": "smithy.api#Unit",
"traits": {
"smithy.api#enumValue": "AWS::AppMesh::GatewayRoute"
}
},
"AppMeshMesh": {
"target": "smithy.api#Unit",
"traits": {
"smithy.api#enumValue": "AWS::AppMesh::Mesh"
}
},
"ConnectInstance": {
"target": "smithy.api#Unit",
"traits": {
"smithy.api#enumValue": "AWS::Connect::Instance"
}
},
"ConnectQuickConnect": {
"target": "smithy.api#Unit",
"traits": {
"smithy.api#enumValue": "AWS::Connect::QuickConnect"
}
},
"EC2CarrierGateway": {
"target": "smithy.api#Unit",
"traits": {
"smithy.api#enumValue": "AWS::EC2::CarrierGateway"
}
},
"EC2IPAMPool": {
"target": "smithy.api#Unit",
"traits": {
"smithy.api#enumValue": "AWS::EC2::IPAMPool"
}
},
"EC2TransitGatewayConnect": {
"target": "smithy.api#Unit",
"traits": {
"smithy.api#enumValue": "AWS::EC2::TransitGatewayConnect"
}
},
"EC2TransitGatewayMulticastDomain": {
"target": "smithy.api#Unit",
"traits": {
"smithy.api#enumValue": "AWS::EC2::TransitGatewayMulticastDomain"
}
},
"ECSCapacityProvider": {
"target": "smithy.api#Unit",
"traits": {
"smithy.api#enumValue": "AWS::ECS::CapacityProvider"
}
},
"IAMInstanceProfile": {
"target": "smithy.api#Unit",
"traits": {
"smithy.api#enumValue": "AWS::IAM::InstanceProfile"
}
},
"IoTCACertificate": {
"target": "smithy.api#Unit",
"traits": {
"smithy.api#enumValue": "AWS::IoT::CACertificate"
}
},
"IoTTwinMakerSyncJob": {
"target": "smithy.api#Unit",
"traits": {
"smithy.api#enumValue": "AWS::IoTTwinMaker::SyncJob"
}
},
"KafkaConnectConnector": {
"target": "smithy.api#Unit",
"traits": {
"smithy.api#enumValue": "AWS::KafkaConnect::Connector"
}
},
"LambdaCodeSigningConfig": {
"target": "smithy.api#Unit",
"traits": {
"smithy.api#enumValue": "AWS::Lambda::CodeSigningConfig"
}
},
"NetworkManagerConnectPeer": {
"target": "smithy.api#Unit",
"traits": {
"smithy.api#enumValue": "AWS::NetworkManager::ConnectPeer"
}
},
"ResourceExplorer2Index": {
"target": "smithy.api#Unit",
"traits": {
"smithy.api#enumValue": "AWS::ResourceExplorer2::Index"
}
}
}
},
Expand Down
Loading

0 comments on commit ee8ed55

Please sign in to comment.