Skip to content

Commit

Permalink
revert change to fromKeyArn
Browse files Browse the repository at this point in the history
  • Loading branch information
Elad Ben-Israel authored Sep 10, 2019
1 parent d8892c2 commit 73df832
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions packages/@aws-cdk/aws-kms/lib/key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,18 +285,23 @@ export class Key extends KeyBase {
* @param keyArn the ARN of an existing KMS key.
*/
public static fromKeyArn(scope: Construct, id: string, keyArn: string): IKey {
const keyResourceName = Stack.of(scope).parseArn(keyArn).resourceName;
if (!keyResourceName) {
throw new Error(`KMS key ARN must be in the format 'arn:aws:kms:<region>:<account>:key/<keyId>', got: '${keyArn}'`);
}

class Import extends KeyBase {
public readonly keyArn = keyArn;
public readonly keyId = keyResourceName;
public readonly keyId: string;
protected readonly policy?: iam.PolicyDocument | undefined = undefined;

constructor(scope: Construct, id: string, keyResourceName: string) {
super(scope, id);
this.keyId = keyResourceName;
}
}

const keyResourceName = Stack.of(scope).parseArn(keyArn).resourceName;
if (!keyResourceName) {
throw new Error(`KMS key ARN must be in the format 'arn:aws:kms:<region>:<account>:key/<keyId>', got: '${keyArn}'`);
}

return new Import();
return new Import(keyResourceName);
}

public readonly keyArn: string;
Expand Down

0 comments on commit 73df832

Please sign in to comment.