Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand parameter overrides #7876

Open
wants to merge 17 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Lint
  • Loading branch information
sigJoe committed Feb 6, 2025
commit 4c740cfc025e859108dd21cb2b9174ab90ee8a26
21 changes: 10 additions & 11 deletions samcli/cli/types.py
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@
from typing import Dict, List, Optional, Union

import click

from ruamel.yaml.comments import CommentedMap, CommentedSeq

from samcli.lib.config.file_manager import FILE_MANAGER_MAPPER
@@ -64,7 +63,8 @@ def _unquote_wrapped_quotes(value):

return value.replace("\\ ", " ").replace('\\"', '"').replace("\\'", "'")

def _flatten_list(data: list) -> list:

def _flatten_list(data: list | tuple) -> list:
"""
Recursively flattens lists and other list-like types for easy sequential processing.
This also helps with lists combined with YAML anchors & aliases.
@@ -97,7 +97,6 @@ class CfnParameterOverridesType(click.ParamType):
__EXAMPLE_2 = "KeyPairName=MyKey InstanceType=t1.micro"
__EXAMPLE_3 = "file://MyParams.yaml"


# Regex that parses CloudFormation parameter key-value pairs:
# https://regex101.com/r/xqfSjW/2
# https://regex101.com/r/xqfSjW/5
@@ -116,8 +115,8 @@ class CfnParameterOverridesType(click.ParamType):

def _normalize_parameters(self, values, param, ctx):
"""
Normalizes parameter overrides into key-value pairs of strings
Later keys overwrite previous ones in case of key conflict
Normalizes parameter overrides into key-value pairs of strings
Later keys overwrite previous ones in case of key conflict
"""
if values in (("",), "", None) or values == {}:
LOG.debug("Empty parameter set (%s)", values)
@@ -130,7 +129,7 @@ def _normalize_parameters(self, values, param, ctx):
parameters = {}
for value in values:
if isinstance(value, str):
if value.startswith('file://'):
if value.startswith("file://"):
filepath = Path(value[7:])
if not filepath.is_file():
self.fail(f"{value} was not found or is a directory", param, ctx)
@@ -148,7 +147,8 @@ def _normalize_parameters(self, values, param, ctx):
break
else:
self.fail(
f"{value} is not a valid format. It must look something like '{self.__EXAMPLE_1}', '{self.__EXAMPLE_2}', or '{self.__EXAMPLE_3}'",
f"{value} is not a valid format. It must look something like "
f"'{self.__EXAMPLE_1}', '{self.__EXAMPLE_2}', or '{self.__EXAMPLE_3}'",
param,
ctx,
)
@@ -169,16 +169,15 @@ def _normalize_parameters(self, values, param, ctx):

result = {}
for key, param_value in parameters.items():
result[_unquote_wrapped_quotes(key)] = _unquote_wrapped_quotes(param_value)
result[_unquote_wrapped_quotes(key.lower())] = _unquote_wrapped_quotes(param_value)
LOG.debug("Output parameters: %s", result)
return result


def convert(self, values, param, ctx):
# Merge samconfig with CLI parameter-overrides
if isinstance(values, tuple): # Tuple implies CLI
if isinstance(values, tuple): # Tuple implies CLI
# default_map was populated from samconfig
default_map = ctx.default_map.get('parameter_overrides', {})
default_map = ctx.default_map.get("parameter_overrides", {})
LOG.debug("Default map: %s", default_map)
LOG.debug("Current values: %s", values)
# Easy merge - will flatten later