Skip to content

Commit a3f679e

Browse files
author
Niranjan Jayakar
authored
Merge branch 'master' into DerkSchooltink/lambda-ruby-2.7-support
2 parents 0c653c0 + 8770934 commit a3f679e

File tree

91 files changed

+3396
-224
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

91 files changed

+3396
-224
lines changed

packages/@aws-cdk/assert/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"cdk-build-tools": "0.0.0",
3434
"jest": "^24.9.0",
3535
"pkglint": "0.0.0",
36-
"ts-jest": "^25.2.0"
36+
"ts-jest": "^25.3.0"
3737
},
3838
"dependencies": {
3939
"@aws-cdk/cloudformation-diff": "0.0.0",

packages/@aws-cdk/assets/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"@aws-cdk/assert": "0.0.0",
6767
"@types/minimatch": "^3.0.3",
6868
"@types/nodeunit": "^0.0.30",
69-
"@types/sinon": "^7.5.2",
69+
"@types/sinon": "^9.0.0",
7070
"aws-cdk": "0.0.0",
7171
"cdk-build-tools": "0.0.0",
7272
"cdk-integ-tools": "0.0.0",

packages/@aws-cdk/aws-amplify/README.md

+19-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ import amplify = require('@aws-cdk/aws-amplify');
2727
import cdk = require('@aws-cdk/core');
2828

2929
const amplifyApp = new amplify.App(this, 'MyApp', {
30-
repository: 'https://github.com/<user>/<repo>',
31-
oauthToken: cdk.SecretValue.secretsManager('my-github-token'),
30+
sourceCodeProvider: new amplify.GitHubSourceCodeProvider({
31+
owner: '<user>',
32+
repository: '<repo>',
33+
oauthToken: cdk.SecretValue.secretsManager('my-github-token')
34+
}),
3235
buildSpec: codebuild.BuildSpec.fromObject({ // Alternatively add a `amplify.yml` to the repo
3336
version: '1.0',
3437
frontend: {
@@ -53,6 +56,20 @@ const amplifyApp = new amplify.App(this, 'MyApp', {
5356
});
5457
```
5558

59+
To connect your `App` to CodeCommit, use the `CodeCommitSourceCodeProvider`:
60+
```ts
61+
const repository = new codecommit.Repository(this, 'Repo', {
62+
repositoryName: 'my-repo'
63+
});
64+
65+
const amplifyApp = new amplify.App(this, 'App', {
66+
sourceCodeProvider: new amplify.CodeCommitSourceCodeProvider({ repository })
67+
});
68+
```
69+
70+
The IAM role associated with the `App` will automatically be granted the permission
71+
to pull the CodeCommit repository.
72+
5673
Add branches:
5774
```ts
5875
const master = amplifyApp.addBranch('master'); // `id` will be used as repo branch name

packages/@aws-cdk/aws-amplify/lib/app.ts

+52-35
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,69 @@ export interface IApp extends IResource {
2020
}
2121

2222
/**
23-
* Properties for an App
23+
* Configuration for the source code provider
2424
*/
25-
export interface AppProps {
25+
export interface SourceCodeProviderConfig {
26+
/**
27+
* The repository for the application. Must use the `HTTPS` protocol.
28+
*
29+
* @example https://github.com/aws/aws-cdk
30+
*/
31+
readonly repository: string;
32+
33+
/**
34+
* OAuth token for 3rd party source control system for an Amplify App, used
35+
* to create webhook and read-only deploy key. OAuth token is not stored.
36+
*
37+
* Either `accessToken` or `oauthToken` must be specified if `repository`
38+
* is sepcified.
39+
*
40+
* @default - do not use a token
41+
*/
42+
readonly oauthToken?: SecretValue;
43+
2644
/**
2745
* Personal Access token for 3rd party source control system for an Amplify
2846
* App, used to create webhook and read-only deploy key. Token is not stored.
2947
*
3048
* Either `accessToken` or `oauthToken` must be specified if `repository`
3149
* is sepcified.
3250
*
33-
* @default - use OAuth token
51+
* @default - do not use a token
3452
*/
3553
readonly accessToken?: SecretValue;
54+
}
55+
56+
/**
57+
* A source code provider
58+
*/
59+
export interface ISourceCodeProvider {
60+
/**
61+
* Binds the source code provider to an app
62+
*
63+
* @param app The app [disable-awslint:ref-via-interface]
64+
*/
65+
bind(app: App): SourceCodeProviderConfig;
66+
}
3667

68+
/**
69+
* Properties for an App
70+
*/
71+
export interface AppProps {
3772
/**
3873
* The name for the application
3974
*
4075
* @default - a CDK generated name
4176
*/
4277
readonly appName?: string;
4378

79+
/**
80+
* The source code provider for this application
81+
*
82+
* @default - not connected to a source code provider
83+
*/
84+
readonly sourceCodeProvider?: ISourceCodeProvider;
85+
4486
/**
4587
* The auto branch creation configuration. Use this to automatically create
4688
* branches that match a certain pattern.
@@ -92,31 +134,12 @@ export interface AppProps {
92134
readonly environmentVariables?: { [name: string]: string };
93135

94136
/**
95-
* The IAM service role to associate with the application
137+
* The IAM service role to associate with the application. The App
138+
* implements IGrantable.
96139
*
97140
* @default - a new role is created
98141
*/
99142
readonly role?: iam.IRole;
100-
101-
/**
102-
* OAuth token for 3rd party source control system for an Amplify App, used
103-
* to create webhook and read-only deploy key. OAuth token is not stored.
104-
*
105-
* Either `accessToken` or `oauthToken` must be specified if `repository`
106-
* is sepcified.
107-
*
108-
* @default - use access token
109-
*/
110-
readonly oauthToken?: SecretValue;
111-
112-
/**
113-
* The repository for the application. Must use the `HTTPS` protocol.
114-
*
115-
* @example https://github.com/aws/aws-cdk
116-
*
117-
* @default - not connected to a repository
118-
*/
119-
readonly repository?: string;
120143
}
121144

122145
/**
@@ -168,14 +191,6 @@ export class App extends Resource implements IApp, iam.IGrantable {
168191
constructor(scope: Construct, id: string, props: AppProps) {
169192
super(scope, id);
170193

171-
if (props.repository && !props.accessToken && !props.oauthToken) {
172-
throw new Error('Either `accessToken` or `oauthToken` must be specified');
173-
}
174-
175-
if (props.repository && !props.repository.startsWith('https://')) {
176-
throw new Error('`repository` must use the HTTPS protocol');
177-
}
178-
179194
this.customRules = props.customRules || [];
180195
this.environmentVariables = props.environmentVariables || {};
181196
this.autoBranchEnvironmentVariables = props.autoBranchCreation && props.autoBranchCreation.environmentVariables || {};
@@ -185,8 +200,10 @@ export class App extends Resource implements IApp, iam.IGrantable {
185200
});
186201
this.grantPrincipal = role;
187202

203+
const sourceCodeProviderOptions = props.sourceCodeProvider?.bind(this);
204+
188205
const app = new CfnApp(this, 'Resource', {
189-
accessToken: props.accessToken && props.accessToken.toString(),
206+
accessToken: sourceCodeProviderOptions?.accessToken?.toString(),
190207
autoBranchCreationConfig: props.autoBranchCreation && {
191208
autoBranchCreationPatterns: props.autoBranchCreation.patterns,
192209
basicAuthConfig: props.autoBranchCreation.basicAuth && props.autoBranchCreation.basicAuth.bind(this, 'BranchBasicAuth'),
@@ -205,8 +222,8 @@ export class App extends Resource implements IApp, iam.IGrantable {
205222
environmentVariables: Lazy.anyValue({ produce: () => renderEnvironmentVariables(this.environmentVariables) }, { omitEmptyArray: true }),
206223
iamServiceRole: role.roleArn,
207224
name: props.appName || this.node.id,
208-
oauthToken: props.oauthToken && props.oauthToken.toString(),
209-
repository: props.repository,
225+
oauthToken: sourceCodeProviderOptions?.oauthToken?.toString(),
226+
repository: sourceCodeProviderOptions?.repository,
210227
});
211228

212229
this.appId = app.attrAppId;

packages/@aws-cdk/aws-amplify/lib/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export * from './app';
22
export * from './branch';
33
export * from './domain';
44
export * from './basic-auth';
5+
export * from './source-code-providers';
56

67
// AWS::Amplify CloudFormation Resources:
78
export * from './amplify.generated';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import * as codecommit from '@aws-cdk/aws-codecommit';
2+
import { SecretValue } from '@aws-cdk/core';
3+
import { App, ISourceCodeProvider, SourceCodeProviderConfig } from './app';
4+
5+
/**
6+
* Properties for a GitHub source code provider
7+
*/
8+
export interface GitHubSourceCodeProviderProps {
9+
/**
10+
* The user or organization owning the repository
11+
*/
12+
readonly owner: string;
13+
14+
/**
15+
* The name of the repository
16+
*/
17+
readonly repository: string;
18+
19+
/**
20+
* A personal access token with the `repo` scope
21+
*/
22+
readonly oauthToken: SecretValue;
23+
}
24+
25+
/**
26+
* GitHub source code provider
27+
*/
28+
export class GitHubSourceCodeProvider implements ISourceCodeProvider {
29+
constructor(private readonly props: GitHubSourceCodeProviderProps) {}
30+
31+
public bind(_app: App): SourceCodeProviderConfig {
32+
return {
33+
repository: `https://github.com/${this.props.owner}/${this.props.repository}`,
34+
oauthToken: this.props.oauthToken
35+
};
36+
}
37+
}
38+
39+
/**
40+
* Properties for a CodeCommit source code provider
41+
*/
42+
export interface CodeCommitSourceCodeProviderProps {
43+
/**
44+
* The CodeCommit repository
45+
*/
46+
readonly repository: codecommit.IRepository;
47+
}
48+
49+
/**
50+
* CodeCommit source code provider
51+
*/
52+
export class CodeCommitSourceCodeProvider implements ISourceCodeProvider {
53+
constructor(private readonly props: CodeCommitSourceCodeProviderProps) {}
54+
55+
public bind(app: App): SourceCodeProviderConfig {
56+
this.props.repository.grantPull(app);
57+
58+
return {
59+
repository: this.props.repository.repositoryCloneUrlHttp
60+
};
61+
}
62+
}

packages/@aws-cdk/aws-amplify/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
"@aws-cdk/aws-iam": "0.0.0",
9292
"@aws-cdk/aws-kms": "0.0.0",
9393
"@aws-cdk/aws-codebuild": "0.0.0",
94+
"@aws-cdk/aws-codecommit": "0.0.0",
9495
"@aws-cdk/aws-secretsmanager": "0.0.0",
9596
"@aws-cdk/core": "0.0.0",
9697
"constructs": "^2.0.0"
@@ -99,6 +100,7 @@
99100
"@aws-cdk/aws-iam": "0.0.0",
100101
"@aws-cdk/aws-kms": "0.0.0",
101102
"@aws-cdk/aws-codebuild": "0.0.0",
103+
"@aws-cdk/aws-codecommit": "0.0.0",
102104
"@aws-cdk/aws-secretsmanager": "0.0.0",
103105
"@aws-cdk/core": "0.0.0",
104106
"constructs": "^2.0.0"

0 commit comments

Comments
 (0)