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

fix(kms): append aliasName only after first #3659

Merged
merged 2 commits into from
Aug 14, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
16 changes: 14 additions & 2 deletions packages/@aws-cdk/aws-kms/lib/key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,23 @@ abstract class KeyBase extends Resource implements IKey {
*/
protected abstract readonly policy?: PolicyDocument;

/**
* Collection of aliases added to the key
*
* Tracked to determine whether or not the aliasName should be added to the end of its ID
*/
private readonly aliases: Alias[] = [];
eladb marked this conversation as resolved.
Show resolved Hide resolved

/**
* Defines a new alias for the key.
*/
public addAlias(alias: string): Alias {
return new Alias(this, `Alias${alias}`, { aliasName: alias, targetKey: this });
public addAlias(aliasName: string): Alias {
const aliasId = this.aliases.length > 0 ? `Alias${aliasName}` : 'Alias';

const alias = new Alias(this, aliasId, { aliasName, targetKey: this });
this.aliases.push(alias);

return alias;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-kms/test/integ.key.expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"UpdateReplacePolicy": "Delete",
"DeletionPolicy": "Delete"
},
"MyKeyAliasaliasbarD0D50DB8": {
"MyKeyAlias1B45D9DA": {
"Type": "AWS::KMS::Alias",
"Properties": {
"AliasName": "alias/bar",
Expand Down
6 changes: 3 additions & 3 deletions packages/@aws-cdk/aws-kms/test/test.key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ export = {
DeletionPolicy: "Retain",
UpdateReplacePolicy: "Retain",
},
MyKeyAliasaliasxoo9464EB1C: {
MyKeyAlias1B45D9DA: {
Type: "AWS::KMS::Alias",
Properties: {
AliasName: "alias/xoo",
Expand Down Expand Up @@ -396,7 +396,7 @@ export = {
DeletionPolicy: "Retain",
UpdateReplacePolicy: "Retain",
},
MyKeyAliasaliasalias1668D31D7: {
MyKeyAlias1B45D9DA: {
Type: "AWS::KMS::Alias",
Properties: {
AliasName: "alias/alias1",
Expand Down Expand Up @@ -484,7 +484,7 @@ export = {

expect(stack2).toMatch({
Resources: {
MyKeyImportedAliasaliashelloD41FEB6C: {
MyKeyImportedAliasB1C5269F: {
Type: "AWS::KMS::Alias",
Properties: {
AliasName: "alias/hello",
Expand Down