@@ -20,27 +20,69 @@ export interface IApp extends IResource {
20
20
}
21
21
22
22
/**
23
- * Properties for an App
23
+ * Configuration for the source code provider
24
24
*/
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
+
26
44
/**
27
45
* Personal Access token for 3rd party source control system for an Amplify
28
46
* App, used to create webhook and read-only deploy key. Token is not stored.
29
47
*
30
48
* Either `accessToken` or `oauthToken` must be specified if `repository`
31
49
* is sepcified.
32
50
*
33
- * @default - use OAuth token
51
+ * @default - do not use a token
34
52
*/
35
53
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
+ }
36
67
68
+ /**
69
+ * Properties for an App
70
+ */
71
+ export interface AppProps {
37
72
/**
38
73
* The name for the application
39
74
*
40
75
* @default - a CDK generated name
41
76
*/
42
77
readonly appName ?: string ;
43
78
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
+
44
86
/**
45
87
* The auto branch creation configuration. Use this to automatically create
46
88
* branches that match a certain pattern.
@@ -92,31 +134,12 @@ export interface AppProps {
92
134
readonly environmentVariables ?: { [ name : string ] : string } ;
93
135
94
136
/**
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.
96
139
*
97
140
* @default - a new role is created
98
141
*/
99
142
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 ;
120
143
}
121
144
122
145
/**
@@ -168,14 +191,6 @@ export class App extends Resource implements IApp, iam.IGrantable {
168
191
constructor ( scope : Construct , id : string , props : AppProps ) {
169
192
super ( scope , id ) ;
170
193
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
-
179
194
this . customRules = props . customRules || [ ] ;
180
195
this . environmentVariables = props . environmentVariables || { } ;
181
196
this . autoBranchEnvironmentVariables = props . autoBranchCreation && props . autoBranchCreation . environmentVariables || { } ;
@@ -185,8 +200,10 @@ export class App extends Resource implements IApp, iam.IGrantable {
185
200
} ) ;
186
201
this . grantPrincipal = role ;
187
202
203
+ const sourceCodeProviderOptions = props . sourceCodeProvider ?. bind ( this ) ;
204
+
188
205
const app = new CfnApp ( this , 'Resource' , {
189
- accessToken : props . accessToken && props . accessToken . toString ( ) ,
206
+ accessToken : sourceCodeProviderOptions ? .accessToken ? .toString ( ) ,
190
207
autoBranchCreationConfig : props . autoBranchCreation && {
191
208
autoBranchCreationPatterns : props . autoBranchCreation . patterns ,
192
209
basicAuthConfig : props . autoBranchCreation . basicAuth && props . autoBranchCreation . basicAuth . bind ( this , 'BranchBasicAuth' ) ,
@@ -205,8 +222,8 @@ export class App extends Resource implements IApp, iam.IGrantable {
205
222
environmentVariables : Lazy . anyValue ( { produce : ( ) => renderEnvironmentVariables ( this . environmentVariables ) } , { omitEmptyArray : true } ) ,
206
223
iamServiceRole : role . roleArn ,
207
224
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 ,
210
227
} ) ;
211
228
212
229
this . appId = app . attrAppId ;
0 commit comments