-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Tests for samconfig use with all commands #1575
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
51b907c
88ad704
5f43d51
cdf59b6
9c2ddae
1632b82
cf6fcd8
8fcd4ed
026861d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,17 @@ | |
| import click | ||
|
|
||
|
|
||
| def _value_regex(delim): | ||
| return f'(\\"(?:\\\\.|[^\\"\\\\]+)*\\"|(?:\\\\.|[^{delim}\\"\\\\]+)+)' | ||
|
|
||
|
|
||
| KEY_REGEX = '([A-Za-z0-9\\"]+)' | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Testing these regexes, will report back with results. |
||
| # Use this regex when you have space as delimiter Ex: "KeyName1=string KeyName2=string" | ||
| VALUE_REGEX_SPACE_DELIM = _value_regex(" ") | ||
| # Use this regex when you have comma as delimiter Ex: "KeyName1=string,KeyName2=string" | ||
| VALUE_REGEX_COMMA_DELIM = _value_regex(",") | ||
|
|
||
|
|
||
| class CfnParameterOverridesType(click.ParamType): | ||
| """ | ||
| Custom Click options type to accept values for CloudFormation template parameters. You can pass values for | ||
|
|
@@ -25,11 +36,8 @@ class CfnParameterOverridesType(click.ParamType): | |
| # If Both ParameterKey pattern and KeyPairName=MyKey should not be present | ||
| # while adding parameter overrides, if they are, it | ||
| # can result in unpredicatable behavior. | ||
| KEY_REGEX = '([A-Za-z0-9\\"]+)' | ||
| VALUE_REGEX = '(\\"(?:\\\\.|[^\\"\\\\]+)*\\"|(?:\\\\.|[^ \\"\\\\]+)+))' | ||
|
|
||
| _pattern_1 = r"(?:ParameterKey={key},ParameterValue={value}".format(key=KEY_REGEX, value=VALUE_REGEX) | ||
| _pattern_2 = r"(?:(?: ){key}={value}".format(key=KEY_REGEX, value=VALUE_REGEX) | ||
| _pattern_1 = r"(?:ParameterKey={key},ParameterValue={value})".format(key=KEY_REGEX, value=VALUE_REGEX_SPACE_DELIM) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, did some testing. Works:
|
||
| _pattern_2 = r"(?:(?: ){key}={value})".format(key=KEY_REGEX, value=VALUE_REGEX_SPACE_DELIM) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Works well, Gotchas with quotes. Works Doesn't work
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not worried about the key not supporting quotes. that's out of scope. Also, value using single quotes is also out-of-scope. |
||
|
|
||
| ordered_pattern_match = [_pattern_1, _pattern_2] | ||
|
|
||
|
|
@@ -114,7 +122,7 @@ class CfnMetadataType(click.ParamType): | |
|
|
||
| _EXAMPLE = 'KeyName1=string,KeyName2=string or {"string":"string"}' | ||
|
|
||
| _pattern = r"([A-Za-z0-9\"]+)=([A-Za-z0-9\"]+)" | ||
| _pattern = r"(?:{key}={value})".format(key=KEY_REGEX, value=VALUE_REGEX_COMMA_DELIM) | ||
|
|
||
| # NOTE(TheSriram): name needs to be added to click.ParamType requires it. | ||
| name = "" | ||
|
|
@@ -160,7 +168,7 @@ class CfnTags(click.ParamType): | |
|
|
||
| _EXAMPLE = "KeyName1=string KeyName2=string" | ||
|
|
||
| _pattern = r"([A-Za-z0-9\"]+)=([A-Za-z0-9\"]+)" | ||
| _pattern = r"{key}={value}".format(key=KEY_REGEX, value=VALUE_REGEX_SPACE_DELIM) | ||
|
|
||
| # NOTE(TheSriram): name needs to be added to click.ParamType requires it. | ||
| name = "" | ||
|
|
@@ -172,11 +180,10 @@ def convert(self, value, param, ctx): | |
| if value == ("",): | ||
| return result | ||
|
|
||
| # if value comes in a via configuration file, we should still convert it. | ||
| # value = (value, ) if not isinstance(value, tuple) else value | ||
| # if value comes in a via configuration file, it will be a string. So we should still convert it. | ||
| value = (value,) if not isinstance(value, tuple) else value | ||
|
|
||
| for val in value: | ||
|
|
||
| groups = re.findall(self._pattern, val) | ||
|
|
||
| if not groups: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.