From 47bfc7ee95c33178550b75cfd4a2dd36d3b806b6 Mon Sep 17 00:00:00 2001 From: Rico Huijbers Date: Mon, 4 Jul 2022 17:44:49 +0200 Subject: [PATCH] refactor: remove more duplicate enum values (#20982) This is a follow-up to #19320: there are more duplicate enum values that need to be removed, in anticipation of a jsii release that will make these duplicate values illegal. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../@aws-cdk/aws-secretsmanager/lib/secret.ts | 25 ++++++++++++++++--- .../aws-secretsmanager/test/secret.test.ts | 8 +++--- .../custom-resource-provider.ts | 16 ++++++++++-- 3 files changed, 40 insertions(+), 9 deletions(-) diff --git a/packages/@aws-cdk/aws-secretsmanager/lib/secret.ts b/packages/@aws-cdk/aws-secretsmanager/lib/secret.ts index 143607650d773..7865b29c2c4bd 100644 --- a/packages/@aws-cdk/aws-secretsmanager/lib/secret.ts +++ b/packages/@aws-cdk/aws-secretsmanager/lib/secret.ts @@ -684,7 +684,7 @@ export enum AttachmentTargetType { * * @deprecated use RDS_DB_INSTANCE instead */ - INSTANCE = 'AWS::RDS::DBInstance', + INSTANCE = 'deprecated_AWS::RDS::DBInstance', /** * AWS::RDS::DBCluster @@ -696,7 +696,7 @@ export enum AttachmentTargetType { * * @deprecated use RDS_DB_CLUSTER instead */ - CLUSTER = 'AWS::RDS::DBCluster', + CLUSTER = 'deprecated_AWS::RDS::DBCluster', /** * AWS::RDS::DBProxy @@ -797,7 +797,7 @@ export class SecretTargetAttachment extends SecretBase implements ISecretTargetA const attachment = new secretsmanager.CfnSecretTargetAttachment(this, 'Resource', { secretId: props.secret.secretArn, targetId: props.target.asSecretAttachmentTarget().targetId, - targetType: props.target.asSecretAttachmentTarget().targetType, + targetType: attachmentTargetTypeToString(props.target.asSecretAttachmentTarget().targetType), }); this.encryptionKey = props.secret.encryptionKey; @@ -950,3 +950,22 @@ Object.defineProperty(Secret.prototype, SECRET_SYMBOL, { enumerable: false, writable: false, }); + +function attachmentTargetTypeToString(x: AttachmentTargetType): string { + switch (x) { + case AttachmentTargetType.RDS_DB_INSTANCE: + case AttachmentTargetType.INSTANCE: + return 'AWS::RDS::DBInstance'; + case AttachmentTargetType.RDS_DB_CLUSTER: + case AttachmentTargetType.CLUSTER: + return 'AWS::RDS::DBCluster'; + case AttachmentTargetType.RDS_DB_PROXY: + return 'AWS::RDS::DBProxy'; + case AttachmentTargetType.REDSHIFT_CLUSTER: + return 'AWS::Redshift::Cluster'; + case AttachmentTargetType.DOCDB_DB_INSTANCE: + return 'AWS::DocDB::DBInstance'; + case AttachmentTargetType.DOCDB_DB_CLUSTER: + return 'AWS::DocDB::DBCluster'; + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-secretsmanager/test/secret.test.ts b/packages/@aws-cdk/aws-secretsmanager/test/secret.test.ts index 91935fdf59330..6caa06421d04e 100644 --- a/packages/@aws-cdk/aws-secretsmanager/test/secret.test.ts +++ b/packages/@aws-cdk/aws-secretsmanager/test/secret.test.ts @@ -1170,7 +1170,7 @@ test('can attach a secret with attach()', () => { secret.attach({ asSecretAttachmentTarget: () => ({ targetId: 'target-id', - targetType: 'target-type' as secretsmanager.AttachmentTargetType, + targetType: secretsmanager.AttachmentTargetType.DOCDB_DB_INSTANCE, }), }); @@ -1180,7 +1180,7 @@ test('can attach a secret with attach()', () => { Ref: 'SecretA720EF05', }, TargetId: 'target-id', - TargetType: 'target-type', + TargetType: 'AWS::DocDB::DBInstance', }); }); @@ -1190,7 +1190,7 @@ test('throws when trying to attach a target multiple times to a secret', () => { const target = { asSecretAttachmentTarget: () => ({ targetId: 'target-id', - targetType: 'target-type' as secretsmanager.AttachmentTargetType, + targetType: secretsmanager.AttachmentTargetType.DOCDB_DB_INSTANCE, }), }; secret.attach(target); @@ -1205,7 +1205,7 @@ test('add a rotation schedule to an attached secret', () => { const attachedSecret = secret.attach({ asSecretAttachmentTarget: () => ({ targetId: 'target-id', - targetType: 'target-type' as secretsmanager.AttachmentTargetType, + targetType: secretsmanager.AttachmentTargetType.DOCDB_DB_INSTANCE, }), }); const rotationLambda = new lambda.Function(stack, 'Lambda', { diff --git a/packages/@aws-cdk/core/lib/custom-resource-provider/custom-resource-provider.ts b/packages/@aws-cdk/core/lib/custom-resource-provider/custom-resource-provider.ts index ab61e98654131..4dea4938c819c 100644 --- a/packages/@aws-cdk/core/lib/custom-resource-provider/custom-resource-provider.ts +++ b/packages/@aws-cdk/core/lib/custom-resource-provider/custom-resource-provider.ts @@ -99,7 +99,7 @@ export enum CustomResourceProviderRuntime { * * @deprecated Use {@link NODEJS_14_X} */ - NODEJS_12 = 'nodejs12.x', + NODEJS_12 = 'deprecated_nodejs12.x', /** * Node.js 14.x @@ -255,7 +255,7 @@ export class CustomResourceProvider extends Construct { MemorySize: memory.toMebibytes(), Handler: `${ENTRYPOINT_FILENAME}.handler`, Role: role.getAtt('Arn'), - Runtime: props.runtime, + Runtime: customResourceProviderRuntimeToString(props.runtime), Environment: this.renderEnvironmentVariables(props.environment), Description: props.description ?? undefined, }, @@ -329,3 +329,15 @@ export class CustomResourceProvider extends Construct { return { Variables: variables }; } } + +function customResourceProviderRuntimeToString(x: CustomResourceProviderRuntime): string { + switch (x) { + case CustomResourceProviderRuntime.NODEJS_12: + case CustomResourceProviderRuntime.NODEJS_12_X: + return 'nodejs12.x'; + case CustomResourceProviderRuntime.NODEJS_14_X: + return 'nodejs14.x'; + case CustomResourceProviderRuntime.NODEJS_16_X: + return 'nodejs16.x'; + } +} \ No newline at end of file