예제 #1
0
    def save_config(
        self,
        parameter_overrides,
        config_env=DEFAULT_ENV,
        config_file=None,
        signing_profiles=None,
        image_repositories=None,
        **kwargs,
    ):

        ctx, samconfig = self.get_config_ctx(config_file)

        cmd_names = get_cmd_names(ctx.info_name, ctx)

        for key, value in kwargs.items():
            if isinstance(value, (list, tuple)):
                value = " ".join(val for val in value)
            if value:
                samconfig.put(cmd_names, self.section, key, value, env=config_env)

        self._save_parameter_overrides(cmd_names, config_env, parameter_overrides, samconfig)
        self._save_image_repositories(cmd_names, config_env, samconfig, image_repositories)
        self._save_signing_profiles(cmd_names, config_env, samconfig, signing_profiles)

        samconfig.flush()

        click.echo("\n\tSaved arguments to config file")
        click.echo("\tRunning 'sam deploy' for future deployments will use the parameters saved above.")
        click.echo("\tThe above parameters can be changed by modifying samconfig.toml")
        click.echo(
            "\tLearn more about samconfig.toml syntax at "
            "\n\thttps://docs.aws.amazon.com/serverless-application-model/latest/"
            "developerguide/serverless-sam-cli-config.html\n"
        )
예제 #2
0
def save_config(template_file, parameter_overrides, **kwargs):

    section = CONFIG_SECTION
    ctx, samconfig = get_config_ctx(template_file)

    cmd_names = get_cmd_names(ctx.info_name, ctx)

    for key, value in kwargs.items():
        if isinstance(value, (list, tuple)):
            value = " ".join(val for val in value)
        if value:
            samconfig.put(cmd_names, section, key, value)

    if parameter_overrides:
        _params = []
        for key, value in parameter_overrides.items():
            if isinstance(value, dict):
                if not value.get("Hidden"):
                    _params.append(f"{key}={value.get('Value')}")
            else:
                _params.append(f"{key}={value}")
        if _params:
            samconfig.put(cmd_names, section, "parameter_overrides", " ".join(_params))

    samconfig.flush()

    click.echo(f"\n\tSaved arguments to config file")
    click.echo("\tRunning 'sam deploy' for future deployments will use the parameters saved above.")
    click.echo("\tThe above parameters can be changed by modifying samconfig.toml")
    click.echo(
        "\tLearn more about samconfig.toml syntax at "
        "\n\thttps://docs.aws.amazon.com/serverless-application-model/latest/"
        "developerguide/serverless-sam-cli-config.html"
    )
예제 #3
0
def get_ctx_defaults(cmd_name, provider, ctx, config_env_name, config_file=None):
    """
    Get the set of the parameters that are needed to be set into the click command.
    This function also figures out the command name by looking up current click context's parent
    and constructing the parsed command name that is used in default configuration file.
    If a given cmd_name is start-api, the parsed name is "local_start_api".
    provider is called with `config_file`, `config_env_name` and `parsed_cmd_name`.

    :param cmd_name: `sam` command name
    :param provider: provider to be called for reading configuration file
    :param ctx: Click context
    :param config_env_name: config-env within configuration file, sam configuration file will be relative to the
                            supplied original template if its path is not specified
    :param config_file: configuration file name
    :return: dictionary of defaults for parameters
    """

    return provider(config_file, config_env_name, get_cmd_names(cmd_name, ctx))
예제 #4
0
def get_ctx_defaults(cmd_name, provider, ctx, config_env_name):
    """
    Get the set of the parameters that are needed to be set into the click command.
    This function also figures out the command name by looking up current click context's parent
    and constructing the parsed command name that is used in default configuration file.
    If a given cmd_name is start-api, the parsed name is "local_start_api".
    provider is called with `config_file`, `config_env_name` and `parsed_cmd_name`.

    :param cmd_name: `sam` command name
    :param provider: provider to be called for reading configuration file
    :param ctx: Click context
    :param config_env_name: config-env within configuration file
    :return: dictionary of defaults for parameters
    """

    # `config_dir` will be a directory relative to SAM template, if it is available. If not it's relative to cwd
    config_dir = getattr(ctx, "samconfig_dir", None) or os.getcwd()
    return provider(config_dir, config_env_name, get_cmd_names(cmd_name, ctx))