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 Oct 1, 2021
1 parent 385c22d commit c60bab2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 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
19 changes: 6 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,13 @@ 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)
)

def check_environment(self, environment):
"""
Expand Down Expand Up @@ -2483,17 +2487,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 c60bab2

Please sign in to comment.