Skip to content

Commit

Permalink
use IPublicKey as items param in KeyGroupProps
Browse files Browse the repository at this point in the history
  • Loading branch information
robertd committed Jan 29, 2021
1 parent 35f4cd1 commit e0a1c2b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/@aws-cdk/aws-cloudfront/lib/key-group.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Resource } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { CfnKeyGroup } from './cloudfront.generated';
import { IPublicKey } from './public-key';

/**
* Represents a Key Group
Expand Down Expand Up @@ -32,7 +33,7 @@ export interface KeyGroupProps {
/**
* A list of the identifiers of the public keys in the key group.
*/
readonly items?: string[];
readonly items: IPublicKey[];
}

/**
Expand All @@ -42,6 +43,7 @@ export interface KeyGroupProps {
*/
export class KeyGroup extends Resource implements IKeyGroup {

/** Imports a Key Group from its id. */
public static fromKeyGroupId(scope: Construct, id: string, keyGroupId: string): IKeyGroup {
return new class extends Resource implements IKeyGroup {
public readonly keyGroupId = keyGroupId;
Expand All @@ -59,10 +61,15 @@ export class KeyGroup extends Resource implements IKeyGroup {
keyGroupConfig: {
name: props.keyGroupName, //TODO: We can always add validation -- once known later
comment: props.comment,
items: props.items ?? [],
items: this.getKeyIdentifiers(props.items),
},
});

this.keyGroupId = resource.ref;
}

private getKeyIdentifiers(items: IPublicKey[]): string[] {
return items.map((key)=> {
return key.publicKeyId;
});
}
}
2 changes: 2 additions & 0 deletions packages/@aws-cdk/aws-cloudfront/lib/public-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export interface PublicKeyProps {
* @resource AWS::CloudFront::KeyGroup
*/
export class PublicKey extends Resource implements IPublicKey {

/** Imports a Public Key from its id. */
public static fromPublicKeyId(scope: Construct, id: string, publicKeyId: string): IPublicKey {
return new class extends Resource implements IPublicKey {
public readonly publicKeyId = publicKeyId;
Expand Down

0 comments on commit e0a1c2b

Please sign in to comment.