Skip to content

Commit c23da91

Browse files
eaddingtonwhiteElad Ben-Israel
authored and
Elad Ben-Israel
committedOct 12, 2018
fix(aws-codebuild): allow passing oauth token to GitHubEnterpriseSource (#908)
1 parent 8b3ae43 commit c23da91

File tree

2 files changed

+87
-12
lines changed

2 files changed

+87
-12
lines changed
 

‎packages/@aws-cdk/aws-codebuild/lib/source.ts

+26-7
Original file line numberDiff line numberDiff line change
@@ -72,38 +72,57 @@ export class CodePipelineSource extends BuildSource {
7272
}
7373
}
7474

75+
export interface GithubSourceProps {
76+
/**
77+
* The git url to clone for this code build project.
78+
*/
79+
cloneUrl: string;
80+
81+
/**
82+
* The oAuthToken used to authenticate when cloning source git repo.
83+
*/
84+
oauthToken: cdk.Secret;
85+
86+
}
87+
7588
/**
7689
* GitHub Source definition for a CodeBuild project
7790
*/
7891
export class GitHubSource extends BuildSource {
79-
constructor(private readonly httpscloneUrl: string, private readonly oauthToken: any) {
92+
private cloneUrl: string;
93+
private oauthToken: cdk.Secret;
94+
constructor(props: GithubSourceProps) {
8095
super();
81-
this.httpscloneUrl = httpscloneUrl;
82-
this.oauthToken = oauthToken;
96+
this.cloneUrl = props.cloneUrl;
97+
this.oauthToken = props.oauthToken;
8398
}
8499

85100
public toSourceJSON(): cloudformation.ProjectResource.SourceProperty {
86101
return {
87102
type: SourceType.GitHub,
88103
auth: this.oauthToken != null ? { type: 'OAUTH', resource: this.oauthToken } : undefined,
89-
location: this.httpscloneUrl
104+
location: this.cloneUrl
90105
};
91106
}
92107
}
93108

94109
/**
95-
* GitHub Enterprice Source definition for a CodeBuild project
110+
* GitHub Enterprise Source definition for a CodeBuild project
96111
*/
97112
export class GitHubEnterpriseSource extends BuildSource {
98-
constructor(private readonly cloneUrl: string) {
113+
private cloneUrl: string;
114+
private oauthToken: cdk.Secret;
115+
constructor(props: GithubSourceProps) {
99116
super();
100-
this.cloneUrl = cloneUrl;
117+
this.cloneUrl = props.cloneUrl;
118+
this.oauthToken = props.oauthToken;
101119
}
102120

103121
public toSourceJSON(): cloudformation.ProjectResource.SourceProperty {
104122
return {
105123
type: SourceType.GitHubEnterPrise,
106124
location: this.cloneUrl,
125+
auth: this.oauthToken != null ? { type: 'OAUTH', resource: this.oauthToken } : undefined,
107126
};
108127
}
109128
}

‎packages/@aws-cdk/aws-codebuild/test/test.project.ts

+61-5
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export = {
3434
// WHEN
3535
new codebuild.Project(stack, 'Project', {
3636
source: new codebuild.CodePipelineSource(),
37-
buildSpec: { phases: [ 'say hi' ] }
37+
buildSpec: { phases: ['say hi'] }
3838
});
3939

4040
// THEN
@@ -47,6 +47,60 @@ export = {
4747
test.done();
4848
},
4949

50+
'github auth test'(test: Test) {
51+
// GIVEN
52+
const stack = new cdk.Stack();
53+
54+
// WHEN
55+
new codebuild.Project(stack, 'Project', {
56+
source: new codebuild.GitHubSource({
57+
cloneUrl: "https://github.com/testowner/testrepo",
58+
oauthToken: new cdk.Secret("test_oauth_token")
59+
})
60+
});
61+
62+
// THEN
63+
expect(stack).to(haveResource('AWS::CodeBuild::Project', {
64+
Source: {
65+
Type: "GITHUB",
66+
Auth: {
67+
Type: 'OAUTH',
68+
Resource: 'test_oauth_token'
69+
},
70+
Location: 'https://github.com/testowner/testrepo'
71+
}
72+
}));
73+
74+
test.done();
75+
},
76+
77+
'github enterprise auth test'(test: Test) {
78+
// GIVEN
79+
const stack = new cdk.Stack();
80+
81+
// WHEN
82+
new codebuild.Project(stack, 'Project', {
83+
source: new codebuild.GitHubEnterpriseSource({
84+
cloneUrl: "https://github.testcompany.com/testowner/testrepo",
85+
oauthToken: new cdk.Secret("test_oauth_token")
86+
})
87+
});
88+
89+
// THEN
90+
expect(stack).to(haveResource('AWS::CodeBuild::Project', {
91+
Source: {
92+
Type: "GITHUB_ENTERPRISE",
93+
Auth: {
94+
Type: 'OAUTH',
95+
Resource: 'test_oauth_token'
96+
},
97+
Location: 'https://github.testcompany.com/testowner/testrepo'
98+
}
99+
}));
100+
101+
test.done();
102+
},
103+
50104
'construct from asset'(test: Test) {
51105
// GIVEN
52106
const stack = new cdk.Stack();
@@ -70,10 +124,12 @@ export = {
70124
{
71125
Name: "SCRIPT_S3_KEY",
72126
Type: "PLAINTEXT",
73-
Value: { "Fn::Join": [ "", [
74-
{ "Fn::Select": [ 0, { "Fn::Split": [ "||", { Ref: "AssetS3VersionKeyA852DDAE" } ] } ] },
75-
{ "Fn::Select": [ 1, { "Fn::Split": [ "||", { Ref: "AssetS3VersionKeyA852DDAE" } ] } ] }
76-
] ] }
127+
Value: {
128+
"Fn::Join": ["", [
129+
{ "Fn::Select": [0, { "Fn::Split": ["||", { Ref: "AssetS3VersionKeyA852DDAE" }] }] },
130+
{ "Fn::Select": [1, { "Fn::Split": ["||", { Ref: "AssetS3VersionKeyA852DDAE" }] }] }
131+
]]
132+
}
77133
}
78134
],
79135
},

0 commit comments

Comments
 (0)