Skip to content

Commit

Permalink
Declare one Import class in module scope
Browse files Browse the repository at this point in the history
  • Loading branch information
Mitch Lloyd committed Feb 7, 2021
1 parent 0b828fa commit 36f9eb9
Showing 1 changed file with 27 additions and 17 deletions.
44 changes: 27 additions & 17 deletions packages/@aws-cdk/aws-kinesisanalytics-flink/lib/application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,27 @@ export interface ApplicationProps {
readonly logEncryptionKey?: kms.IKey;
}

/**
* An imported Flink application.
*/
class Import extends ApplicationBase {
public readonly grantPrincipal: iam.IPrincipal;
public readonly role?: iam.IRole;
public readonly applicationName: string;
public readonly applicationArn: string;

constructor(scope: Construct, id: string, attrs: { applicationArn: string, applicationName: string }) {
super(scope, id);

// Imported applications have no associated role or grantPrincipal
this.grantPrincipal = new iam.UnknownPrincipal({ resource: this });
this.role = undefined;

this.applicationArn = attrs.applicationArn;
this.applicationName = attrs.applicationName;
}
}

/**
* The L2 construct for Flink Kinesis Data Applications.
*
Expand All @@ -226,33 +247,22 @@ export class Application extends ApplicationBase {
* applicationName.
*/
public static fromApplicationName(scope: Construct, id: string, applicationName: string): IApplication {
class Import extends ApplicationBase {
// Imported applications have no associated role or grantPrincipal
public readonly role = undefined;
public readonly grantPrincipal = new iam.UnknownPrincipal({ resource: this });
const applicationArn = core.Stack.of(scope).formatArn(applicationArnComponents(applicationName));

public readonly applicationName = applicationName;
public readonly applicationArn = core.Stack.of(this).formatArn(applicationArnComponents(applicationName));
}

return new Import(scope, id);
return new Import(scope, id, { applicationArn, applicationName });
}

/**
* Import an existing application defined outside of CDK code by
* applicationArn.
*/
public static fromApplicationArn(scope: Construct, id: string, applicationArn: string): IApplication {
class Import extends ApplicationBase {
// Imported applications have no associated role or grantPrincipal
public readonly role = undefined;
public readonly grantPrincipal = new iam.UnknownPrincipal({ resource: this });

public readonly applicationName = applicationArn.split('/')[1];
public readonly applicationArn = applicationArn;
const applicationName = core.Stack.of(scope).parseArn(applicationArn).resourceName;
if (!applicationName) {
throw new Error(`applicationArn for fromApplicationArn (${applicationArn}) must include resource name`);
}

return new Import(scope, id);
return new Import(scope, id, { applicationArn, applicationName });
}

public readonly applicationArn: string;
Expand Down

0 comments on commit 36f9eb9

Please sign in to comment.