Skip to content

Commit

Permalink
refactor: remove more duplicate enum values (aws#20982)
Browse files Browse the repository at this point in the history
This is a follow-up to aws#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*
  • Loading branch information
rix0rrr authored and daschaa committed Jul 9, 2022
1 parent f5c72e4 commit 47bfc7e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
25 changes: 22 additions & 3 deletions packages/@aws-cdk/aws-secretsmanager/lib/secret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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';
}
}
8 changes: 4 additions & 4 deletions packages/@aws-cdk/aws-secretsmanager/test/secret.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
});

Expand All @@ -1180,7 +1180,7 @@ test('can attach a secret with attach()', () => {
Ref: 'SecretA720EF05',
},
TargetId: 'target-id',
TargetType: 'target-type',
TargetType: 'AWS::DocDB::DBInstance',
});
});

Expand All @@ -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);
Expand All @@ -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', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
},
Expand Down Expand Up @@ -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';
}
}

0 comments on commit 47bfc7e

Please sign in to comment.