Skip to content

Commit

Permalink
Abstract renderRepositoryCredentials() func
Browse files Browse the repository at this point in the history
  • Loading branch information
allisaurus committed Mar 8, 2019
1 parent 6ede80e commit 7877598
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-ecs/lib/container-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ export class ContainerDefinition extends cdk.Construct {
portMappings: this.portMappings.map(renderPortMapping),
privileged: this.props.privileged,
readonlyRootFilesystem: this.props.readonlyRootFilesystem,
repositoryCredentials: this.props.image.credentials && this.props.image.renderRepositoryCredentials(),
repositoryCredentials: this.props.image.renderRepositoryCredentials(),
ulimits: this.ulimits.map(renderUlimit),
user: this.props.user,
volumesFrom: this.volumesFrom.map(renderVolumeFrom),
Expand Down
8 changes: 2 additions & 6 deletions packages/@aws-cdk/aws-ecs/lib/container-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export abstract class ContainerImage {
/**
* Optional credentials for a private image registry
*/
public abstract readonly credentials?: RepositoryCreds;
protected abstract readonly credentials?: RepositoryCreds;

/**
* Called when the image is used by a ContainerDefinition
Expand All @@ -57,11 +57,7 @@ export abstract class ContainerImage {
/**
* Render the Repository credentials to the CloudFormation object
*/
public renderRepositoryCredentials(): CfnTaskDefinition.RepositoryCredentialsProperty {
return {
credentialsParameter: this.credentials ? this.credentials.secret.secretArn : ''
};
}
public abstract renderRepositoryCredentials(): CfnTaskDefinition.RepositoryCredentialsProperty | undefined;
}

import { AssetImage, AssetImageProps } from './images/asset-image';
Expand Down
6 changes: 5 additions & 1 deletion packages/@aws-cdk/aws-ecs/lib/images/asset-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface AssetImageProps {
* An image that will be built at synthesis time
*/
export class AssetImage extends ContainerImage {
public readonly credentials?: RepositoryCreds;
protected readonly credentials?: RepositoryCreds;
private readonly asset: DockerImageAsset;

constructor(scope: cdk.Construct, id: string, props: AssetImageProps) {
Expand All @@ -26,6 +26,10 @@ export class AssetImage extends ContainerImage {
this.asset.repository.grantPull(containerDefinition.taskDefinition.obtainExecutionRole());
}

public renderRepositoryCredentials(): undefined {
return undefined;
}

public get imageName() {
return this.asset.imageUri;
}
Expand Down
6 changes: 5 additions & 1 deletion packages/@aws-cdk/aws-ecs/lib/images/ecr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ContainerImage, RepositoryCreds } from '../container-image';
*/
export class EcrImage extends ContainerImage {
public readonly imageName: string;
public readonly credentials?: RepositoryCreds;
protected readonly credentials?: RepositoryCreds;
private readonly repository: ecr.IRepository;

constructor(repository: ecr.IRepository, tag: string) {
Expand All @@ -19,4 +19,8 @@ export class EcrImage extends ContainerImage {
public bind(containerDefinition: ContainerDefinition): void {
this.repository.grantPull(containerDefinition.taskDefinition.obtainExecutionRole());
}

public renderRepositoryCredentials(): undefined {
return undefined;
}
}
10 changes: 9 additions & 1 deletion packages/@aws-cdk/aws-ecs/lib/images/internet-hosted.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import secretsmanager = require('@aws-cdk/aws-secretsmanager');
import { ContainerDefinition } from "../container-definition";
import { ContainerImage, RepositoryCreds } from "../container-image";
import { CfnTaskDefinition } from '../ecs.generated';

export interface InternetHostedImageProps {
/**
Expand All @@ -14,7 +15,7 @@ export interface InternetHostedImageProps {
*/
export class InternetHostedImage extends ContainerImage {
public readonly imageName: string;
public readonly credentials?: RepositoryCreds;
protected readonly credentials?: RepositoryCreds;

constructor(imageName: string, props: InternetHostedImageProps = {}) {
super();
Expand All @@ -30,4 +31,11 @@ export class InternetHostedImage extends ContainerImage {
this.credentials.secret.grantRead(containerDefinition.taskDefinition.obtainExecutionRole());
}
}

public renderRepositoryCredentials(): CfnTaskDefinition.RepositoryCredentialsProperty | undefined {
if (!this.credentials) { return undefined; }
return {
credentialsParameter: this.credentials.secret.secretArn
};
}
}

0 comments on commit 7877598

Please sign in to comment.