-
Notifications
You must be signed in to change notification settings - Fork 3.7k
/
cfn-parse.ts
676 lines (607 loc) · 24.2 KB
/
cfn-parse.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
import { CfnCondition } from './cfn-condition';
import { CfnElement } from './cfn-element';
import { Fn } from './cfn-fn';
import { CfnMapping } from './cfn-mapping';
import { Aws } from './cfn-pseudo';
import { CfnResource } from './cfn-resource';
import {
CfnAutoScalingReplacingUpdate, CfnAutoScalingRollingUpdate, CfnAutoScalingScheduledAction, CfnCodeDeployLambdaAliasUpdate,
CfnCreationPolicy, CfnDeletionPolicy, CfnResourceAutoScalingCreationPolicy, CfnResourceSignal, CfnUpdatePolicy,
} from './cfn-resource-policy';
import { CfnTag } from './cfn-tag';
import { Lazy } from './lazy';
import { CfnReference } from './private/cfn-reference';
import { IResolvable } from './resolvable';
import { Mapper, Validator } from './runtime';
import { isResolvableObject, Token } from './token';
/**
* This class contains static methods called when going from
* translated values received from {@link CfnParser.parseValue}
* to the actual L1 properties -
* things like changing IResolvable to the appropriate type
* (string, string array, or number), etc.
*
* While this file not exported from the module
* (to not make it part of the public API),
* it is directly referenced in the generated L1 code.
*
* @experimental
*/
export class FromCloudFormation {
// nothing to for any but return it
public static getAny(value: any) { return value; }
// nothing to do - if 'value' is not a boolean or a Token,
// a validator should report that at runtime
public static getBoolean(value: any): boolean | IResolvable { return value; }
public static getDate(value: any): Date | IResolvable {
// if the date is a deploy-time value, just return it
if (isResolvableObject(value)) {
return value;
}
// if the date has been given as a string, convert it
if (typeof value === 'string') {
return new Date(value);
}
// all other cases - just return the value,
// if it's not a Date, a validator should catch it
return value;
}
// won't always return a string; if the input can't be resolved to a string,
// the input will be returned.
public static getString(value: any): string {
// if the string is a deploy-time value, serialize it to a Token
if (isResolvableObject(value)) {
return value.toString();
}
// in all other cases, just return the input,
// and let a validator handle it if it's not a string
return value;
}
// won't always return a number; if the input can't be parsed to a number,
// the input will be returned.
public static getNumber(value: any): number {
// if the string is a deploy-time value, serialize it to a Token
if (isResolvableObject(value)) {
return Token.asNumber(value);
}
// return a number, if the input can be parsed as one
let parsedValue;
if (typeof value === 'string') {
parsedValue = parseFloat(value);
if (!isNaN(parsedValue)) {
return parsedValue;
}
}
// otherwise return the input,
// and let a validator handle it if it's not a number
return value;
}
public static getStringArray(value: any): string[] {
// if the array is a deploy-time value, serialize it to a Token
if (isResolvableObject(value)) {
return Token.asList(value);
}
// in all other cases, delegate to the standard mapping logic
return this.getArray(this.getString)(value);
}
public static getArray<T>(mapper: (arg: any) => T): (x: any) => T[] {
return (value: any) => {
if (!Array.isArray(value)) {
// break the type system, and just return the given value,
// which hopefully will be reported as invalid by the validator
// of the property we're transforming
// (unless it's a deploy-time value,
// which we can't map over at build time anyway)
return value;
}
return value.map(mapper);
};
}
public static getMap<T>(mapper: (arg: any) => T): (x: any) => { [key: string]: T } {
return (value: any) => {
if (typeof value !== 'object') {
// if the input is not a map (= object in JS land),
// just return it, and let the validator of this property handle it
// (unless it's a deploy-time value,
// which we can't map over at build time anyway)
return value;
}
const ret: { [key: string]: T } = {};
for (const [key, val] of Object.entries(value)) {
ret[key] = mapper(val);
}
return ret;
};
}
public static getCfnTag(tag: any): CfnTag {
return tag == null
? { } as any // break the type system - this should be detected at runtime by a tag validator
: {
key: tag.Key,
value: tag.Value,
};
}
/**
* Return a function that, when applied to a value, will return the first validly deserialized one
*/
public static getTypeUnion(validators: Validator[], mappers: Mapper[]): (x: any) => any {
return (value: any): any => {
for (let i = 0; i < validators.length; i++) {
const candidate = mappers[i](value);
if (validators[i](candidate).isSuccess) {
return candidate;
}
}
// if nothing matches, just return the input unchanged, and let validators catch it
return value;
};
}
}
/**
* An interface that represents callbacks into a CloudFormation template.
* Used by the fromCloudFormation methods in the generated L1 classes.
*/
export interface ICfnFinder {
/**
* Return the Condition with the given name from the template.
* If there is no Condition with that name in the template,
* returns undefined.
*/
findCondition(conditionName: string): CfnCondition | undefined;
/**
* Return the Mapping with the given name from the template.
* If there is no Mapping with that name in the template,
* returns undefined.
*/
findMapping(mappingName: string): CfnMapping | undefined;
/**
* Returns the element referenced using a Ref expression with the given name.
* If there is no element with this name in the template,
* return undefined.
*/
findRefTarget(elementName: string): CfnElement | undefined;
/**
* Returns the resource with the given logical ID in the template.
* If a resource with that logical ID was not found in the template,
* returns undefined.
*/
findResource(logicalId: string): CfnResource | undefined;
}
/**
* The interface used as the last argument to the fromCloudFormation
* static method of the generated L1 classes.
*/
export interface FromCloudFormationOptions {
/**
* The parser used to convert CloudFormation to values the CDK understands.
*/
readonly parser: CfnParser;
}
/**
* The context in which the parsing is taking place.
*
* Some fragments of CloudFormation templates behave differently than others
* (for example, the 'Conditions' sections treats { "Condition": "NameOfCond" }
* differently than the 'Resources' section).
* This enum can be used to change the created {@link CfnParser} behavior,
* based on the template context.
*/
export enum CfnParsingContext {
/** We're currently parsing the 'Conditions' section. */
CONDITIONS,
/** We're currently parsing the 'Rules' section. */
RULES,
}
/**
* The options for {@link FromCloudFormation.parseValue}.
*/
export interface ParseCfnOptions {
/**
* The finder interface used to resolve references in the template.
*/
readonly finder: ICfnFinder;
/**
* The context we're parsing the template in.
*
* @default - the default context (no special behavior)
*/
readonly context?: CfnParsingContext;
/**
* Values provided here will replace references to parameters in the parsed template.
*/
readonly parameters: { [parameterName: string]: any };
}
/**
* This class contains methods for translating from a pure CFN value
* (like a JS object { "Ref": "Bucket" })
* to a form CDK understands
* (like Fn.ref('Bucket')).
*
* While this file not exported from the module
* (to not make it part of the public API),
* it is directly referenced in the generated L1 code,
* so any renames of it need to be reflected in cfn2ts/codegen.ts as well.
*
* @experimental
*/
export class CfnParser {
private readonly options: ParseCfnOptions;
constructor(options: ParseCfnOptions) {
this.options = options;
}
public handleAttributes(resource: CfnResource, resourceAttributes: any, logicalId: string): void {
const finder = this.options.finder;
const cfnOptions = resource.cfnOptions;
cfnOptions.creationPolicy = this.parseCreationPolicy(resourceAttributes.CreationPolicy);
cfnOptions.updatePolicy = this.parseUpdatePolicy(resourceAttributes.UpdatePolicy);
cfnOptions.deletionPolicy = this.parseDeletionPolicy(resourceAttributes.DeletionPolicy);
cfnOptions.updateReplacePolicy = this.parseDeletionPolicy(resourceAttributes.UpdateReplacePolicy);
cfnOptions.metadata = this.parseValue(resourceAttributes.Metadata);
// handle Condition
if (resourceAttributes.Condition) {
const condition = finder.findCondition(resourceAttributes.Condition);
if (!condition) {
throw new Error(`Resource '${logicalId}' uses Condition '${resourceAttributes.Condition}' that doesn't exist`);
}
cfnOptions.condition = condition;
}
// handle DependsOn
resourceAttributes.DependsOn = resourceAttributes.DependsOn ?? [];
const dependencies: string[] = Array.isArray(resourceAttributes.DependsOn) ?
resourceAttributes.DependsOn : [resourceAttributes.DependsOn];
for (const dep of dependencies) {
const depResource = finder.findResource(dep);
if (!depResource) {
throw new Error(`Resource '${logicalId}' depends on '${dep}' that doesn't exist`);
}
resource.node.addDependency(depResource);
}
}
private parseCreationPolicy(policy: any): CfnCreationPolicy | undefined {
if (typeof policy !== 'object') { return undefined; }
// change simple JS values to their CDK equivalents
policy = this.parseValue(policy);
return undefinedIfAllValuesAreEmpty({
autoScalingCreationPolicy: parseAutoScalingCreationPolicy(policy.AutoScalingCreationPolicy),
resourceSignal: parseResourceSignal(policy.ResourceSignal),
});
function parseAutoScalingCreationPolicy(p: any): CfnResourceAutoScalingCreationPolicy | undefined {
if (typeof p !== 'object') { return undefined; }
return undefinedIfAllValuesAreEmpty({
minSuccessfulInstancesPercent: FromCloudFormation.getNumber(p.MinSuccessfulInstancesPercent),
});
}
function parseResourceSignal(p: any): CfnResourceSignal | undefined {
if (typeof p !== 'object') { return undefined; }
return undefinedIfAllValuesAreEmpty({
count: FromCloudFormation.getNumber(p.Count),
timeout: FromCloudFormation.getString(p.Timeout),
});
}
}
private parseUpdatePolicy(policy: any): CfnUpdatePolicy | undefined {
if (typeof policy !== 'object') { return undefined; }
// change simple JS values to their CDK equivalents
policy = this.parseValue(policy);
return undefinedIfAllValuesAreEmpty({
autoScalingReplacingUpdate: parseAutoScalingReplacingUpdate(policy.AutoScalingReplacingUpdate),
autoScalingRollingUpdate: parseAutoScalingRollingUpdate(policy.AutoScalingRollingUpdate),
autoScalingScheduledAction: parseAutoScalingScheduledAction(policy.AutoScalingScheduledAction),
codeDeployLambdaAliasUpdate: parseCodeDeployLambdaAliasUpdate(policy.CodeDeployLambdaAliasUpdate),
enableVersionUpgrade: policy.EnableVersionUpgrade,
useOnlineResharding: policy.UseOnlineResharding,
});
function parseAutoScalingReplacingUpdate(p: any): CfnAutoScalingReplacingUpdate | undefined {
if (typeof p !== 'object') { return undefined; }
return undefinedIfAllValuesAreEmpty({
willReplace: p.WillReplace,
});
}
function parseAutoScalingRollingUpdate(p: any): CfnAutoScalingRollingUpdate | undefined {
if (typeof p !== 'object') { return undefined; }
return undefinedIfAllValuesAreEmpty({
maxBatchSize: FromCloudFormation.getNumber(p.MaxBatchSize),
minInstancesInService: FromCloudFormation.getNumber(p.MinInstancesInService),
minSuccessfulInstancesPercent: FromCloudFormation.getNumber(p.MinSuccessfulInstancesPercent),
pauseTime: FromCloudFormation.getString(p.PauseTime),
suspendProcesses: FromCloudFormation.getStringArray(p.SuspendProcesses),
waitOnResourceSignals: p.WaitOnResourceSignals,
});
}
function parseCodeDeployLambdaAliasUpdate(p: any): CfnCodeDeployLambdaAliasUpdate | undefined {
if (typeof p !== 'object') { return undefined; }
return {
beforeAllowTrafficHook: FromCloudFormation.getString(p.BeforeAllowTrafficHook),
afterAllowTrafficHook: FromCloudFormation.getString(p.AfterAllowTrafficHook),
applicationName: FromCloudFormation.getString(p.ApplicationName),
deploymentGroupName: FromCloudFormation.getString(p.DeploymentGroupName),
};
}
function parseAutoScalingScheduledAction(p: any): CfnAutoScalingScheduledAction | undefined {
if (typeof p !== 'object') { return undefined; }
return undefinedIfAllValuesAreEmpty({
ignoreUnmodifiedGroupSizeProperties: p.IgnoreUnmodifiedGroupSizeProperties,
});
}
}
private parseDeletionPolicy(policy: any): CfnDeletionPolicy | undefined {
switch (policy) {
case null: return undefined;
case undefined: return undefined;
case 'Delete': return CfnDeletionPolicy.DELETE;
case 'Retain': return CfnDeletionPolicy.RETAIN;
case 'Snapshot': return CfnDeletionPolicy.SNAPSHOT;
default: throw new Error(`Unrecognized DeletionPolicy '${policy}'`);
}
}
public parseValue(cfnValue: any): any {
// == null captures undefined as well
if (cfnValue == null) {
return undefined;
}
// if we have any late-bound values,
// just return them
if (isResolvableObject(cfnValue)) {
return cfnValue;
}
if (Array.isArray(cfnValue)) {
return cfnValue.map(el => this.parseValue(el));
}
if (typeof cfnValue === 'object') {
// an object can be either a CFN intrinsic, or an actual object
const cfnIntrinsic = this.parseIfCfnIntrinsic(cfnValue);
if (cfnIntrinsic) {
return cfnIntrinsic;
}
const ret: any = {};
for (const [key, val] of Object.entries(cfnValue)) {
ret[key] = this.parseValue(val);
}
return ret;
}
// in all other cases, just return the input
return cfnValue;
}
private parseIfCfnIntrinsic(object: any): any {
const key = this.looksLikeCfnIntrinsic(object);
switch (key) {
case undefined:
return undefined;
case 'Ref': {
const refTarget = object[key];
const specialRef = this.specialCaseRefs(refTarget);
if (specialRef) {
return specialRef;
} else {
const refElement = this.options.finder.findRefTarget(refTarget);
if (!refElement) {
throw new Error(`Element used in Ref expression with logical ID: '${refTarget}' not found`);
}
return CfnReference.for(refElement, 'Ref');
}
}
case 'Fn::GetAtt': {
// Fn::GetAtt takes a 2-element list as its argument
const value = object[key];
const target = this.options.finder.findResource(value[0]);
if (!target) {
throw new Error(`Resource used in GetAtt expression with logical ID: '${value[0]}' not found`);
}
return target.getAtt(value[1]);
}
case 'Fn::Join': {
// Fn::Join takes a 2-element list as its argument,
// where the first element is the delimiter,
// and the second is the list of elements to join
const value = this.parseValue(object[key]);
// wrap the array as a Token,
// as otherwise Fn.join() will try to concatenate
// the non-token parts,
// causing a diff with the original template
return Fn.join(value[0], Lazy.listValue({ produce: () => value[1] }));
}
case 'Fn::Cidr': {
const value = this.parseValue(object[key]);
return Fn.cidr(value[0], value[1], value[2]);
}
case 'Fn::FindInMap': {
const value = this.parseValue(object[key]);
// the first argument to FindInMap is the mapping name
const mapping = this.options.finder.findMapping(value[0]);
if (!mapping) {
throw new Error(`Mapping used in FindInMap expression with name '${value[0]}' was not found in the template`);
}
return Fn.findInMap(mapping.logicalId, value[1], value[2]);
}
case 'Fn::Select': {
const value = this.parseValue(object[key]);
return Fn.select(value[0], value[1]);
}
case 'Fn::GetAZs': {
const value = this.parseValue(object[key]);
return Fn.getAzs(value);
}
case 'Fn::ImportValue': {
const value = this.parseValue(object[key]);
return Fn.importValue(value);
}
case 'Fn::Split': {
const value = this.parseValue(object[key]);
return Fn.split(value[0], value[1]);
}
case 'Fn::Transform': {
const value = this.parseValue(object[key]);
return Fn.transform(value.Name, value.Parameters);
}
case 'Fn::Base64': {
const value = this.parseValue(object[key]);
return Fn.base64(value);
}
case 'Fn::If': {
// Fn::If takes a 3-element list as its argument,
// where the first element is the name of a Condition
const value = this.parseValue(object[key]);
const condition = this.options.finder.findCondition(value[0]);
if (!condition) {
throw new Error(`Condition '${value[0]}' used in an Fn::If expression does not exist in the template`);
}
return Fn.conditionIf(condition.logicalId, value[1], value[2]);
}
case 'Fn::Equals': {
const value = this.parseValue(object[key]);
return Fn.conditionEquals(value[0], value[1]);
}
case 'Fn::And': {
const value = this.parseValue(object[key]);
return Fn.conditionAnd(...value);
}
case 'Fn::Not': {
const value = this.parseValue(object[key]);
return Fn.conditionNot(value[0]);
}
case 'Fn::Or': {
const value = this.parseValue(object[key]);
return Fn.conditionOr(...value);
}
case 'Fn::Sub': {
const value = this.parseValue(object[key]);
let fnSubString: string;
let map: { [key: string]: any } | undefined;
if (typeof value === 'string') {
fnSubString = value;
map = undefined;
} else {
fnSubString = value[0];
map = value[1];
}
return Fn.sub(this.parseFnSubString(fnSubString, map), map);
}
case 'Condition': {
// a reference to a Condition from another Condition
const condition = this.options.finder.findCondition(object[key]);
if (!condition) {
throw new Error(`Referenced Condition with name '${object[key]}' was not found in the template`);
}
return { Condition: condition.logicalId };
}
default:
if (this.options.context === CfnParsingContext.RULES) {
return this.handleRulesIntrinsic(key, object);
} else {
throw new Error(`Unsupported CloudFormation function '${key}'`);
}
}
}
private looksLikeCfnIntrinsic(object: object): string | undefined {
const objectKeys = Object.keys(object);
// a CFN intrinsic is always an object with a single key
if (objectKeys.length !== 1) {
return undefined;
}
const key = objectKeys[0];
return key === 'Ref' || key.startsWith('Fn::') ||
// special intrinsic only available in the 'Conditions' section
(this.options.context === CfnParsingContext.CONDITIONS && key === 'Condition')
? key
: undefined;
}
private parseFnSubString(value: string, map: { [key: string]: any } = {}): string {
const leftBrace = value.indexOf('${');
const rightBrace = value.indexOf('}') + 1;
// don't include left and right braces when searching for the target of the reference
if (leftBrace === -1 || leftBrace >= rightBrace) {
return value;
}
const leftHalf = value.substring(0, leftBrace);
const rightHalf = value.substring(rightBrace);
const refTarget = value.substring(leftBrace + 2, rightBrace - 1).trim();
if (refTarget[0] === '!') {
return value.substring(0, rightBrace) + this.parseFnSubString(rightHalf, map);
}
// lookup in map
if (refTarget in map) {
return leftHalf + '${' + refTarget + '}' + this.parseFnSubString(rightHalf, map);
}
// since it's not in the map, check if it's a pseudo parameter
const specialRef = this.specialCaseSubRefs(refTarget);
if (specialRef) {
return leftHalf + specialRef + this.parseFnSubString(rightHalf, map);
}
const dotIndex = refTarget.indexOf('.');
const isRef = dotIndex === -1;
if (isRef) {
const refElement = this.options.finder.findRefTarget(refTarget);
if (!refElement) {
throw new Error(`Element referenced in Fn::Sub expression with logical ID: '${refTarget}' was not found in the template`);
}
return leftHalf + CfnReference.for(refElement, 'Ref', true).toString() + this.parseFnSubString(rightHalf, map);
} else {
const targetId = refTarget.substring(0, dotIndex);
const refResource = this.options.finder.findResource(targetId);
if (!refResource) {
throw new Error(`Resource referenced in Fn::Sub expression with logical ID: '${targetId}' was not found in the template`);
}
const attribute = refTarget.substring(dotIndex + 1);
return leftHalf + CfnReference.for(refResource, attribute, true).toString() + this.parseFnSubString(rightHalf, map);
}
}
private handleRulesIntrinsic(key: string, object: any): any {
// Rules have their own set of intrinsics:
// https://docs.aws.amazon.com/servicecatalog/latest/adminguide/intrinsic-function-reference-rules.html
switch (key) {
case 'Fn::ValueOf': {
// ValueOf is special,
// as it takes the name of a Parameter as its first argument
const value = this.parseValue(object[key]);
const parameterName = value[0];
if (parameterName in this.parameters) {
// since ValueOf returns the value of a specific attribute,
// fail here - this substitution is not allowed
throw new Error(`Cannot substitute parameter '${parameterName}' used in Fn::ValueOf expression with attribute '${value[1]}'`);
}
const param = this.options.finder.findRefTarget(parameterName);
if (!param) {
throw new Error(`Rule references parameter '${parameterName}' which was not found in the template`);
}
// create an explicit IResolvable,
// as Fn.valueOf() returns a string,
// which is incorrect
// (Fn::ValueOf can also return an array)
return Lazy.anyValue({ produce: () => ({ 'Fn::ValueOf': [param.logicalId, value[1]] }) });
}
default:
// I don't want to hard-code the list of supported Rules-specific intrinsics in this function;
// so, just return undefined here,
// and they will be treated as a regular JSON object
return undefined;
}
}
private specialCaseRefs(value: any): any {
if (value in this.parameters) {
return this.parameters[value];
}
switch (value) {
case 'AWS::AccountId': return Aws.ACCOUNT_ID;
case 'AWS::Region': return Aws.REGION;
case 'AWS::Partition': return Aws.PARTITION;
case 'AWS::URLSuffix': return Aws.URL_SUFFIX;
case 'AWS::NotificationARNs': return Aws.NOTIFICATION_ARNS;
case 'AWS::StackId': return Aws.STACK_ID;
case 'AWS::StackName': return Aws.STACK_NAME;
case 'AWS::NoValue': return Aws.NO_VALUE;
default: return undefined;
}
}
private specialCaseSubRefs(value: string): string | undefined {
if (value in this.parameters) {
return this.parameters[value];
}
return value.indexOf('::') === -1 ? undefined: '${' + value + '}';
}
private get parameters(): { [parameterName: string]: any } {
return this.options.parameters || {};
}
}
function undefinedIfAllValuesAreEmpty(object: object): object | undefined {
return Object.values(object).some(v => v !== undefined) ? object : undefined;
}