Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#907 Adds oauth token as param to codebuild.GitHubEnterpriseSource #908

Merged
merged 4 commits into from
Oct 12, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/@aws-cdk/aws-codebuild/lib/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,20 @@ export class GitHubSource extends BuildSource {
}

/**
* GitHub Enterprice Source definition for a CodeBuild project
* GitHub Enterprise Source definition for a CodeBuild project
*/
export class GitHubEnterpriseSource extends BuildSource {
constructor(private readonly cloneUrl: string) {
constructor(private readonly cloneUrl: string, private readonly oauthToken: any) {
Copy link
Contributor Author

@eaddingtonwhite eaddingtonwhite Oct 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was not sure if I should make oauthToken optional?

constructor(private readonly cloneUrl: string, private readonly oauthToken?: any) {

I was mostly copying how it was done w/ GitHubSource but now this is breaking change I believe.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skinny85 - should the token be any?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Going by the GitHub CodePipeline Action example, it seems like oauthToken should be a cdk.Secret.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super();
this.cloneUrl = cloneUrl;
this.oauthToken = oauthToken;
}

public toSourceJSON(): cloudformation.ProjectResource.SourceProperty {
return {
type: SourceType.GitHubEnterPrise,
location: this.cloneUrl,
auth: this.oauthToken != null ? { type: 'OAUTH', resource: this.oauthToken } : undefined,
};
}
}
Expand Down
36 changes: 31 additions & 5 deletions packages/@aws-cdk/aws-codebuild/test/test.project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export = {
// WHEN
new codebuild.Project(stack, 'Project', {
source: new codebuild.CodePipelineSource(),
buildSpec: { phases: [ 'say hi' ] }
buildSpec: { phases: ['say hi'] }
});

// THEN
Expand All @@ -47,6 +47,30 @@ export = {
test.done();
},

'github enterprise auth test'(test: Test) {
// GIVEN
const stack = new cdk.Stack();

// WHEN
new codebuild.Project(stack, 'Project', {
source: new codebuild.GitHubEnterpriseSource("https://mycompany.github.com", "my_oauth_token")
});

// THEN
expect(stack).to(haveResource('AWS::CodeBuild::Project', {
Source: {
Type: "GITHUB_ENTERPRISE",
Auth: {
Type: 'OAUTH',
Resource: 'my_oauth_token'
},
Location: 'https://mycompany.github.com'
}
}));

test.done();
},

'construct from asset'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
Expand All @@ -70,10 +94,12 @@ export = {
{
Name: "SCRIPT_S3_KEY",
Type: "PLAINTEXT",
Value: { "Fn::Join": [ "", [
{ "Fn::Select": [ 0, { "Fn::Split": [ "||", { Ref: "AssetS3VersionKeyA852DDAE" } ] } ] },
{ "Fn::Select": [ 1, { "Fn::Split": [ "||", { Ref: "AssetS3VersionKeyA852DDAE" } ] } ] }
] ] }
Value: {
"Fn::Join": ["", [
{ "Fn::Select": [0, { "Fn::Split": ["||", { Ref: "AssetS3VersionKeyA852DDAE" }] }] },
{ "Fn::Select": [1, { "Fn::Split": ["||", { Ref: "AssetS3VersionKeyA852DDAE" }] }] }
]]
}
}
],
},
Expand Down