4141import software .amazon .awssdk .regions .providers .DefaultAwsRegionProviderChain ;
4242import software .amazon .awssdk .services .dynamodb .DynamoDbClientBuilder ;
4343import software .amazon .awssdk .services .glue .GlueClientBuilder ;
44+ import software .amazon .awssdk .services .kms .KmsClientBuilder ;
4445import software .amazon .awssdk .services .kms .model .DataKeySpec ;
4546import software .amazon .awssdk .services .kms .model .EncryptionAlgorithmSpec ;
4647
@@ -208,6 +209,14 @@ public class AwsProperties implements Serializable {
208209 */
209210 public static final String REST_SESSION_TOKEN = "rest.session-token" ;
210211
212+ /**
213+ * Configure an alternative endpoint of the KMS service for AwsKeyManagementClient to access.
214+ *
215+ * <p>This could be used to use KMS key management with any KMS-compatible service that has a
216+ * different endpoint
217+ */
218+ public static final String KMS_ENDPOINT = "kms.endpoint" ;
219+
211220 /** Encryption algorithm used to encrypt/decrypt master table keys */
212221 public static final String KMS_ENCRYPTION_ALGORITHM_SPEC = "kms.encryption-algorithm-spec" ;
213222
@@ -243,6 +252,7 @@ public class AwsProperties implements Serializable {
243252 private String restAccessKeyId ;
244253 private String restSecretAccessKey ;
245254 private String restSessionToken ;
255+ private final String kmsEndpoint ;
246256 private EncryptionAlgorithmSpec kmsEncryptionAlgorithmSpec ;
247257 private DataKeySpec kmsDataKeySpec ;
248258
@@ -268,6 +278,7 @@ public AwsProperties() {
268278
269279 this .restSigningName = REST_SIGNING_NAME_DEFAULT ;
270280
281+ this .kmsEndpoint = null ;
271282 this .kmsEncryptionAlgorithmSpec = KMS_ENCRYPTION_ALGORITHM_SPEC_DEFAULT ;
272283 this .kmsDataKeySpec = KMS_DATA_KEY_SPEC_DEFAULT ;
273284 }
@@ -312,6 +323,7 @@ public AwsProperties(Map<String, String> properties) {
312323 this .restSecretAccessKey = properties .get (REST_SECRET_ACCESS_KEY );
313324 this .restSessionToken = properties .get (REST_SESSION_TOKEN );
314325
326+ this .kmsEndpoint = properties .get (KMS_ENDPOINT );
315327 this .kmsEncryptionAlgorithmSpec =
316328 EncryptionAlgorithmSpec .fromValue (
317329 properties .getOrDefault (
@@ -411,6 +423,19 @@ public <T extends DynamoDbClientBuilder> void applyDynamoDbEndpointConfiguration
411423 configureEndpoint (builder , dynamoDbEndpoint );
412424 }
413425
426+ /**
427+ * Override the endpoint for a KMS client.
428+ *
429+ * <p>Sample usage:
430+ *
431+ * <pre>
432+ * KmsClient.builder().applyMutation(awsProperties::applyKmsEndpointConfigurations)
433+ * </pre>
434+ */
435+ public <T extends KmsClientBuilder > void applyKmsEndpointConfigurations (T builder ) {
436+ configureEndpoint (builder , kmsEndpoint );
437+ }
438+
414439 public Region restSigningRegion () {
415440 if (restSigningRegion == null ) {
416441 this .restSigningRegion = DefaultAwsRegionProviderChain .builder ().build ().getRegion ().id ();
@@ -428,6 +453,10 @@ public AwsCredentialsProvider restCredentialsProvider() {
428453 this .restAccessKeyId , this .restSecretAccessKey , this .restSessionToken );
429454 }
430455
456+ public String kmsEndpoint () {
457+ return this .kmsEndpoint ;
458+ }
459+
431460 public EncryptionAlgorithmSpec kmsEncryptionAlgorithmSpec () {
432461 return this .kmsEncryptionAlgorithmSpec ;
433462 }
0 commit comments