configorama 0.5.5 → 0.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/main.js +33 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "configorama",
3
- "version": "0.5.5",
3
+ "version": "0.5.7",
4
4
  "description": "Variable support for configuration files",
5
5
  "main": "lib/index.js",
6
6
  "files": [
package/src/main.js CHANGED
@@ -413,12 +413,18 @@ class Configorama {
413
413
  let loggedHeader = false
414
414
  traverse(this.originalConfig).forEach(function (rawValue) {
415
415
  if (typeof rawValue === 'string' && rawValue.match(variableSyntax)) {
416
+ const configValuePath = this.path.join('.')
417
+ if (configValuePath.endsWith('Fn::Sub')) {
418
+ return
419
+ }
420
+
421
+
416
422
  if (!loggedHeader) {
417
423
  console.log('───────────── Variables Detected ──────────────────────')
418
424
  console.log()
419
425
  loggedHeader = true
420
426
  }
421
- const configValuePath = this.path.join('.')
427
+
422
428
  const nested = findNestedVariables(rawValue, variableSyntax, variablesKnownTypes, configValuePath)
423
429
  /*
424
430
  console.log(nested)
@@ -1080,11 +1086,13 @@ class Configorama {
1080
1086
  }
1081
1087
  }
1082
1088
 
1089
+ const currentPath = valueObject.path.join('.')
1090
+
1083
1091
  const errorMessage = `
1084
1092
  Missing Value ${missingValue} - ${matchedString}
1085
1093
  \nMake sure the property is being passed in correctly
1086
1094
  \nFor variable:
1087
- \n${valueObject.path}: ${valueObject.originalSource}
1095
+ \n${currentPath}: ${valueObject.originalSource}
1088
1096
  `
1089
1097
  throw new Error(errorMessage)
1090
1098
  }
@@ -1549,9 +1557,10 @@ Unable to resolve configuration variable
1549
1557
  }
1550
1558
 
1551
1559
  // Variable NOT FOUND. Warn user
1560
+ const key = valueObject.path ? valueObject.path.join('.') : 'na'
1552
1561
  const errorMessage = [
1553
1562
  `Invalid variable reference syntax`,
1554
- `Key: "${valueObject.path ? valueObject.path.join('.') : 'na'}"`,
1563
+ `Key: "${key}"`,
1555
1564
  `Variable: "${variableString}" from ${propertyString} not found`,
1556
1565
  ]
1557
1566
 
@@ -1560,9 +1569,29 @@ Unable to resolve configuration variable
1560
1569
  errorMessage.push('\n Default values for self referenced values are not allowed')
1561
1570
  errorMessage.push(`\n Fix the ${propertyString} variable`)
1562
1571
  }
1572
+
1573
+ let allowSpecialCase = false
1574
+ /* handle special cases for cloudformation ${Sub} values */
1575
+ if (this.originalConfig && key.endsWith('Fn::Sub')) {
1576
+ const params = this.originalConfig.Parameters || (this.originalConfig.parameters || {}).Parameters
1577
+ const resources = this.originalConfig.Resources || (this.originalConfig.resources || {}).Resources
1578
+ /* Cloudformation Resource References */
1579
+ if (resources && resources[variableString]) {
1580
+ allowSpecialCase = true
1581
+ } else if (params && params[variableString]) {
1582
+ allowSpecialCase = true
1583
+ } else if (variableString === 'ApiGatewayRestApi') {
1584
+ // Allow for "hidden" cloudformation variables, set by sls framework
1585
+ allowSpecialCase = true
1586
+ } else if (variableString === 'HttpApi') {
1587
+ // Allow for "hidden" cloudformation variables, set by sls framework
1588
+ allowSpecialCase = true
1589
+ }
1590
+ }
1591
+ /* Todo handle stage variables */
1563
1592
 
1564
1593
  /* Pass through unknown variables */
1565
- if (this.opts.allowUnknownVars) {
1594
+ if (this.opts.allowUnknownVars || allowSpecialCase) {
1566
1595
  // console.log('allowUnknownVars propertyString', propertyString)
1567
1596
  const varMatches = propertyString.match(this.variableSyntax)
1568
1597
  let allowUnknownVars = propertyString