Skip to content
This repository has been archived by the owner on Apr 16, 2022. It is now read-only.

Parameter guessing #97

Merged
merged 3 commits into from Nov 29, 2017
Merged

Conversation

akdor1154
Copy link
Contributor

@akdor1154 akdor1154 commented Nov 20, 2017

Implement strict control over how parameter values are guessed.

By default, parameters guessing is unchanged from current behaviour. The parameter will be guessed by looking at the param Default, AllowedValues, and Type properties in that order.

If the guessParameters option is set (to a list of parameter names), only parameters which are in that list will be guessed without reporting an error. Any that are absent and that still need to be guessed will cause a critical error to be raised.

From the CLI side this is controlled by the guess-parameters/no-guess-parameters flags.

From the API side this is controlled by just setting guessParameters in the options - an empty list can be used to disable guessing everything.

@akdor1154 akdor1154 force-pushed the parameterGuessing branch 2 times, most recently from d8438d1 to 60d63f4 Compare November 20, 2017 06:07
@martysweet
Copy link
Owner

@akdor1154 Can you resolve the conflict? I don't have permission to write back to your branch. Ta

@akdor1154
Copy link
Contributor Author

whoops sorry, I thought that was on by default!

README.md Outdated
`--pseudo <psuedo param values>`: Provide a list of comma-separated key=value pairs of CloudFormation pseudo-parameters to use when validating your template. e.g.
- `--pseudo AWS::Region=ap-southeast-2`

`--no-guess-parameters`: Disable the guessing of parameters if they don't have a Default. If you don't provide them on the CLI in this situation, a critical error will be raised instead of the parameter value being mocked.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have the default behaviour specified if these flags are omitted?

Leaving as undefined preserves the default loose behaviour, where parameters are guessed as needed without causing an error.

}).timeout(5000);

it('guess-parameters should allow opting in to parameter mocking', (done) => {
exec('node lib/index.js validate testData/valid/yaml/no-guess-parameters.yaml --guess-parameters Param1', function(error, stdout, stderr) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a test for multiple parameters specified for guess-parameters?
--guess parameters Param1, Param 2

src/validator.ts Outdated
const logLevel = (okToGuess)
? 'info'
: 'crit';
addError(logLevel, 'Guessing parameter value', ['Parameters', parameterName], 'Parameters')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be misleading; if I specify --no-guess-parameters I would be confused to see a critical error saying Guessing parameter value (It shouldn't be guessing my parameter values!). Maybe something different for this use case would be better. Value for parameter not provided?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that would be sensible. Does it still make sense to guess in this case (it kind of has to continue validation...)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've also removed the output completely if okToGuess is true (so behaviour is identical to current)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good shout, maybe something like:
If parameter name IN --guess--parameters OR guessAll => "Guessing parameter value" (INFO)
If --no-guess-parameters => "Value for parameter not provided, continuing validation with empty input"

Then we are enforcing what the user expects by using the CLI option.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I leave off the INFO message completely? It currently works like that and would lead to lots of noise in the output. (I think I was mistaken in adding it.)

@akdor1154
Copy link
Contributor Author

akdor1154 commented Nov 21, 2017

Decided to change --guess-parameters Param1,etc to --only-guess-parameters Param1,etc. This means --guess-parameters is now just the boolean opposite to --no-guess-parameters which is probably more sensible, and the default behaviour can be described there too.

@akdor1154
Copy link
Contributor Author

@martysweet were you waiting on me to fix anything up for this? I'm mildly against having an info message when a parameter is guessed in normal mode, simply because there isn't one now and I wouldn't want to change default behaviour (also it'd lead to some console spam), but I can add it back if you think it would be beneficial.

@martysweet
Copy link
Owner

@akdor1154 Agreed. Could you add the following to the CHANGELOG under "Unreleased".

(Or something which describes it better)

### Added
- Merge PR #97, guess parameters flags

Will release a new version later today!

@akdor1154
Copy link
Contributor Author

should be good, thanks!

@martysweet martysweet merged commit bd1fa4b into martysweet:master Nov 29, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants