def setUp(self):
     setattr(
         _local,
         "stack",
         [
             Context(command="test",
                     allow_extra_args=False,
                     allow_interspersed_args=False,
                     ignore_unknown_options=False)
         ],
     )
     with tempfile_platform_independent() as template:
         self.template_file = os.path.abspath(template.name)
         self.samconfig_dir = os.path.dirname(self.template_file)
         self.samconfig_path = os.path.join(self.samconfig_dir,
                                            DEFAULT_CONFIG_FILE_NAME)
     self.gc = GuidedConfig(template_file=self.template_file,
                            section="dummy")
    def run(self):

        try:
            _parameter_override_keys = get_template_parameters(
                template_file=self.template_file)
        except ValueError as ex:
            LOG.debug("Failed to parse SAM template", exc_info=ex)
            raise GuidedDeployFailedError(str(ex)) from ex

        guided_config = GuidedConfig(template_file=self.template_file,
                                     section=self.config_section)
        guided_config.read_config_showcase(
            self.config_file or DEFAULT_CONFIG_FILE_NAME, )

        self.guided_prompts(_parameter_override_keys)

        if self.save_to_config:
            guided_config.save_config(
                self._parameter_overrides,
                self.config_env or DEFAULT_ENV,
                self.config_file or DEFAULT_CONFIG_FILE_NAME,
                stack_name=self.guided_stack_name,
                s3_bucket=self.guided_s3_bucket,
                s3_prefix=self.guided_s3_prefix,
                image_repositories=self.guided_image_repositories,
                region=self.guided_region,
                profile=self.guided_profile,
                confirm_changeset=self.confirm_changeset,
                capabilities=self._capabilities,
                signing_profiles=self.signing_profiles,
            )
示例#3
0
    def run(self):

        try:
            _parameter_override_keys = get_template_parameters(
                template_file=self.template_file)
        except ValueError as ex:
            LOG.debug("Failed to parse SAM template", exc_info=ex)
            raise GuidedDeployFailedError(str(ex))

        guided_config = GuidedConfig(template_file=self.template_file,
                                     section=self.config_section)
        guided_config.read_config_showcase()

        self.guided_prompts(_parameter_override_keys)

        if self.save_to_config:
            guided_config.save_config(
                self._parameter_overrides,
                stack_name=self.guided_stack_name,
                s3_bucket=self.guided_s3_bucket,
                s3_prefix=self.guided_s3_prefix,
                region=self.guided_region,
                profile=self.guided_profile,
                confirm_changeset=self.confirm_changeset,
                capabilities=self._capabilities,
            )
示例#4
0
class TestGuidedConfig(TestCase):
    def setUp(self):
        setattr(
            _local,
            "stack",
            [
                Context(command="test",
                        allow_extra_args=False,
                        allow_interspersed_args=False,
                        ignore_unknown_options=False)
            ],
        )
        with tempfile_platform_independent() as template:
            self.template_file = os.path.abspath(template.name)
            self.samconfig_dir = os.path.dirname(self.template_file)
            self.samconfig_path = os.path.join(self.samconfig_dir,
                                               DEFAULT_CONFIG_FILE_NAME)
        self.gc = GuidedConfig(template_file=self.template_file,
                               section="dummy")

    def tearDown(self):
        delattr(_local, "stack")
        remove(self.samconfig_path)

    def test_guided_config_init(self):
        ctx, samconfig = self.gc.get_config_ctx()
        self.assertTrue(isinstance(ctx, click.Context))
        self.assertTrue(isinstance(samconfig, SamConfig))

    def test_read_config_showcase(self):
        # No samconfig file present, no errors thrown.
        self.gc.read_config_showcase()
        with open(self.samconfig_path, "wb") as f:
            f.write(b"default\\n")
        # Empty samconfig, config file found but invalid
        with self.assertRaises(GuidedDeployFailedError):
            self.gc.read_config_showcase()

    @patch("samcli.commands.deploy.guided_config.get_cmd_names")
    def test_save_config(self, patched_cmd_names):
        patched_cmd_names.return_value = ["local", "start-api"]
        # Should save with no errors.
        signing_profiles = {
            "a": {
                "profile_name": "profile",
                "profile_owner": "owner"
            },
            "b": {
                "profile_name": "profile"
            },
        }
        self.gc.save_config(parameter_overrides={"a": "b"},
                            signing_profiles=signing_profiles,
                            port="9090")