Skip to content

Commit

Permalink
feat: log get_merged_config steps
Browse files Browse the repository at this point in the history
  • Loading branch information
Zane Clark committed Oct 31, 2024
1 parent 6e53452 commit 713ae2d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion schemachange/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def main():
% {"schemachange_version": SCHEMACHANGE_VERSION}
)

config = get_merged_config()
config = get_merged_config(logger=module_logger)
redact_config_secrets(config_secrets=config.secrets)

structlog.configure(
Expand Down
14 changes: 13 additions & 1 deletion schemachange/config/get_merged_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from pathlib import Path
from typing import Union, Optional

import structlog

from schemachange.config.DeployConfig import DeployConfig
from schemachange.config.RenderConfig import RenderConfig
from schemachange.config.parse_cli_args import parse_cli_args
Expand Down Expand Up @@ -36,11 +38,16 @@ def get_yaml_config_kwargs(config_file_path: Optional[Path]) -> dict:
return {k: v for k, v in kwargs.items() if v is not None}


def get_merged_config() -> Union[DeployConfig, RenderConfig]:
def get_merged_config(
logger: structlog.BoundLogger,
) -> Union[DeployConfig, RenderConfig]:
env_kwargs: dict[str, str] = get_env_kwargs()
logger.info("env_kwargs", **env_kwargs)

connection_name = env_kwargs.pop("connection_name", None)

cli_kwargs = parse_cli_args(sys.argv[1:])
logger.info("cli_kwargs", **cli_kwargs)

cli_config_vars = cli_kwargs.pop("config_vars")

Expand All @@ -58,6 +65,8 @@ def get_merged_config() -> Union[DeployConfig, RenderConfig]:
yaml_kwargs = get_yaml_config_kwargs(
config_file_path=config_file_path,
)
logger.info("yaml_kwargs", **yaml_kwargs)

yaml_config_vars = yaml_kwargs.pop("config_vars", None)
if yaml_config_vars is None:
yaml_config_vars = {}
Expand All @@ -77,6 +86,7 @@ def get_merged_config() -> Union[DeployConfig, RenderConfig]:
connections_file_path=connections_file_path,
connection_name=connection_name,
)
logger.info("connection_kwargs", **connection_kwargs)

config_vars = {
**yaml_config_vars,
Expand All @@ -97,6 +107,8 @@ def get_merged_config() -> Union[DeployConfig, RenderConfig]:
if connection_name is not None:
kwargs["connection_name"] = connection_name

logger.info("final kwargs", **kwargs)

if cli_kwargs["subcommand"] == "deploy":
return DeployConfig.factory(**kwargs)
elif cli_kwargs["subcommand"] == "render":
Expand Down

0 comments on commit 713ae2d

Please sign in to comment.