648 Commits

Author SHA1 Message Date
Erik Erikson
2ebc65fe97 Fix Embedded Deep Variable in Variable String, within Override bug
If an override comes back as a variable containing a deep variable (e.g. `''${self:custom.${deep:1}, "fallback"}''`) or really any variable at all, it needs to be made a deep variable and paused for next iteration.  Do this generally rather than only in the case of deep variables.  See the test case for a circumstance that the prior fix didn't resolve.  This more generalized handling improves the fix and solves a remaining issue we found locally.
2018-08-17 17:50:58 -07:00
Erik Erikson
73ebe0f66b Fix #5205
Use the variable string from which the overwrite parameters were extracted as the replacement target (in the case of deep variable discovery) rather than the context property which represents the entire original value that the replacement is being waited upon.  That context property can contain far more content than the overwrite string itself.
2018-08-16 18:35:53 -07:00
Takahiro Horike
659df3651c
Merge pull request #5119 from gcphost/master
#5110 null error on undefined AWS SSM variables
2018-08-06 21:31:57 +09:00
Takahiro Horike
8c85ed0db1
Merge pull request #5156 from erikerikson/fix-overwrite-to-deep-unresolvable
During Overwrite, Pause on Deep Variables
2018-08-02 20:41:27 +09:00
Erik Erikson
42d1749c36 When evaluating overwrite values, identify deep values and pause population.
This avoids taking a deep value as a valid term within an overwrite 
(defaulting) variable statement that will later resolve to undefined 
but, as a deep variable string, is valid in immediate evaluation.

Fixes #5027
2018-07-24 14:42:21 -07:00
Erik Erikson
0b97b74be4 Improve messaging and formatting of pending promise warnings
Add explanatory text:
```
This can result from latent connections but may represent a cyclic 
variable dependency
```

Also, rather than messages such as:
```
Serverless Information ----------------------------------

##########################################################################################
 
 Serverless Information ----------------------------------
 
 # 0: 0 of 2 promises have settled
 
 Serverless Information ----------------------------------
 
 # 0: 2 unsettled promises:
 
 Serverless Information ----------------------------------
 
 # 0:   foo waited on by: ${foo:}
 
 Serverless Information ----------------------------------
 
 # 0:   foo waited on by: ${foo:}
 
 Serverless Information ----------------------------------
 
##########################################################################################
```

Collate the message to read like:
```
Serverless Information ----------------------------------

##########################################################################################
 # 0: 0 of 2 promises have settled
 # 0: 2 unsettled promises:
 # 0:   foo waited on by: ${foo:}
 # 0:   foo waited on by: ${foo:}
 # This can result from latent connections but may represent a cyclic 
variable dependency
##########################################################################################
```
2018-07-23 17:03:34 -07:00
William
0f1c8047da Use statusCode for comparison, update tests to provide correct statusCode. 2018-07-16 21:51:02 -07:00
William
58c8352ec2
Switch to lodash get. 2018-07-16 20:54:30 -07:00
William
20401e7c3c
Remove extra space 2018-07-12 21:37:11 -07:00
William
2d6248f08b
Remove additional space 2018-07-12 14:26:02 -07:00
William
849d3b206f
Change error detection
Use code provided by the errors providerError.
2018-07-12 14:24:56 -07:00
William
880ba0b788
#5110 null error on undefined SSM variables
Ignore null errors to allow resolution instead of rejection on undefined SSM variables.
2018-07-11 08:44:58 -07:00
Eslam A. Hefnawy
e7e4b0154e add getLocalAccessKey method 2018-07-11 15:42:14 +03:00
Eslam λ Hefnawy
743efc9e75
Merge pull request #5043 from serverless/dashboard-integration
Integrate with Serverless Dashboard
2018-07-04 08:11:00 +03:00
Eslam A. Hefnawy
ee72cee853 add all events 2018-06-20 12:33:54 +03:00
Takahiro Horike
aeffbae743
Merge pull request #5029 from dougmoscrop/cycles
only use json-cycles when opt-in, for state serialization
2018-06-18 04:14:02 +09:00
GuruRAM
77f33e789e Merge branch 'master' of https://github.com/serverless/serverless 2018-06-17 12:54:26 +03:00
Eslam A. Hefnawy
396febb306 publish, archive, access keys and login updated 2018-06-15 16:10:52 +03:00
Doug Moscrop
8d9f4a296b only use json-cycles when opt-in, for state serialization 2018-06-06 15:07:03 -04:00
Erik Erikson
534dda6285 Fix #4973
Do a better job of extracting the current variable syntax for use in deep variable generation.
2018-05-18 00:04:37 -07:00
Erik Erikson
63045fd206 Fix #4946
Use the variable syntax present in the given variable string, extracting it from the given string that may contain embedded custom variables (i.e. `${{self:var.${{self:var.foo}}.bar}}`).
2018-05-02 11:52:24 -07:00
GuruRAM
b9c7260881 #4839 pluginInstance.provider check type fixed. 2018-04-23 00:51:04 +03:00
GuruRAM
00b2024f76 #4839 reimplemented yamlAstParser addNewArrayItem and removeExistingArrayItem methods.
Extended install.test.js, uninstall.test.js unit tests to cover complex plugins object.
2018-04-15 23:01:11 +03:00
GuruRAM
0081afd78c #4839 use lodash check functions (isString, isArray, isObject) instead of native ones. 2018-04-09 21:43:28 +03:00
GuruRAM
78c46ee943 #4839 lint error fixes 2018-04-09 00:14:38 +03:00
GuruRAM
1c180c850a #4839 Configurable local plugins folder feature. 2018-04-08 23:28:52 +03:00
Doug Moscrop
8bde1b4902 Support arrays in function definition too 2018-04-04 20:03:56 -04:00
Takahiro Horike
6cbd0a95bd
Merge pull request #4665 from americansystems/sls-govcloud
Support AWS GovCloud and China region deployments
2018-04-03 19:09:26 +09:00
Takahiro Horike
a9e6a79d01
Merge pull request #4743 from svdgraaf/feature/pass-serverless-variable
Pass serverless variable when calling function in referenced file
2018-04-03 05:04:08 +09:00
Takahiro Horike
721f8b6580
Merge pull request #4859 from erikerikson/self-service-rewrite
Re-write `self:service.[...]` to `self:serviceObject.[...]`
2018-03-29 09:14:50 +09:00
David Wells
88b0f3ad3f
Update Error.js 2018-03-27 16:22:25 -07:00
Erik Erikson
71c6db9687 Re-write self:service.[...] to self:serviceObject.[...]
Handle `self:service.[...]` references properly.  The prior represents what the user typed into their configuration.  In service, we move all this from `service` to `serviceObject`, therefore, by rewriting `self:service.[...]` to `self:serviceObject.[...]` user's will get the result they expect.
Use else if, given exclusivity of conditions
2018-03-27 15:34:34 -07:00
Takahiro Horike
5c886b5b2c
Merge branch 'master' into sls-govcloud 2018-03-13 06:02:22 +09:00
Frank Schmid
5a4d00c9ad
Merge pull request #4800 from bsdkurt/master
Continue recursion for #4687
2018-03-06 11:35:17 +01:00
Erik Erikson
8f32a59c7f add test that fails prior to the fix in #4800 and succeeds after 2018-03-05 13:33:18 -08:00
Kurt Miller
3f5a041678 Continue recursion for #4687 2018-03-04 08:25:19 -05:00
Erik Erikson
0ee0a1e239 Only disable and restore dependent service resolution methods once. Otherwise, subsequent removals may cache the previous replacements. If they restore last then they will restore with the replacements, breaking standard usage.
Add tests for this guarantee.
2018-02-24 09:34:50 -08:00
Erik Erikson
91a10940eb Add further comments noting code entanglement 2018-02-23 10:09:18 -08:00
Erik Erikson
bf5a8c9fd4 Fix 4744 and associated
The framework's Service class modifies a user's service, mutating a given `service: { name: 'string' }` to `service: 'string'` but doesn't account for this in the variables system.  This is the basis for #4744.

While working this area, I discovered that the Service class also does this to the provider, accepting `provider: 'aws'` and replacing it with `provider: { name: 'aws' }`, causing the natural `${self:provider}` to fail.

Catching either 'self:service.name' or 'self:provider' and replacing them with the mutated reference solves this user confusion.
2018-02-22 17:17:55 -08:00
Erik Erikson
dc3a4aa6af Fix print, clean pre-population, fix cyclic bug
Fix `print`
The print command is highly linked to the `Variables` and `Service` codebases, keep those in sync and leave reminders about the link.  Made these explicit and separately implemented to avoid complexity.
Additionally, the print command re-populates an object with the *very similar* content as the previously pre-populated service (just not augmented as just mentioned).  This can lead to cross contamination between the two.  As such, all caches must be cleared per unique invocation of service/object/property population.
Add tests for some expected but previously unverified behaviors.

Clean pre-population
The previous implementation worked okay but was unnecessary and would have been a maintenance problem.  Instead, just knock out the population of variables depending on those config dependent services and use the standard means of resolution.

Fix cyclic bug (resulting from running print against a self-referencing serverless.yml)
The caching of values could lead to a cyclic object remaining in the caches for variable population.  This causes crashes and pain.  Solved by the cache cleaning logic.
2018-02-22 16:30:04 -08:00
Erik Erikson
8c7db120ae Add cases for all dependent services, and a variety of deep variable (DV) cases
Solve for these cases.  The bug was that DVs can render to DVs when a value is being obtained from them (i.e. they are being de-referenced in getValueFromDeep).  This is particularly problematic in the case that the original DV being rendered has a deep reference into the rendered DV.  In that case the DV returned by rendering must be replaced by yet another DV.

While accomplishing the above, various bits of cleanup were implemented and I added some commentary around getDeeperValue for future engineers.

This case is particularly relevant if you have:

`serverless.yml`:
```
service: serverless-hello-world

provider:
  name: aws
  runtime: nodejs6.10
  stage: dev
  environment:
    SECRET: ${self:custom.secrets.SECRET}

functions:
  helloWorld:
    handler: handler.helloWorld
    events:
      - http:
          path: hello-world
          method: get
          cors: true

custom:
  stage: ${opt:stage, self:provider.stage}
  secrets: ${file(secrets.${self:custom.stage}.yml)}
```
AND
`secrets.dev.yml`:
```
SECRETS: secrets
```

Populating this service should result in the following sequence of rendering phases:

#########################
# PHASE 1
#
# ${self:custom.secrets.SECRET}
#   <- ${deep:0.SECRET}
#   deep[0] = ${file(secrets.${self:custom.stage}.yml)}
#
# ${opt:stage, self:provider.stage}
#   <- 'dev'
#
# ${file(secrets.${self:custom.stage}.yml)}
#   <- ${file(secrets.${deep:1}.yml)}
#   deep[1] = ${opt:stage, self:provider.stage}
#
# RESULT
#
# service: serverless-hello-world
#
# provider:
#   name: aws
#   runtime: nodejs6.10
#   stage: dev
#   environment:
#     SECRET: ${deep:0.SECRET}
#
# functions:
#   helloWorld:
#     handler: handler.helloWorld
#     events:
#       - http:
#           path: hello-world
#           method: get
#           cors: true
#
# custom:
#   stage: dev
#   secrets: ${file(secrets.${deep:1}.yml)}
#########################

#########################
# PHASE 2
#
# ${deep:0.SECRET}
#   <- this.populateValue('${file(secrets.${self:custom.stage}.yml)}') => '${file(secrets.${deep:1}.yml)}' => '${deep:2}' => '${deep:2.SECRET}'
#   deep[2] = ${file(secrets.${deep:1}.yml)}
#
# ${file(secrets.${deep:1}.yml)}
#   <- this.populateValue('${file(secrets.${deep:1}.yml)}') => '${file(secrets.dev.yml)}' => '${deep:3}'
#   deep[3] = ${file(secrets.dev.yml)}
#
# RESULT
#
# service: serverless-hello-world
#
# provider:
#   name: aws
#   runtime: nodejs6.10
#   stage: dev
#   environment:
#     SECRET: ${deep:2.SECRET}
#
# functions:
#   helloWorld:
#     handler: handler.helloWorld
#     events:
#       - http:
#           path: hello-world
#           method: get
#           cors: true
#
# custom:
#   stage: dev
#   secrets: ${deep:3}
#########################

#########################
# PHASE 3
#
# ${deep:2.SECRET}
#   <- this.populateValue('${file(secrets.${deep:1}.yml)}') => '${file(secrets.dev.yml)}' => '${deep:3}' => '${deep:3.SECRET}'
#   deep[3] is already set to ${file(secrets.dev.yml)}
#
# ${deep:3}
#   <- this.populateValue('${file(secrets.dev.yml)}') => { SECRET: 'secret' }
#
# RESULT
#
# service: serverless-hello-world
#
# provider:
#   name: aws
#   runtime: nodejs6.10
#   stage: dev
#   environment:
#     SECRET: ${deep:3.SECRET}
#
# functions:
#   helloWorld:
#     handler: handler.helloWorld
#     events:
#       - http:
#           path: hello-world
#           method: get
#           cors: true
#
# custom:
#   stage: dev
#   secrets:
#     SECRET: secret
#########################

#########################
# PHASE 4
#
# ${deep:3}
#   <- this.populateValue('${file(secrets.dev.yml)}') => this.getDeeperValue(['SECRET'], { SECRET: 'secret' }) => 'secret'
#
# RESULT
#
# service: serverless-hello-world
#
# provider:
#   name: aws
#   runtime: nodejs6.10
#   stage: dev
#   environment:
#     SECRET: secret
#
# functions:
#   helloWorld:
#     handler: handler.helloWorld
#     events:
#       - http:
#           path: hello-world
#           method: get
#           cors: true
#
# custom:
#   stage: dev
#   secrets:
#     SECRET: secret
#########################
2018-02-20 20:57:24 -08:00
Erik Erikson
a35bcc01cd Deep values can be overwrites too! Fix issue reported by @laardee (thank you!)
Simple oversight that deep variables can reference overwrites too.  This fix acknowledges this oversight by using the standard logic for using overwrite instead of getValueFromSource in this case.
2018-02-20 12:21:26 -08:00
Frank Schmid
39caddc404
Merge pull request #4713 from erikerikson/fix-4687-cyclic-variable-dependencies
Eliminate/Report Hung Promises (#4687), Prepopulate Stage and Region (#4311), Handle Quoted Strings (#4734)
2018-02-20 13:56:27 +01:00
Erik Erikson
ffc7686465 fix pending promise test bugs 2018-02-16 18:46:28 -08:00
Erik Erikson
91f50f6918 add 'use strict' for node 4.x and 5.x 2018-02-16 17:26:40 -08:00
Erik Erikson
4400ffc9e4 fix #4311 & #4734, separate PromiseTracker, minutiae
#4311
  see prepopulateService - attempts to pre-populate the region and stage settings necessary for making a request to AWS, rejecting and dependencies thereon it runs into during that process
  see the `deep` variable work.  this was a knock-on effect of providing pre-population.  it actually represents an obscure class of bugs where the recursive population previously in getDeepValue caused the caller not to be in charge of population choices (thus fixing for pre-population) but also caused potential deadlocks resulting from getDeepValue creating circular dependencies.

#4734
  see splitByComma - a regex to do the splitting but ignore quoted commas was getting very deep and involved.  Instead, identify quoted string boundaries, then identify commas (including white space around them) and take those commas not contained by quotes as the locations for splitting the given string.  Trim the string as well (removing leading and trailing white space).
  add sophistication to the overwrite syntax, allowing for whitespace and repetitions (for robustness)
  add sophistication to the string ref syntax, allowing for use in identifying multiple quoted strings in a variable (i.e. for overwrites)

#NotCreated
  fix a bug I created earlier in the branch that caused reporting to be less informative (see renderMatches)

separate PromiseTracker
  move this class into its own file for the purpose of increasing testability and offering reuse

minutiae
  filter the properties given to populateVariables so as to avoid attempting resolution on non-variables.  Efficiency and noise reduction change.  Also cleans up the code (e.g. see populateObject and its use)
  cleaning of overwrite as a side effect
  offer variable cleaning as a idiom
  reorder the Variables.js `require`s to be in alphabetical order
2018-02-16 17:13:03 -08:00
Sander van de Graaf
8abcee66a4
Pass the serverless variable as parameter to the receiving function 2018-02-15 15:59:45 +01:00
Mike Pugh
7b6a8ff262 Lodash and test updates 2018-02-07 19:50:24 -05:00
Erik Erikson
3606589ff2 Do not double-reject errors
Calling .then here creates a new promise.  One that is not returned and generating a rejection within that promise can lead to unhandledRejection events being inappropriately raised.
As such, don't declare unneeded variables.
2018-02-06 16:35:16 -08:00
Erik Erikson
8f69678a88 remove .only from describe for Variables tests
add expected rejection message
2018-02-03 13:14:11 -08:00