From c60bab21883ffd3dd963e6817e470cea7d6f7937 Mon Sep 17 00:00:00 2001 From: Will Boyce Date: Wed, 23 Jun 2021 22:26:20 +0100 Subject: [PATCH] relax stage name restrictions when not using apigateway --- tests/test_bad_stage_name_settings.json | 4 +++- tests/tests.py | 8 +++----- zappa/cli.py | 19 ++++++------------- 3 files changed, 12 insertions(+), 19 deletions(-) diff --git a/tests/test_bad_stage_name_settings.json b/tests/test_bad_stage_name_settings.json index 65f1aa723..783c6acd8 100644 --- a/tests/test_bad_stage_name_settings.json +++ b/tests/test_bad_stage_name_settings.json @@ -1,5 +1,6 @@ { "ttt-888": { + "apigateway_enabled": true, "touch": false, "s3_bucket": "lmbda", "app_function": "tests.test_app.hello_world", @@ -29,6 +30,7 @@ ] }, "devor": { + "apigateway_enabled": true, "s3_bucket": "lmbda", "app_function": "tests.test_app.hello_world", "callbacks": { @@ -45,4 +47,4 @@ "expression": "rate(1 minute)" }] } -} +} \ No newline at end of file diff --git a/tests/tests.py b/tests/tests.py index 52c3a6eb7..d5ecf5ac0 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -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() diff --git a/zappa/cli.py b/zappa/cli.py index 44f462753..728c163b1 100755 --- a/zappa/cli.py +++ b/zappa/cli.py @@ -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"]: @@ -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): """ @@ -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(