Skip to content

Commit

Permalink
Merge branch 'main' into automation/spec-update
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Dec 5, 2023
2 parents d0e345a + 6126413 commit e537f9e
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
19 changes: 19 additions & 0 deletions packages/aws-cdk-lib/aws-kms/lib/alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ abstract class AliasBase extends Resource implements IAlias {

public abstract readonly aliasTargetKey: IKey;

/**
* The ARN of the alias.
*
* @attribute
* @deprecated use `aliasArn` instead
*/
public get keyArn(): string {
return Stack.of(this).formatArn({
service: 'kms',
Expand All @@ -67,6 +73,19 @@ abstract class AliasBase extends Resource implements IAlias {
});
}

/**
* The ARN of the alias.
*
* @attribute
*/
public get aliasArn(): string {
return Stack.of(this).formatArn({
service: 'kms',
// aliasName already contains the '/'
resource: this.aliasName,
});
}

public get keyId(): string {
return this.aliasName;
}
Expand Down
26 changes: 25 additions & 1 deletion packages/aws-cdk-lib/aws-kms/test/alias.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Construct } from 'constructs';
import { Template } from '../../assertions';
import * as iam from '../../aws-iam';
import { ArnPrincipal, PolicyStatement } from '../../aws-iam';
import { App, Aws, CfnOutput, Stack } from '../../core';
import { App, Arn, Aws, CfnOutput, Stack } from '../../core';
import { KMS_ALIAS_NAME_REF } from '../../cx-api';
import { Alias } from '../lib/alias';
import { IKey, Key } from '../lib/key';
Expand Down Expand Up @@ -357,6 +357,30 @@ test('does not add alias if starts with token', () => {
});
});

test('aliasArn and keyArn from alias should match', () => {
const app = new App();
const stack = new Stack(app, 'Test');
const key = new Key(stack, 'Key');

const alias = new Alias(stack, 'Alias', { targetKey: key, aliasName: 'alias/foo' });

expect(alias.aliasArn).toEqual(alias.keyArn);
});

test('aliasArn should be a valid ARN', () => {
const app = new App();
const stack = new Stack(app, 'Test');
const key = new Key(stack, 'Key');

const alias = new Alias(stack, 'Alias', { targetKey: key, aliasName: 'alias/foo' });

expect(alias.aliasArn).toEqual(Arn.format({
service: 'kms',
// aliasName already contains the '/'
resource: alias.aliasName,
}, stack));
});

class AliasOutputsConstruct extends Construct {
constructor(scope: Construct, id: string, key: IKey) {
super(scope, id);
Expand Down

0 comments on commit e537f9e

Please sign in to comment.