-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,17 +5,18 @@ const { | |
const AWS_CDK_LATEST_RELEASE = '2.0.0-rc.19'; | ||
|
||
const PROJECT_NAME = 'cdk-codepipeline-bitbucket-build-result-reporter'; | ||
const PROJECT_DESCRIPTION = 'A JSII construct lib for reporting AWS CodePipeline build statuses to a Bitbucket server instance'; | ||
const PROJECT_DESCRIPTION = 'A JSII construct lib for reporting AWS CodePipeline and build statuses to a Bitbucket server instance'; | ||
|
||
const project = new AwsCdkConstructLibrary({ | ||
name: PROJECT_NAME, | ||
description: PROJECT_DESCRIPTION, | ||
authorName: 'Markus', | ||
authorName: 'Markus Lindqvist', | ||
authorEmail: '[email protected]', | ||
stability: 'stable', | ||
repository: 'https://github.com/markusl/cdk-codepipeline-bitbucket-build-result-reporter.git', | ||
cdkVersion: AWS_CDK_LATEST_RELEASE, | ||
defaultReleaseBranch: 'master', | ||
minNodeVersion: '14.15.0', | ||
tsconfig: { | ||
compilerOptions: { | ||
lib: ['ES2019'], | ||
|
@@ -27,10 +28,12 @@ const project = new AwsCdkConstructLibrary({ | |
devDeps: [ | ||
'@types/aws-lambda', | ||
'@types/node-fetch', | ||
'aws-sdk-client-mock', | ||
'esbuild', | ||
'[email protected]', | ||
], | ||
bundledDeps: [ | ||
'@aws-sdk/client-iam', | ||
'@aws-sdk/client-ssm', | ||
'@aws-sdk/client-codebuild', | ||
'@aws-sdk/client-codepipeline', | ||
|
@@ -40,7 +43,6 @@ const project = new AwsCdkConstructLibrary({ | |
}); | ||
|
||
const common_exclude = [ | ||
'.cdk.staging', | ||
'cdk.context.json', | ||
'cdk.out', | ||
'coverage', | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as IAM from '@aws-sdk/client-iam'; | ||
|
||
const iam = new IAM.IAMClient({}); | ||
|
||
export const getCurrentAccountAlias = async (accountId: string) => { | ||
try { | ||
const aliases = await iam.send(new IAM.ListAccountAliasesCommand({})); | ||
if (aliases.AccountAliases && aliases.AccountAliases.length > 0) { | ||
return aliases.AccountAliases[0]; | ||
} | ||
return accountId; | ||
} catch (err) { | ||
console.error(err); | ||
return accountId; | ||
} | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import * as SSM from '@aws-sdk/client-ssm'; | ||
import { mockClient } from 'aws-sdk-client-mock'; | ||
import '@aws-cdk/assert/jest'; | ||
import { getToken } from '../src/bitbucket'; | ||
|
||
const ssmMock = mockClient(SSM.SSMClient); | ||
|
||
const paramName = 'EXAMPLE_TOKEN'; | ||
const exampleToken = 'frhWbyXaEPprfZRZXiuCUfmwMr6a0SAchp1JINHW7tXN21RZjF5jTcKaRr9kbm2'; | ||
|
||
test('getToken returns the token', async () => { | ||
ssmMock.on(SSM.GetParameterCommand, { | ||
Name: paramName, | ||
}).resolves({ | ||
Parameter: { | ||
Value: exampleToken, | ||
}, | ||
}); | ||
|
||
expect(await getToken(paramName)).toBe(exampleToken); | ||
}); | ||
|
||
test('getToken fails with incorrect token', async () => { | ||
ssmMock.on(SSM.GetParameterCommand, { | ||
Name: paramName, | ||
}).resolves({ | ||
Parameter: { | ||
Value: exampleToken, | ||
}, | ||
}); | ||
|
||
await expect(getToken('invalid-token')).rejects.toThrow(/Cannot fetch token/); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import * as IAM from '@aws-sdk/client-iam'; | ||
import { mockClient } from 'aws-sdk-client-mock'; | ||
import '@aws-cdk/assert/jest'; | ||
import { getCurrentAccountAlias } from '../src/iam-helper'; | ||
|
||
const iamMock = mockClient(IAM.IAMClient); | ||
|
||
test('getCurrentAccountAlias returns account alias', async () => { | ||
iamMock.on(IAM.ListAccountAliasesCommand).resolves({ | ||
AccountAliases: [ | ||
'account-alias', | ||
], | ||
}); | ||
|
||
expect(await getCurrentAccountAlias('0987654321')).toBe('account-alias'); | ||
}); | ||
|
||
test('getCurrentAccountAlias returns account id if no aliases found', async () => { | ||
iamMock.on(IAM.ListAccountAliasesCommand).resolves({ | ||
AccountAliases: [], | ||
}); | ||
|
||
expect(await getCurrentAccountAlias('0987654321')).toBe('0987654321'); | ||
}); | ||
|
||
test('getCurrentAccountAlias handles promise rejection', async () => { | ||
iamMock.on(IAM.ListAccountAliasesCommand).rejects(); | ||
|
||
expect(await getCurrentAccountAlias('0987654321')).toBe('0987654321'); | ||
}); |