File tree Expand file tree Collapse file tree 2 files changed +26
-2
lines changed
packages/@aws-cdk/aws-ecr-assets Expand file tree Collapse file tree 2 files changed +26
-2
lines changed Original file line number Diff line number Diff line change @@ -70,8 +70,8 @@ export class DockerImageAsset extends cdk.Construct implements assets.IAsset {
70
70
constructor ( scope : cdk . Construct , id : string , props : DockerImageAssetProps ) {
71
71
super ( scope , id ) ;
72
72
73
- // verify buildArgs do not use tokens in neither keys nor values
74
- validateBuildArgs ( props . buildArgs ) ;
73
+ // none of the properties use tokens
74
+ validateProps ( props ) ;
75
75
76
76
// resolve full path
77
77
const dir = path . resolve ( props . directory ) ;
@@ -134,6 +134,16 @@ export class DockerImageAsset extends cdk.Construct implements assets.IAsset {
134
134
}
135
135
}
136
136
137
+ function validateProps ( props : DockerImageAssetProps ) {
138
+ for ( const [ key , value ] of Object . entries ( props ) ) {
139
+ if ( Token . isUnresolved ( value ) ) {
140
+ throw new Error ( `Cannot use Token as value of '${ key } ': this value is used before deployment starts` ) ;
141
+ }
142
+ }
143
+
144
+ validateBuildArgs ( props . buildArgs ) ;
145
+ }
146
+
137
147
function validateBuildArgs ( buildArgs ?: { [ key : string ] : string } ) {
138
148
for ( const [ key , value ] of Object . entries ( buildArgs || { } ) ) {
139
149
if ( Token . isUnresolved ( key ) || Token . isUnresolved ( value ) ) {
Original file line number Diff line number Diff line change @@ -233,6 +233,20 @@ export = {
233
233
buildArgs : { key : token }
234
234
} ) , expected ) ;
235
235
236
+ test . done ( ) ;
237
+ } ,
238
+
239
+ 'fails if using token as repositoryName' ( test : Test ) {
240
+ // GIVEN
241
+ const stack = new Stack ( ) ;
242
+ const token = Lazy . stringValue ( { produce : ( ) => 'foo' } ) ;
243
+
244
+ // THEN
245
+ test . throws ( ( ) => new DockerImageAsset ( stack , 'MyAsset1' , {
246
+ directory : path . join ( __dirname , 'demo-image' ) ,
247
+ repositoryName : token
248
+ } ) , / C a n n o t u s e T o k e n a s v a l u e o f ' r e p o s i t o r y N a m e ' / ) ;
249
+
236
250
test . done ( ) ;
237
251
}
238
252
} ;
You can’t perform that action at this time.
0 commit comments