From dcb75ee4c0c8b1b36d809510a4c93e5ccc2b1b91 Mon Sep 17 00:00:00 2001 From: "Stijn Brouwers (EISMEA)" Date: Sat, 18 May 2024 09:00:33 +0200 Subject: [PATCH] bugfix(code-commit-integration): Fix host for codecommit integrations Signed-off-by: Stijn Brouwers (EISMEA) --- docs/integrations/aws-codecommit/locations.md | 8 +++---- .../AwsCodeCommitIntegration.test.ts | 15 ++++++------ .../src/awsCodeCommit/config.test.ts | 15 ++++++------ .../integration/src/awsCodeCommit/config.ts | 24 +++++++++---------- 4 files changed, 29 insertions(+), 33 deletions(-) diff --git a/docs/integrations/aws-codecommit/locations.md b/docs/integrations/aws-codecommit/locations.md index 05a13e5b21..c91c995289 100644 --- a/docs/integrations/aws-codecommit/locations.md +++ b/docs/integrations/aws-codecommit/locations.md @@ -20,7 +20,8 @@ To use this integration, add configuration to your `app-config.yaml`: ```yaml integrations: awsCodeCommit: - - accessKeyId: ${AWS_ACCESS_KEY_ID} + - region: eu-west-1 + accessKeyId: ${AWS_ACCESS_KEY_ID} secretAccessKey: ${AWS_SECRET_ACCESS_KEY} ``` @@ -34,10 +35,7 @@ instruct the AWS CodeCommit reader to assume a role before accessing CodeCommit: ```yaml integrations: awsCodeCommit: - - accessKeyId: ${AWS_ACCESS_KEY_ID} - secretAccessKey: ${AWS_SECRET_ACCESS_KEY} + - region: eu-west-1 roleArn: 'arn:aws:iam::xxxxxxxxxxxx:role/example-role' externalId: 'some-id' # optional ``` - -When no entries are added, the AWS CodeCommit reader will add a default entry that uses the [standard credentials provider chain](https://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/auth/DefaultAWSCredentialsProviderChain.html). diff --git a/packages/integration/src/awsCodeCommit/AwsCodeCommitIntegration.test.ts b/packages/integration/src/awsCodeCommit/AwsCodeCommitIntegration.test.ts index 14b3c6c73b..76ccd59af6 100644 --- a/packages/integration/src/awsCodeCommit/AwsCodeCommitIntegration.test.ts +++ b/packages/integration/src/awsCodeCommit/AwsCodeCommitIntegration.test.ts @@ -30,30 +30,29 @@ describe('AwsCodeCommitIntegration', () => { secretAccessKey: ' secret key ', roleArn: `role arn`, externalId: `external id`, + region: `region`, }, ], }, }), }); expect(integrations.list().length).toBe(1); // including default - expect(integrations.list()[0].config.host).toBe(AMAZON_AWS_CODECOMMIT_HOST); + expect(integrations.list()[0].config.host).toBe( + `region.${AMAZON_AWS_CODECOMMIT_HOST}`, + ); expect(integrations.list()[0].config.accessKeyId).toBe('access key'); expect(integrations.list()[0].config.secretAccessKey).toBe('secret key'); expect(integrations.list()[0].config.roleArn).toBe(`role arn`); expect(integrations.list()[0].config.externalId).toBe(`external id`); + expect(integrations.list()[0].config.region).toBe(`region`); }); - it('has a working factory with default values when no data provided', () => { + it('does not have a working factory with default values when no data provided', () => { const integrations = AwsCodeCommitIntegration.factory({ config: new ConfigReader({ integrations: {}, }), }); - expect(integrations.list().length).toBe(1); // including default - expect(integrations.list()[0].config.host).toBe(AMAZON_AWS_CODECOMMIT_HOST); - expect(integrations.list()[0].config.accessKeyId).toBeUndefined(); - expect(integrations.list()[0].config.secretAccessKey).toBeUndefined(); - expect(integrations.list()[0].config.roleArn).toBeUndefined(); - expect(integrations.list()[0].config.externalId).toBeUndefined(); + expect(integrations.list().length).toBe(0); // including default }); it('returns the basics', () => { diff --git a/packages/integration/src/awsCodeCommit/config.test.ts b/packages/integration/src/awsCodeCommit/config.test.ts index 217485b45e..637189f1f8 100644 --- a/packages/integration/src/awsCodeCommit/config.test.ts +++ b/packages/integration/src/awsCodeCommit/config.test.ts @@ -31,7 +31,8 @@ describe('readAwsCodeCommitIntegrationConfig', () => { it('reads all values (default)', () => { const output = readAwsCodeCommitIntegrationConfig(buildConfig({})); expect(output).toEqual({ - host: AMAZON_AWS_CODECOMMIT_HOST, + host: `us-east-1.${AMAZON_AWS_CODECOMMIT_HOST}`, + region: `us-east-1`, }); }); @@ -42,14 +43,16 @@ describe('readAwsCodeCommitIntegrationConfig', () => { secretAccessKey: 'fake-secret-key', externalId: 'fake-external-id', roleArn: 'fake-role-arn', + region: 'fake-region', }), ); expect(output).toEqual({ - host: AMAZON_AWS_CODECOMMIT_HOST, + host: `fake-region.${AMAZON_AWS_CODECOMMIT_HOST}`, accessKeyId: 'fake-key', secretAccessKey: 'fake-secret-key', externalId: 'fake-external-id', roleArn: 'fake-role-arn', + region: 'fake-region', }); }); }); @@ -70,6 +73,7 @@ describe('readAwsCodeCommitIntegrationConfigs', () => { secretAccessKey: 'secret', externalId: 'external-id', roleArn: 'role-arn', + region: 'region', }, ]), ); @@ -79,15 +83,12 @@ describe('readAwsCodeCommitIntegrationConfigs', () => { secretAccessKey: 'secret', externalId: 'external-id', roleArn: 'role-arn', + region: 'region', }); }); it('adds a default entry when missing', () => { const output = readAwsCodeCommitIntegrationConfigs(buildConfig([])); - expect(output).toEqual([ - { - host: AMAZON_AWS_CODECOMMIT_HOST, - }, - ]); + expect(output).toEqual([]); }); }); diff --git a/packages/integration/src/awsCodeCommit/config.ts b/packages/integration/src/awsCodeCommit/config.ts index 0ebd62519f..9b8acccb6f 100644 --- a/packages/integration/src/awsCodeCommit/config.ts +++ b/packages/integration/src/awsCodeCommit/config.ts @@ -48,6 +48,11 @@ export type AwsCodeCommitIntegrationConfig = { * (Optional) External ID to use when assuming role */ externalId?: string; + + /** + * region to use for AWS (default: us-east-1) + */ + region: string; }; /** @@ -64,7 +69,10 @@ export function readAwsCodeCommitIntegrationConfig( const secretAccessKey = config.getOptionalString('secretAccessKey')?.trim(); const roleArn = config.getOptionalString('roleArn'); const externalId = config.getOptionalString('externalId'); - const host = AMAZON_AWS_CODECOMMIT_HOST; + const region = config.getOptionalString('region') || 'us-east-1'; + const host = + config.getOptionalString('host') || + `${region}.${AMAZON_AWS_CODECOMMIT_HOST}`; return { host, @@ -72,6 +80,7 @@ export function readAwsCodeCommitIntegrationConfig( secretAccessKey, roleArn, externalId, + region, }; } @@ -85,16 +94,5 @@ export function readAwsCodeCommitIntegrationConfig( export function readAwsCodeCommitIntegrationConfigs( configs: Config[], ): AwsCodeCommitIntegrationConfig[] { - // First read all the explicit integrations - const result = configs.map(readAwsCodeCommitIntegrationConfig); - - // If no explicit console.aws.amazon.com integration was added, put one in the list as - // a convenience - if (!result.some(c => c.host === AMAZON_AWS_CODECOMMIT_HOST)) { - result.push({ - host: AMAZON_AWS_CODECOMMIT_HOST, - }); - } - - return result; + return configs.map(readAwsCodeCommitIntegrationConfig); }