Skip to content

Commit 37fdd2d

Browse files
committed
feat!: resouce name changed & add get host arn method
1 parent f8751de commit 37fdd2d

6 files changed

+54
-1
lines changed

src/index.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ export enum CodeConnectionsHostProviderType {
1313
GIT_LAB_SELF_MANAGED = 'GitLabSelfManaged',
1414
}
1515

16+
export enum ResponseField {
17+
HostArn = 'HostArn',
18+
}
19+
1620
export interface CodeConnectionsHostCustomResourceProps {
1721
readonly name: string;
1822
readonly providerEndpoint: string;
@@ -25,7 +29,7 @@ export class CodeConnectionsHostCustomResource extends cr.AwsCustomResource {
2529

2630
// 👇 Create random 8 length string
2731
const random: string = crypto.createHash('shake256', { outputLength: 4 })
28-
.update(cdk.Names.uniqueId(scope))
32+
.update(`${cdk.Names.uniqueId(scope)}.${props.name}.${props.providerEndpoint}.${props.providerType}`)
2933
.digest('hex');
3034

3135
const account = cdk.Stack.of(scope).account;
@@ -89,4 +93,9 @@ export class CodeConnectionsHostCustomResource extends cr.AwsCustomResource {
8993
},
9094
});
9195
}
96+
97+
getHostArn(): string {
98+
return this.getResponseField(ResponseField.HostArn);
99+
}
100+
92101
}

test/custom-resource.bitbucket.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { App, Stack } from 'aws-cdk-lib';
22
import { Template } from 'aws-cdk-lib/assertions';
3+
import * as codeconnections from 'aws-cdk-lib/aws-codeconnections';
34
import { AwsCustomResource } from 'aws-cdk-lib/custom-resources';
45
import { CodeConnectionsHostCustomResource, CodeConnectionsHostProviderType } from '../src';
56

@@ -19,6 +20,13 @@ describe('CustomResource Testing', () => {
1920
providerType: CodeConnectionsHostProviderType.BIT_BUCKET,
2021
});
2122

23+
const hostArn = bitbucketConnectionHostCustomResource.getHostArn();
24+
25+
new codeconnections.CfnConnection(stack, 'Connection', {
26+
connectionName: 'example-bitbucket-connection',
27+
hostArn,
28+
});
29+
2230
const template = Template.fromStack(stack);
2331

2432
it('Is Bitbucket Connection Host CustomResource', () => {

test/custom-resource.github-enterprise.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { App, Stack } from 'aws-cdk-lib';
22
import { Template } from 'aws-cdk-lib/assertions';
3+
import * as codeconnections from 'aws-cdk-lib/aws-codeconnections';
34
import { AwsCustomResource } from 'aws-cdk-lib/custom-resources';
45
import { CodeConnectionsHostCustomResource, CodeConnectionsHostProviderType } from '../src';
56

@@ -19,6 +20,13 @@ describe('CustomResource Testing', () => {
1920
providerType: CodeConnectionsHostProviderType.GIT_HUB_ENTERPRISE_SERVER,
2021
});
2122

23+
const hostArn = gitHubEnterpriseConnectionHostCustomResource.getHostArn();
24+
25+
new codeconnections.CfnConnection(stack, 'Connection', {
26+
connectionName: 'example-github-enterprise-connection',
27+
hostArn,
28+
});
29+
2230
const template = Template.fromStack(stack);
2331

2432
it('Is GitHub Enterprise Connection Host CustomResource', () => {

test/custom-resource.github.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { App, Stack } from 'aws-cdk-lib';
22
import { Template } from 'aws-cdk-lib/assertions';
3+
import * as codeconnections from 'aws-cdk-lib/aws-codeconnections';
34
import { AwsCustomResource } from 'aws-cdk-lib/custom-resources';
45
import { CodeConnectionsHostCustomResource, CodeConnectionsHostProviderType } from '../src';
56

@@ -19,6 +20,13 @@ describe('CustomResource Testing', () => {
1920
providerType: CodeConnectionsHostProviderType.GIT_HUB,
2021
});
2122

23+
const hostArn = gitHubConnectionHostCustomResource.getHostArn();
24+
25+
new codeconnections.CfnConnection(stack, 'Connection', {
26+
connectionName: 'example-github-connection',
27+
hostArn,
28+
});
29+
2230
const template = Template.fromStack(stack);
2331

2432
it('Is GitHub Connection Host CustomResource', () => {

test/custom-resource.gitlab-self-managed.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { App, Stack } from 'aws-cdk-lib';
22
import { Template } from 'aws-cdk-lib/assertions';
3+
import * as codeconnections from 'aws-cdk-lib/aws-codeconnections';
34
import { AwsCustomResource } from 'aws-cdk-lib/custom-resources';
45
import { CodeConnectionsHostCustomResource, CodeConnectionsHostProviderType } from '../src';
56

@@ -19,12 +20,23 @@ describe('CustomResource Testing', () => {
1920
providerType: CodeConnectionsHostProviderType.GIT_LAB_SELF_MANAGED,
2021
});
2122

23+
const hostArn = gitLabSelfManagedConnectionHostCustomResource.getHostArn();
24+
25+
new codeconnections.CfnConnection(stack, 'Connection', {
26+
connectionName: 'example-gitlab-self-managed-connection',
27+
hostArn,
28+
});
29+
2230
const template = Template.fromStack(stack);
2331

2432
it('Is GitLab Self Managed Connectrion Host CustomResource', () => {
2533
expect(gitLabSelfManagedConnectionHostCustomResource).toBeInstanceOf(AwsCustomResource);
2634
});
2735

36+
it('Is hostArn string', () => {
37+
expect(hostArn).not.toBeNull();
38+
});
39+
2840
it('Should match snapshot', () => {
2941
expect(template.toJSON()).toMatchSnapshot();
3042
});

test/custom-resource.gitlab.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { App, Stack } from 'aws-cdk-lib';
22
import { Template } from 'aws-cdk-lib/assertions';
3+
import * as codeconnections from 'aws-cdk-lib/aws-codeconnections';
34
import { AwsCustomResource } from 'aws-cdk-lib/custom-resources';
45
import { CodeConnectionsHostCustomResource, CodeConnectionsHostProviderType } from '../src';
56

@@ -19,6 +20,13 @@ describe('CustomResource Testing', () => {
1920
providerType: CodeConnectionsHostProviderType.GIT_LAB,
2021
});
2122

23+
const hostArn = gitLabConnectionHostCustomResource.getHostArn();
24+
25+
new codeconnections.CfnConnection(stack, 'Connection', {
26+
connectionName: 'example-gitlab-connection',
27+
hostArn,
28+
});
29+
2230
const template = Template.fromStack(stack);
2331

2432
it('Is GitLab Connection Host CustomResource', () => {

0 commit comments

Comments
 (0)