bugfix(code-commit-integration): Fix host for codecommit integrations
Signed-off-by: Stijn Brouwers (EISMEA) <stijn@bdcommit.com>
This commit is contained in:
committed by
blam
parent
6f5b034465
commit
dcb75ee4c0
@@ -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).
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
@@ -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([]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user