From 4e309cf76f6532c9068719a3ec939f8222b36d9c Mon Sep 17 00:00:00 2001 From: yicr Date: Wed, 2 Oct 2024 14:46:48 +0900 Subject: [PATCH 1/6] feat!: change provider type to enum --- src/index.ts | 11 ++++++- test/custom-resource.bitbucket.test.ts | 32 +++++++++++++++++++ .../custom-resource.github-enterprise.test.ts | 32 +++++++++++++++++++ test/custom-resource.github.test.ts | 32 +++++++++++++++++++ ...ustom-resource.gitlab-self-managed.test.ts | 32 +++++++++++++++++++ ...test.ts => custom-resource.gitlab.test.ts} | 10 +++--- 6 files changed, 143 insertions(+), 6 deletions(-) create mode 100644 test/custom-resource.bitbucket.test.ts create mode 100644 test/custom-resource.github-enterprise.test.ts create mode 100644 test/custom-resource.github.test.ts create mode 100644 test/custom-resource.gitlab-self-managed.test.ts rename test/{custom-resource.test.ts => custom-resource.gitlab.test.ts} (58%) diff --git a/src/index.ts b/src/index.ts index 85cd3b9..54d9aa7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,10 +4,19 @@ import * as iam from 'aws-cdk-lib/aws-iam'; import * as cr from 'aws-cdk-lib/custom-resources'; import { Construct } from 'constructs'; +// Bitbucket | GitHub | GitHubEnterpriseServer | GitLab | GitLabSelfManaged +export enum CodeConnectionsHostProviderType { + Bitbucket = 'Bitbucket', + GitHub = 'GitHub', + GitHubEnterpriseServer = 'GitHubEnterpriseServer', + GitLab = 'GitLab', + GitLabSelfManaged = 'GitLabSelfManaged', +} + export interface CodeConnectionsHostCustomResourceProps { readonly name: string; readonly providerEndpoint: string; - readonly providerType: string; + readonly providerType: CodeConnectionsHostProviderType; } export class CodeConnectionsHostCustomResource extends cr.AwsCustomResource { diff --git a/test/custom-resource.bitbucket.test.ts b/test/custom-resource.bitbucket.test.ts new file mode 100644 index 0000000..940a1dd --- /dev/null +++ b/test/custom-resource.bitbucket.test.ts @@ -0,0 +1,32 @@ +import { App, Stack } from 'aws-cdk-lib'; +import { Template } from 'aws-cdk-lib/assertions'; +import { AwsCustomResource } from 'aws-cdk-lib/custom-resources'; +import { CodeConnectionsHostCustomResource, CodeConnectionsHostProviderType } from '../src'; + +describe('CustomResource Testing', () => { + + const app = new App(); + const stack = new Stack(app, 'TestingStack', { + env: { + account: '123456789012', + region: 'us-east-1', + }, + }); + + const bitbucketConnectionHostCustomResource = new CodeConnectionsHostCustomResource(stack, 'BitBucketCodeConnectionsHostCustomResource', { + name: 'bitbucket.example.com', + providerEndpoint: 'https://bitbucket.example.com', + providerType: CodeConnectionsHostProviderType.Bitbucket, + }); + + const template = Template.fromStack(stack); + + it('Is Bitbucket Connection Host CustomResource', () => { + expect(bitbucketConnectionHostCustomResource).toBeInstanceOf(AwsCustomResource); + }); + + it('Should match snapshot', () => { + expect(template.toJSON()).toMatchSnapshot(); + }); + +}); diff --git a/test/custom-resource.github-enterprise.test.ts b/test/custom-resource.github-enterprise.test.ts new file mode 100644 index 0000000..d2cee14 --- /dev/null +++ b/test/custom-resource.github-enterprise.test.ts @@ -0,0 +1,32 @@ +import { App, Stack } from 'aws-cdk-lib'; +import { Template } from 'aws-cdk-lib/assertions'; +import { AwsCustomResource } from 'aws-cdk-lib/custom-resources'; +import { CodeConnectionsHostCustomResource, CodeConnectionsHostProviderType } from '../src'; + +describe('CustomResource Testing', () => { + + const app = new App(); + const stack = new Stack(app, 'TestingStack', { + env: { + account: '123456789012', + region: 'us-east-1', + }, + }); + + const gitHubEnterpriseConnectionHostCustomResource = new CodeConnectionsHostCustomResource(stack, 'GitHibEnterpriseCodeConnectionsHostCustomResource', { + name: 'github.example.com', + providerEndpoint: 'https://github.example.com', + providerType: CodeConnectionsHostProviderType.GitHubEnterpriseServer, + }); + + const template = Template.fromStack(stack); + + it('Is GitHub Enterprise Connection Host CustomResource', () => { + expect(gitHubEnterpriseConnectionHostCustomResource).toBeInstanceOf(AwsCustomResource); + }); + + it('Should match snapshot', () => { + expect(template.toJSON()).toMatchSnapshot(); + }); + +}); diff --git a/test/custom-resource.github.test.ts b/test/custom-resource.github.test.ts new file mode 100644 index 0000000..12e7c82 --- /dev/null +++ b/test/custom-resource.github.test.ts @@ -0,0 +1,32 @@ +import { App, Stack } from 'aws-cdk-lib'; +import { Template } from 'aws-cdk-lib/assertions'; +import { AwsCustomResource } from 'aws-cdk-lib/custom-resources'; +import { CodeConnectionsHostCustomResource, CodeConnectionsHostProviderType } from '../src'; + +describe('CustomResource Testing', () => { + + const app = new App(); + const stack = new Stack(app, 'TestingStack', { + env: { + account: '123456789012', + region: 'us-east-1', + }, + }); + + const gitHubConnectionHostCustomResource = new CodeConnectionsHostCustomResource(stack, 'GitHubCodeConnectionsHostCustomResource', { + name: 'github.example.com', + providerEndpoint: 'https://github.example.com', + providerType: CodeConnectionsHostProviderType.GitHub, + }); + + const template = Template.fromStack(stack); + + it('Is GitHub Connection Host CustomResource', () => { + expect(gitHubConnectionHostCustomResource).toBeInstanceOf(AwsCustomResource); + }); + + it('Should match snapshot', () => { + expect(template.toJSON()).toMatchSnapshot(); + }); + +}); diff --git a/test/custom-resource.gitlab-self-managed.test.ts b/test/custom-resource.gitlab-self-managed.test.ts new file mode 100644 index 0000000..573d5de --- /dev/null +++ b/test/custom-resource.gitlab-self-managed.test.ts @@ -0,0 +1,32 @@ +import { App, Stack } from 'aws-cdk-lib'; +import { Template } from 'aws-cdk-lib/assertions'; +import { AwsCustomResource } from 'aws-cdk-lib/custom-resources'; +import { CodeConnectionsHostCustomResource, CodeConnectionsHostProviderType } from '../src'; + +describe('CustomResource Testing', () => { + + const app = new App(); + const stack = new Stack(app, 'TestingStack', { + env: { + account: '123456789012', + region: 'us-east-1', + }, + }); + + const gitLabSelfManagedConnectionHostCustomResource = new CodeConnectionsHostCustomResource(stack, 'GitLabSelfManagedCodeConnectionsHostCustomResource', { + name: 'gitlab.example.com', + providerEndpoint: 'https://gitlab.example.com', + providerType: CodeConnectionsHostProviderType.GitLabSelfManaged, + }); + + const template = Template.fromStack(stack); + + it('Is GitLab Self Managed Connectrion Host CustomResource', () => { + expect(gitLabSelfManagedConnectionHostCustomResource).toBeInstanceOf(AwsCustomResource); + }); + + it('Should match snapshot', () => { + expect(template.toJSON()).toMatchSnapshot(); + }); + +}); diff --git a/test/custom-resource.test.ts b/test/custom-resource.gitlab.test.ts similarity index 58% rename from test/custom-resource.test.ts rename to test/custom-resource.gitlab.test.ts index 4c7586d..b7cb3d9 100644 --- a/test/custom-resource.test.ts +++ b/test/custom-resource.gitlab.test.ts @@ -1,7 +1,7 @@ import { App, Stack } from 'aws-cdk-lib'; import { Template } from 'aws-cdk-lib/assertions'; import { AwsCustomResource } from 'aws-cdk-lib/custom-resources'; -import { CodeConnectionsHostCustomResource } from '../src'; +import { CodeConnectionsHostCustomResource, CodeConnectionsHostProviderType } from '../src'; describe('CustomResource Testing', () => { @@ -13,16 +13,16 @@ describe('CustomResource Testing', () => { }, }); - const cr = new CodeConnectionsHostCustomResource(stack, 'CodeConnectionsHostCustomResource', { + const gitLabConnectionHostCustomResource = new CodeConnectionsHostCustomResource(stack, 'GitLabCodeConnectionsHostCustomResource', { name: 'gitlab.example.com', providerEndpoint: 'https://gitlab.example.com', - providerType: 'GitLabSelfManaged', + providerType: CodeConnectionsHostProviderType.GitLabSelfManaged, }); const template = Template.fromStack(stack); - it('Is CustomResource', () => { - expect(cr).toBeInstanceOf(AwsCustomResource); + it('Is GitLab Connection Host CustomResource', () => { + expect(gitLabConnectionHostCustomResource).toBeInstanceOf(AwsCustomResource); }); it('Should match snapshot', () => { From 4042727caec91f1e6bfebc651d63cc21627f1b73 Mon Sep 17 00:00:00 2001 From: yicr Date: Wed, 2 Oct 2024 14:47:26 +0900 Subject: [PATCH 2/6] chore(test): update snapshots --- .../custom-resource.bitbucket.test.ts.snap | 133 ++++++++++++++++++ ...om-resource.github-enterprise.test.ts.snap | 133 ++++++++++++++++++ .../custom-resource.github.test.ts.snap | 133 ++++++++++++++++++ ...-resource.gitlab-self-managed.test.ts.snap | 133 ++++++++++++++++++ ...ap => custom-resource.gitlab.test.ts.snap} | 34 ++--- 5 files changed, 549 insertions(+), 17 deletions(-) create mode 100644 test/__snapshots__/custom-resource.bitbucket.test.ts.snap create mode 100644 test/__snapshots__/custom-resource.github-enterprise.test.ts.snap create mode 100644 test/__snapshots__/custom-resource.github.test.ts.snap create mode 100644 test/__snapshots__/custom-resource.gitlab-self-managed.test.ts.snap rename test/__snapshots__/{custom-resource.test.ts.snap => custom-resource.gitlab.test.ts.snap} (98%) diff --git a/test/__snapshots__/custom-resource.bitbucket.test.ts.snap b/test/__snapshots__/custom-resource.bitbucket.test.ts.snap new file mode 100644 index 0000000..f4af77d --- /dev/null +++ b/test/__snapshots__/custom-resource.bitbucket.test.ts.snap @@ -0,0 +1,133 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`CustomResource Testing Should match snapshot 1`] = ` +{ + "Parameters": { + "BootstrapVersion": { + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]", + "Type": "AWS::SSM::Parameter::Value", + }, + }, + "Resources": { + "AWS679f53fac002430cb0da5b7982bd22872D164C4C": { + "DependsOn": [ + "FunctionRole111A5701", + ], + "Properties": { + "Code": { + "S3Bucket": "cdk-hnb659fds-assets-123456789012-us-east-1", + "S3Key": "17c16a3854838fd3ff4bda08146122a6701f33b9c86ae17f415ad0dc47a97544.zip", + }, + "FunctionName": "custom-resource-codeconnection-host-eadb0d58-func", + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "FunctionRole111A5701", + "Arn", + ], + }, + "Runtime": "nodejs18.x", + "Timeout": 15, + }, + "Type": "AWS::Lambda::Function", + }, + "BitBucketCodeConnectionsHostCustomResource983A9F6A": { + "DeletionPolicy": "Delete", + "Properties": { + "Create": "{"service":"CodeConnections","action":"createHost","parameters":{"Name":"bitbucket.example.com","ProviderEndpoint":"https://bitbucket.example.com","ProviderType":"Bitbucket"},"physicalResourceId":{"responsePath":"HostArn"}}", + "Delete": "{"service":"CodeConnections","action":"deleteHost","parameters":{"HostArn":"PHYSICAL:RESOURCEID:"}}", + "InstallLatestAwsSdk": true, + "ServiceToken": { + "Fn::GetAtt": [ + "AWS679f53fac002430cb0da5b7982bd22872D164C4C", + "Arn", + ], + }, + "Update": "{"service":"CodeConnections","action":"updateHost","parameters":{"HostArn":"PHYSICAL:RESOURCEID:","ProviderEndpoint":"https://bitbucket.example.com"}}", + }, + "Type": "Custom::AWS", + "UpdateReplacePolicy": "Delete", + }, + "FunctionRole111A5701": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com", + }, + }, + ], + "Version": "2012-10-17", + }, + "Description": "Custom Resource Function Execution Role.", + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition", + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + ], + ], + }, + ], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "codeconnections:CreateHost", + "codeconnections:UpdateHost", + "codeconnections:DeleteHost", + ], + "Effect": "Allow", + "Resource": "arn:aws:codeconnections:us-east-1:123456789012:*", + }, + ], + "Version": "2012-10-17", + }, + "PolicyName": "CustomResourcePolicy", + }, + ], + "RoleName": "custom-resource-codeconnection-host-eadb0d58-func-exc-role", + }, + "Type": "AWS::IAM::Role", + }, + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5", + ], + { + "Ref": "BootstrapVersion", + }, + ], + }, + ], + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI.", + }, + ], + }, + }, +} +`; diff --git a/test/__snapshots__/custom-resource.github-enterprise.test.ts.snap b/test/__snapshots__/custom-resource.github-enterprise.test.ts.snap new file mode 100644 index 0000000..872a446 --- /dev/null +++ b/test/__snapshots__/custom-resource.github-enterprise.test.ts.snap @@ -0,0 +1,133 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`CustomResource Testing Should match snapshot 1`] = ` +{ + "Parameters": { + "BootstrapVersion": { + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]", + "Type": "AWS::SSM::Parameter::Value", + }, + }, + "Resources": { + "AWS679f53fac002430cb0da5b7982bd22872D164C4C": { + "DependsOn": [ + "FunctionRole111A5701", + ], + "Properties": { + "Code": { + "S3Bucket": "cdk-hnb659fds-assets-123456789012-us-east-1", + "S3Key": "17c16a3854838fd3ff4bda08146122a6701f33b9c86ae17f415ad0dc47a97544.zip", + }, + "FunctionName": "custom-resource-codeconnection-host-eadb0d58-func", + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "FunctionRole111A5701", + "Arn", + ], + }, + "Runtime": "nodejs18.x", + "Timeout": 15, + }, + "Type": "AWS::Lambda::Function", + }, + "FunctionRole111A5701": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com", + }, + }, + ], + "Version": "2012-10-17", + }, + "Description": "Custom Resource Function Execution Role.", + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition", + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + ], + ], + }, + ], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "codeconnections:CreateHost", + "codeconnections:UpdateHost", + "codeconnections:DeleteHost", + ], + "Effect": "Allow", + "Resource": "arn:aws:codeconnections:us-east-1:123456789012:*", + }, + ], + "Version": "2012-10-17", + }, + "PolicyName": "CustomResourcePolicy", + }, + ], + "RoleName": "custom-resource-codeconnection-host-eadb0d58-func-exc-role", + }, + "Type": "AWS::IAM::Role", + }, + "GitHibEnterpriseCodeConnectionsHostCustomResource3C231391": { + "DeletionPolicy": "Delete", + "Properties": { + "Create": "{"service":"CodeConnections","action":"createHost","parameters":{"Name":"github.example.com","ProviderEndpoint":"https://github.example.com","ProviderType":"GitHubEnterpriseServer"},"physicalResourceId":{"responsePath":"HostArn"}}", + "Delete": "{"service":"CodeConnections","action":"deleteHost","parameters":{"HostArn":"PHYSICAL:RESOURCEID:"}}", + "InstallLatestAwsSdk": true, + "ServiceToken": { + "Fn::GetAtt": [ + "AWS679f53fac002430cb0da5b7982bd22872D164C4C", + "Arn", + ], + }, + "Update": "{"service":"CodeConnections","action":"updateHost","parameters":{"HostArn":"PHYSICAL:RESOURCEID:","ProviderEndpoint":"https://github.example.com"}}", + }, + "Type": "Custom::AWS", + "UpdateReplacePolicy": "Delete", + }, + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5", + ], + { + "Ref": "BootstrapVersion", + }, + ], + }, + ], + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI.", + }, + ], + }, + }, +} +`; diff --git a/test/__snapshots__/custom-resource.github.test.ts.snap b/test/__snapshots__/custom-resource.github.test.ts.snap new file mode 100644 index 0000000..cc665e2 --- /dev/null +++ b/test/__snapshots__/custom-resource.github.test.ts.snap @@ -0,0 +1,133 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`CustomResource Testing Should match snapshot 1`] = ` +{ + "Parameters": { + "BootstrapVersion": { + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]", + "Type": "AWS::SSM::Parameter::Value", + }, + }, + "Resources": { + "AWS679f53fac002430cb0da5b7982bd22872D164C4C": { + "DependsOn": [ + "FunctionRole111A5701", + ], + "Properties": { + "Code": { + "S3Bucket": "cdk-hnb659fds-assets-123456789012-us-east-1", + "S3Key": "17c16a3854838fd3ff4bda08146122a6701f33b9c86ae17f415ad0dc47a97544.zip", + }, + "FunctionName": "custom-resource-codeconnection-host-eadb0d58-func", + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "FunctionRole111A5701", + "Arn", + ], + }, + "Runtime": "nodejs18.x", + "Timeout": 15, + }, + "Type": "AWS::Lambda::Function", + }, + "FunctionRole111A5701": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com", + }, + }, + ], + "Version": "2012-10-17", + }, + "Description": "Custom Resource Function Execution Role.", + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition", + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + ], + ], + }, + ], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "codeconnections:CreateHost", + "codeconnections:UpdateHost", + "codeconnections:DeleteHost", + ], + "Effect": "Allow", + "Resource": "arn:aws:codeconnections:us-east-1:123456789012:*", + }, + ], + "Version": "2012-10-17", + }, + "PolicyName": "CustomResourcePolicy", + }, + ], + "RoleName": "custom-resource-codeconnection-host-eadb0d58-func-exc-role", + }, + "Type": "AWS::IAM::Role", + }, + "GitHubCodeConnectionsHostCustomResource79EB46DC": { + "DeletionPolicy": "Delete", + "Properties": { + "Create": "{"service":"CodeConnections","action":"createHost","parameters":{"Name":"github.example.com","ProviderEndpoint":"https://github.example.com","ProviderType":"GitHub"},"physicalResourceId":{"responsePath":"HostArn"}}", + "Delete": "{"service":"CodeConnections","action":"deleteHost","parameters":{"HostArn":"PHYSICAL:RESOURCEID:"}}", + "InstallLatestAwsSdk": true, + "ServiceToken": { + "Fn::GetAtt": [ + "AWS679f53fac002430cb0da5b7982bd22872D164C4C", + "Arn", + ], + }, + "Update": "{"service":"CodeConnections","action":"updateHost","parameters":{"HostArn":"PHYSICAL:RESOURCEID:","ProviderEndpoint":"https://github.example.com"}}", + }, + "Type": "Custom::AWS", + "UpdateReplacePolicy": "Delete", + }, + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5", + ], + { + "Ref": "BootstrapVersion", + }, + ], + }, + ], + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI.", + }, + ], + }, + }, +} +`; diff --git a/test/__snapshots__/custom-resource.gitlab-self-managed.test.ts.snap b/test/__snapshots__/custom-resource.gitlab-self-managed.test.ts.snap new file mode 100644 index 0000000..d68e113 --- /dev/null +++ b/test/__snapshots__/custom-resource.gitlab-self-managed.test.ts.snap @@ -0,0 +1,133 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`CustomResource Testing Should match snapshot 1`] = ` +{ + "Parameters": { + "BootstrapVersion": { + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]", + "Type": "AWS::SSM::Parameter::Value", + }, + }, + "Resources": { + "AWS679f53fac002430cb0da5b7982bd22872D164C4C": { + "DependsOn": [ + "FunctionRole111A5701", + ], + "Properties": { + "Code": { + "S3Bucket": "cdk-hnb659fds-assets-123456789012-us-east-1", + "S3Key": "17c16a3854838fd3ff4bda08146122a6701f33b9c86ae17f415ad0dc47a97544.zip", + }, + "FunctionName": "custom-resource-codeconnection-host-eadb0d58-func", + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "FunctionRole111A5701", + "Arn", + ], + }, + "Runtime": "nodejs18.x", + "Timeout": 15, + }, + "Type": "AWS::Lambda::Function", + }, + "FunctionRole111A5701": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com", + }, + }, + ], + "Version": "2012-10-17", + }, + "Description": "Custom Resource Function Execution Role.", + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition", + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole", + ], + ], + }, + ], + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": [ + "codeconnections:CreateHost", + "codeconnections:UpdateHost", + "codeconnections:DeleteHost", + ], + "Effect": "Allow", + "Resource": "arn:aws:codeconnections:us-east-1:123456789012:*", + }, + ], + "Version": "2012-10-17", + }, + "PolicyName": "CustomResourcePolicy", + }, + ], + "RoleName": "custom-resource-codeconnection-host-eadb0d58-func-exc-role", + }, + "Type": "AWS::IAM::Role", + }, + "GitLabSelfManagedCodeConnectionsHostCustomResource31CD67FB": { + "DeletionPolicy": "Delete", + "Properties": { + "Create": "{"service":"CodeConnections","action":"createHost","parameters":{"Name":"gitlab.example.com","ProviderEndpoint":"https://gitlab.example.com","ProviderType":"GitLabSelfManaged"},"physicalResourceId":{"responsePath":"HostArn"}}", + "Delete": "{"service":"CodeConnections","action":"deleteHost","parameters":{"HostArn":"PHYSICAL:RESOURCEID:"}}", + "InstallLatestAwsSdk": true, + "ServiceToken": { + "Fn::GetAtt": [ + "AWS679f53fac002430cb0da5b7982bd22872D164C4C", + "Arn", + ], + }, + "Update": "{"service":"CodeConnections","action":"updateHost","parameters":{"HostArn":"PHYSICAL:RESOURCEID:","ProviderEndpoint":"https://gitlab.example.com"}}", + }, + "Type": "Custom::AWS", + "UpdateReplacePolicy": "Delete", + }, + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5", + ], + { + "Ref": "BootstrapVersion", + }, + ], + }, + ], + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI.", + }, + ], + }, + }, +} +`; diff --git a/test/__snapshots__/custom-resource.test.ts.snap b/test/__snapshots__/custom-resource.gitlab.test.ts.snap similarity index 98% rename from test/__snapshots__/custom-resource.test.ts.snap rename to test/__snapshots__/custom-resource.gitlab.test.ts.snap index 3e4bf05..d393bc5 100644 --- a/test/__snapshots__/custom-resource.test.ts.snap +++ b/test/__snapshots__/custom-resource.gitlab.test.ts.snap @@ -32,23 +32,6 @@ exports[`CustomResource Testing Should match snapshot 1`] = ` }, "Type": "AWS::Lambda::Function", }, - "CodeConnectionsHostCustomResourceA0D203C1": { - "DeletionPolicy": "Delete", - "Properties": { - "Create": "{"service":"CodeConnections","action":"createHost","parameters":{"Name":"gitlab.example.com","ProviderEndpoint":"https://gitlab.example.com","ProviderType":"GitLabSelfManaged"},"physicalResourceId":{"responsePath":"HostArn"}}", - "Delete": "{"service":"CodeConnections","action":"deleteHost","parameters":{"HostArn":"PHYSICAL:RESOURCEID:"}}", - "InstallLatestAwsSdk": true, - "ServiceToken": { - "Fn::GetAtt": [ - "AWS679f53fac002430cb0da5b7982bd22872D164C4C", - "Arn", - ], - }, - "Update": "{"service":"CodeConnections","action":"updateHost","parameters":{"HostArn":"PHYSICAL:RESOURCEID:","ProviderEndpoint":"https://gitlab.example.com"}}", - }, - "Type": "Custom::AWS", - "UpdateReplacePolicy": "Delete", - }, "FunctionRole111A5701": { "Properties": { "AssumeRolePolicyDocument": { @@ -101,6 +84,23 @@ exports[`CustomResource Testing Should match snapshot 1`] = ` }, "Type": "AWS::IAM::Role", }, + "GitLabCodeConnectionsHostCustomResource84EEAEED": { + "DeletionPolicy": "Delete", + "Properties": { + "Create": "{"service":"CodeConnections","action":"createHost","parameters":{"Name":"gitlab.example.com","ProviderEndpoint":"https://gitlab.example.com","ProviderType":"GitLabSelfManaged"},"physicalResourceId":{"responsePath":"HostArn"}}", + "Delete": "{"service":"CodeConnections","action":"deleteHost","parameters":{"HostArn":"PHYSICAL:RESOURCEID:"}}", + "InstallLatestAwsSdk": true, + "ServiceToken": { + "Fn::GetAtt": [ + "AWS679f53fac002430cb0da5b7982bd22872D164C4C", + "Arn", + ], + }, + "Update": "{"service":"CodeConnections","action":"updateHost","parameters":{"HostArn":"PHYSICAL:RESOURCEID:","ProviderEndpoint":"https://gitlab.example.com"}}", + }, + "Type": "Custom::AWS", + "UpdateReplacePolicy": "Delete", + }, }, "Rules": { "CheckBootstrapVersion": { From 7a7a55aae4cd549e7a9d500395b2a0fe0c3a3dc5 Mon Sep 17 00:00:00 2001 From: yicr Date: Wed, 2 Oct 2024 15:17:05 +0900 Subject: [PATCH 3/6] fix: enum to ALL_CAPS --- src/index.ts | 10 +++++----- test/custom-resource.bitbucket.test.ts | 2 +- test/custom-resource.github-enterprise.test.ts | 2 +- test/custom-resource.github.test.ts | 2 +- test/custom-resource.gitlab-self-managed.test.ts | 2 +- test/custom-resource.gitlab.test.ts | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/index.ts b/src/index.ts index 54d9aa7..b5a0410 100644 --- a/src/index.ts +++ b/src/index.ts @@ -6,11 +6,11 @@ import { Construct } from 'constructs'; // Bitbucket | GitHub | GitHubEnterpriseServer | GitLab | GitLabSelfManaged export enum CodeConnectionsHostProviderType { - Bitbucket = 'Bitbucket', - GitHub = 'GitHub', - GitHubEnterpriseServer = 'GitHubEnterpriseServer', - GitLab = 'GitLab', - GitLabSelfManaged = 'GitLabSelfManaged', + BIT_BUCKET = 'Bitbucket', + GIT_HUB = 'GitHub', + GIT_HUB_ENTERPRISE_SERVER = 'GitHubEnterpriseServer', + GIT_LAB = 'GitLab', + GIT_LAB_SELF_MANAGED = 'GitLabSelfManaged', } export interface CodeConnectionsHostCustomResourceProps { diff --git a/test/custom-resource.bitbucket.test.ts b/test/custom-resource.bitbucket.test.ts index 940a1dd..aaf79bb 100644 --- a/test/custom-resource.bitbucket.test.ts +++ b/test/custom-resource.bitbucket.test.ts @@ -16,7 +16,7 @@ describe('CustomResource Testing', () => { const bitbucketConnectionHostCustomResource = new CodeConnectionsHostCustomResource(stack, 'BitBucketCodeConnectionsHostCustomResource', { name: 'bitbucket.example.com', providerEndpoint: 'https://bitbucket.example.com', - providerType: CodeConnectionsHostProviderType.Bitbucket, + providerType: CodeConnectionsHostProviderType.BIT_BUCKET, }); const template = Template.fromStack(stack); diff --git a/test/custom-resource.github-enterprise.test.ts b/test/custom-resource.github-enterprise.test.ts index d2cee14..8e269d4 100644 --- a/test/custom-resource.github-enterprise.test.ts +++ b/test/custom-resource.github-enterprise.test.ts @@ -16,7 +16,7 @@ describe('CustomResource Testing', () => { const gitHubEnterpriseConnectionHostCustomResource = new CodeConnectionsHostCustomResource(stack, 'GitHibEnterpriseCodeConnectionsHostCustomResource', { name: 'github.example.com', providerEndpoint: 'https://github.example.com', - providerType: CodeConnectionsHostProviderType.GitHubEnterpriseServer, + providerType: CodeConnectionsHostProviderType.GIT_HUB_ENTERPRISE_SERVER, }); const template = Template.fromStack(stack); diff --git a/test/custom-resource.github.test.ts b/test/custom-resource.github.test.ts index 12e7c82..6edd41c 100644 --- a/test/custom-resource.github.test.ts +++ b/test/custom-resource.github.test.ts @@ -16,7 +16,7 @@ describe('CustomResource Testing', () => { const gitHubConnectionHostCustomResource = new CodeConnectionsHostCustomResource(stack, 'GitHubCodeConnectionsHostCustomResource', { name: 'github.example.com', providerEndpoint: 'https://github.example.com', - providerType: CodeConnectionsHostProviderType.GitHub, + providerType: CodeConnectionsHostProviderType.GIT_HUB, }); const template = Template.fromStack(stack); diff --git a/test/custom-resource.gitlab-self-managed.test.ts b/test/custom-resource.gitlab-self-managed.test.ts index 573d5de..f73cb22 100644 --- a/test/custom-resource.gitlab-self-managed.test.ts +++ b/test/custom-resource.gitlab-self-managed.test.ts @@ -16,7 +16,7 @@ describe('CustomResource Testing', () => { const gitLabSelfManagedConnectionHostCustomResource = new CodeConnectionsHostCustomResource(stack, 'GitLabSelfManagedCodeConnectionsHostCustomResource', { name: 'gitlab.example.com', providerEndpoint: 'https://gitlab.example.com', - providerType: CodeConnectionsHostProviderType.GitLabSelfManaged, + providerType: CodeConnectionsHostProviderType.GIT_LAB_SELF_MANAGED, }); const template = Template.fromStack(stack); diff --git a/test/custom-resource.gitlab.test.ts b/test/custom-resource.gitlab.test.ts index b7cb3d9..1da451c 100644 --- a/test/custom-resource.gitlab.test.ts +++ b/test/custom-resource.gitlab.test.ts @@ -16,7 +16,7 @@ describe('CustomResource Testing', () => { const gitLabConnectionHostCustomResource = new CodeConnectionsHostCustomResource(stack, 'GitLabCodeConnectionsHostCustomResource', { name: 'gitlab.example.com', providerEndpoint: 'https://gitlab.example.com', - providerType: CodeConnectionsHostProviderType.GitLabSelfManaged, + providerType: CodeConnectionsHostProviderType.GIT_LAB, }); const template = Template.fromStack(stack); From a364abe59c26007025abc0b9e0258663aa20c6c2 Mon Sep 17 00:00:00 2001 From: yicr Date: Wed, 2 Oct 2024 15:18:00 +0900 Subject: [PATCH 4/6] chore(test): update snapshots --- test/__snapshots__/custom-resource.gitlab.test.ts.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/__snapshots__/custom-resource.gitlab.test.ts.snap b/test/__snapshots__/custom-resource.gitlab.test.ts.snap index d393bc5..e5f5548 100644 --- a/test/__snapshots__/custom-resource.gitlab.test.ts.snap +++ b/test/__snapshots__/custom-resource.gitlab.test.ts.snap @@ -87,7 +87,7 @@ exports[`CustomResource Testing Should match snapshot 1`] = ` "GitLabCodeConnectionsHostCustomResource84EEAEED": { "DeletionPolicy": "Delete", "Properties": { - "Create": "{"service":"CodeConnections","action":"createHost","parameters":{"Name":"gitlab.example.com","ProviderEndpoint":"https://gitlab.example.com","ProviderType":"GitLabSelfManaged"},"physicalResourceId":{"responsePath":"HostArn"}}", + "Create": "{"service":"CodeConnections","action":"createHost","parameters":{"Name":"gitlab.example.com","ProviderEndpoint":"https://gitlab.example.com","ProviderType":"GitLab"},"physicalResourceId":{"responsePath":"HostArn"}}", "Delete": "{"service":"CodeConnections","action":"deleteHost","parameters":{"HostArn":"PHYSICAL:RESOURCEID:"}}", "InstallLatestAwsSdk": true, "ServiceToken": { From 046e379e69a3b3fbf00403674c6ba80fa10e9b2e Mon Sep 17 00:00:00 2001 From: yicr Date: Wed, 2 Oct 2024 15:18:30 +0900 Subject: [PATCH 5/6] chore(docs): update auto generated api document --- API.md | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) diff --git a/API.md b/API.md index 089744e..66c4e42 100644 --- a/API.md +++ b/API.md @@ -200,7 +200,7 @@ const codeConnectionsHostCustomResourceProps: CodeConnectionsHostCustomResourceP | --- | --- | --- | | name | string | *No description.* | | providerEndpoint | string | *No description.* | -| providerType | string | *No description.* | +| providerType | CodeConnectionsHostProviderType | *No description.* | --- @@ -227,12 +227,52 @@ public readonly providerEndpoint: string; ##### `providerType`Required ```typescript -public readonly providerType: string; +public readonly providerType: CodeConnectionsHostProviderType; ``` -- *Type:* string +- *Type:* CodeConnectionsHostProviderType + +--- + + + +## Enums + +### CodeConnectionsHostProviderType + +#### Members + +| **Name** | **Description** | +| --- | --- | +| BIT_BUCKET | *No description.* | +| GIT_HUB | *No description.* | +| GIT_HUB_ENTERPRISE_SERVER | *No description.* | +| GIT_LAB | *No description.* | +| GIT_LAB_SELF_MANAGED | *No description.* | + +--- + +##### `BIT_BUCKET` --- +##### `GIT_HUB` + +--- + + +##### `GIT_HUB_ENTERPRISE_SERVER` + +--- + + +##### `GIT_LAB` + +--- + + +##### `GIT_LAB_SELF_MANAGED` + +--- From 0017a61d9ee39340358f1f50da596748198cda70 Mon Sep 17 00:00:00 2001 From: yicr Date: Wed, 2 Oct 2024 15:24:33 +0900 Subject: [PATCH 6/6] chore(docs): update readme(update example) --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 098c909..6532114 100644 --- a/README.md +++ b/README.md @@ -28,12 +28,12 @@ yarn add @gammarers/aws-codeconnections-host-custom-resource ## Example ```typescript -import { RDSDatabaseAutoRunningStopStack } from '@gammarers/aws-codeconnections-host-custom-resource'; +import { RDSDatabaseAutoRunningStopStack, CodeConnectionsHostProviderType } from '@gammarers/aws-codeconnections-host-custom-resource'; const codeConnectionsHostCustomResource = new CodeConnectionsHostCustomResource(this, 'CodeConnectionsHost', { name: 'gitlab.example.com', // required, connection host name (Minimum length of 1. Maximum length of 64.) providerEndpoint: 'https://gitlab.example.com', // required, your provider endpoint (Minimum length of 1. Maximum length of 512.) - providerType: 'GitLabSelfManaged', // required, Bitbucket | GitHub | GitHubEnterpriseServer | GitLab | GitLabSelfManaged + providerType: CodeConnectionsHostProviderType.GIT_LAB_SELF_MANAGED, }); // get host arn