-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(servicecatalogappregistry): prepare ApplicationAssociator fo…
…r future extensions (#22644) Updated Input Structure for Application Associator L2 Construct * This helps user to pass the input using factory pattern * Factory Pattern makes construct extensible ---- ### All Submissions: * [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [x] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* Co-authored by: Santanu Ghosh
- Loading branch information
1 parent
1f50814
commit c4e07a6
Showing
7 changed files
with
187 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
packages/@aws-cdk/aws-servicecatalogappregistry/lib/target-application.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import * as cdk from '@aws-cdk/core'; | ||
import { Construct } from 'constructs'; | ||
import { IApplication, Application } from './application'; | ||
|
||
/** | ||
* Properties used to define targetapplication. | ||
*/ | ||
export interface TargetApplicationCommonOptions extends cdk.StackProps { | ||
/** | ||
* Stack ID in which application will be created or imported. | ||
* | ||
* @default - ApplicationAssociatorStack | ||
*/ | ||
readonly stackId?: string; | ||
} | ||
|
||
|
||
/** | ||
* Properties used to define New TargetApplication. | ||
*/ | ||
export interface CreateTargetApplicationOptions extends TargetApplicationCommonOptions { | ||
/** | ||
* Enforces a particular physical application name. | ||
*/ | ||
readonly applicationName: string; | ||
|
||
/** | ||
* Application description. | ||
* | ||
* @default - No description. | ||
*/ | ||
readonly applicationDescription?: string; | ||
} | ||
|
||
/** | ||
* Properties used to define Existing TargetApplication. | ||
*/ | ||
export interface ExistingTargetApplicationOptions extends TargetApplicationCommonOptions { | ||
/** | ||
* Enforces a particular application arn. | ||
*/ | ||
readonly applicationArnValue: string; | ||
} | ||
|
||
/** | ||
* Contains static factory methods with which you can build the input | ||
* needed for application associator to work | ||
*/ | ||
export abstract class TargetApplication { | ||
/** | ||
* Factory method to build the input using the provided | ||
* application ARN. | ||
*/ | ||
public static existingApplicationFromArn(options: ExistingTargetApplicationOptions) : TargetApplication { | ||
return new ExistingTargetApplication(options); | ||
} | ||
|
||
/** | ||
* Factory method to build the input using the provided | ||
* application name and stack props. | ||
*/ | ||
public static createApplicationStack(options: CreateTargetApplicationOptions) : TargetApplication { | ||
return new CreateTargetApplication(options); | ||
} | ||
|
||
/** | ||
* Called when the ApplicationAssociator is initialized | ||
*/ | ||
public abstract bind(scope: Construct): BindTargetApplicationResult; | ||
} | ||
|
||
/** | ||
* Properties for Service Catalog AppRegistry Application Associator to work with | ||
*/ | ||
export interface BindTargetApplicationResult { | ||
/** | ||
* Created or imported application. | ||
*/ | ||
readonly application: IApplication; | ||
} | ||
|
||
/** | ||
* Class which constructs the input from provided application name and stack props. | ||
* With this input, the construct will create the Application. | ||
*/ | ||
class CreateTargetApplication extends TargetApplication { | ||
constructor( | ||
private readonly applicationOptions: CreateTargetApplicationOptions) { | ||
super(); | ||
} | ||
public bind(scope: Construct): BindTargetApplicationResult { | ||
const stackId = this.applicationOptions.stackId ?? 'ApplicationAssociatorStack'; | ||
const applicationStack = new cdk.Stack(scope, stackId, this.applicationOptions); | ||
const appRegApplication = new Application(applicationStack, 'DefaultCdkApplication', { | ||
applicationName: this.applicationOptions.applicationName, | ||
description: this.applicationOptions.applicationDescription, | ||
}); | ||
|
||
return { | ||
application: appRegApplication, | ||
}; | ||
} | ||
} | ||
|
||
/** | ||
* Class which constructs the input from provided Application ARN. | ||
*/ | ||
class ExistingTargetApplication extends TargetApplication { | ||
constructor( | ||
private readonly applicationOptions: ExistingTargetApplicationOptions) { | ||
super(); | ||
} | ||
public bind(scope: Construct): BindTargetApplicationResult { | ||
const stackId = this.applicationOptions.stackId ?? 'ApplicationAssociatorStack'; | ||
const applicationStack = new cdk.Stack(scope, stackId, this.applicationOptions); | ||
const appRegApplication = Application.fromApplicationArn(applicationStack, 'ExistingApplication', this.applicationOptions.applicationArnValue); | ||
return { | ||
application: appRegApplication, | ||
}; | ||
} | ||
} |
Oops, something went wrong.