Skip to content
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

relax stage name restrictions when not using apigateway #993

Merged
merged 1 commit into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion tests/test_bad_stage_name_settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"ttt-888": {
"apigateway_enabled": true,
"touch": false,
"s3_bucket": "lmbda",
"app_function": "tests.test_app.hello_world",
Expand Down Expand Up @@ -29,6 +30,7 @@
]
},
"devor": {
"apigateway_enabled": true,
"s3_bucket": "lmbda",
"app_function": "tests.test_app.hello_world",
"callbacks": {
Expand All @@ -45,4 +47,4 @@
"expression": "rate(1 minute)"
}]
}
}
}
8 changes: 3 additions & 5 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1424,11 +1424,9 @@ def test_bad_json_catch(self):

def test_bad_stage_name_catch(self):
zappa_cli = ZappaCLI()
self.assertRaises(
ValueError,
zappa_cli.load_settings,
"tests/test_bad_stage_name_settings.json",
)
zappa_cli.api_stage = "ttt-888"
zappa_cli.load_settings("tests/test_bad_stage_name_settings.json")
self.assertRaises(ValueError, zappa_cli.dispatch_command, "deploy", "ttt-888")

def test_bad_environment_vars_catch(self):
zappa_cli = ZappaCLI()
Expand Down
21 changes: 8 additions & 13 deletions zappa/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ def dispatch_command(self, command, stage):
Given a command to execute and stage,
execute that command.
"""

self.check_stage_name(stage)
self.api_stage = stage

if command not in ["status", "manage"]:
Expand Down Expand Up @@ -1789,9 +1789,15 @@ def check_stage_name(self, stage_name):
calling the CreateDeployment operation: Stage name only allows
a-zA-Z0-9_" if the pattern does not match)
"""
if not self.use_apigateway:
return True
if self.stage_name_env_pattern.match(stage_name):
return True
raise ValueError("AWS requires stage name to match a-zA-Z0-9_")
raise ValueError(
"API stage names must match a-zA-Z0-9_ ; '{0!s}' does not.".format(
stage_name
)
)

def check_environment(self, environment):
"""
Expand Down Expand Up @@ -2483,17 +2489,6 @@ def load_settings(self, settings_file=None, session=None):
# Load up file
self.load_settings_file(settings_file)

# Make sure that the stages are valid names:
for stage_name in self.zappa_settings.keys():
try:
self.check_stage_name(stage_name)
except ValueError:
raise ValueError(
"API stage names must match a-zA-Z0-9_ ; '{0!s}' does not.".format(
stage_name
)
)

# Make sure that this stage is our settings
if self.api_stage not in self.zappa_settings.keys():
raise ClickException(
Expand Down