Skip to content

Commit

Permalink
relax stage name restrictions when not using apigateway
Browse files Browse the repository at this point in the history
  • Loading branch information
wrboyce committed Sep 27, 2021
1 parent 5dc7b7a commit dbbdd58
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
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: 10 additions & 11 deletions zappa/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,14 @@ def dispatch_command(self, command, stage):
"""

self.api_stage = stage
try:
self.check_stage_name(stage)
except ValueError:
raise ValueError(
"API stage names must match a-zA-Z0-9_ ; '{0!s}' does not.".format(
stage
)
)

if command not in ["status", "manage"]:
if not self.vargs.get("json", None):
Expand Down Expand Up @@ -1789,6 +1797,8 @@ 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_")
Expand Down Expand Up @@ -2483,17 +2493,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

0 comments on commit dbbdd58

Please sign in to comment.