Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove more duplicate enum values #20982

Merged
merged 4 commits into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
}
}
3 changes: 3 additions & 0 deletions packages/aws-cdk-lib/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@
"./aws-elasticsearch": "./aws-elasticsearch/index.js",
"./aws-emr": "./aws-emr/index.js",
"./aws-emrcontainers": "./aws-emrcontainers/index.js",
"./aws-emrserverless": "./aws-emrserverless/index.js",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were these intentional?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding do-not-merge and approving.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They get added as part of the aws-cdk-lib build.

"./aws-events": "./aws-events/index.js",
"./aws-events-targets": "./aws-events-targets/index.js",
"./aws-eventschemas": "./aws-eventschemas/index.js",
Expand Down Expand Up @@ -599,6 +600,7 @@
"./aws-synthetics": "./aws-synthetics/index.js",
"./aws-timestream": "./aws-timestream/index.js",
"./aws-transfer": "./aws-transfer/index.js",
"./aws-voiceid": "./aws-voiceid/index.js",
"./aws-waf": "./aws-waf/index.js",
"./aws-wafregional": "./aws-wafregional/index.js",
"./aws-wafv2": "./aws-wafv2/index.js",
Expand All @@ -607,6 +609,7 @@
"./aws-xray": "./aws-xray/index.js",
"./cloud-assembly-schema": "./cloud-assembly-schema/index.js",
"./cloudformation-include": "./cloudformation-include/index.js",
"./core/lib/helpers-internal": "./core/lib/helpers-internal/index.js",
"./custom-resources": "./custom-resources/index.js",
"./cx-api": "./cx-api/index.js",
"./lambda-layer-awscli": "./lambda-layer-awscli/index.js",
Expand Down