Skip to content

Commit

Permalink
chore(logging): Replace warn logging with info/error
Browse files Browse the repository at this point in the history
Also, respect the `silent` parameter a bit more strictly; if
`silent=True`, don't emit log lines.
  • Loading branch information
jperras committed Jul 20, 2023
1 parent e035374 commit 47278f3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
20 changes: 10 additions & 10 deletions dynaconf_aws_loader/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,17 +219,17 @@ def _fetch_single_parameter(
try:
value = client.get_parameter(Name=path, WithDecryption=True)
except ClientError as exc:
if exc.response.get("Error", {}).get("Code") == "ParameterNotFound":
logger.warn("Parameter with path %s does not exist in AWS SSM." % path)
if silent:
return
if exc.response.get("Error", {}).get("Code") == "ParameterNotFound":
logger.info("Parameter with path %s does not exist in AWS SSM." % path)
raise
except BotoCoreError:
logger.warn(
"Could not connect to AWS SSM at endpoint %s." % client.meta.endpoint_url
)
if silent:
return
logger.error(
"Could not connect to AWS SSM at endpoint %s." % client.meta.endpoint_url
)
raise

if data := value.get("Parameter"):
Expand Down Expand Up @@ -264,17 +264,17 @@ def _fetch_all_parameters(
data.append({parameter["Name"]: parameter["Value"]})

except ClientError as exc:
if exc.response.get("Error", {}).get("Code") == "ParameterNotFound":
logger.warn("Parameter with path %s does not exist in AWS SSM." % path)
if silent:
return
if exc.response.get("Error", {}).get("Code") == "ParameterNotFound":
logger.info("Parameter with path %s does not exist in AWS SSM." % path)
raise
except BotoCoreError:
logger.warn(
"Could not connect to AWS SSM at endpoint %s." % client.meta.endpoint_url
)
if silent:
return
logger.error(
"Could not connect to AWS SSM at endpoint %s." % client.meta.endpoint_url
)
raise

result = parse_conf_data(data=slashes_to_dict(data), tomlfy=True)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def test_fetch_single_parameter_missing(stubbed_client, caplog):

with stubbed_client:
with pytest.raises(stubbed_client.client.exceptions.ParameterNotFound):
with caplog.at_level(logging.WARN, logger="dynaconf.aws_loader"):
with caplog.at_level(logging.INFO, logger="dynaconf.aws_loader"):
_fetch_single_parameter(
stubbed_client.client,
project_prefix="foobar",
Expand All @@ -146,7 +146,7 @@ def test_fetch_single_parameter_missing(stubbed_client, caplog):
assert caplog.record_tuples == [
(
"dynaconf.aws_loader",
logging.WARN,
logging.INFO,
"Parameter with path /foobar/testing/baldur does not exist in AWS SSM.",
)
]
Expand All @@ -166,7 +166,7 @@ def test_fetch_all_parameters_missing(stubbed_client, caplog):

with stubbed_client:
with pytest.raises(stubbed_client.client.exceptions.ParameterNotFound):
with caplog.at_level(logging.WARN, logger="dynaconf.aws_loader"):
with caplog.at_level(logging.INFO, logger="dynaconf.aws_loader"):
_fetch_all_parameters(
stubbed_client.client,
project_prefix="foobar",
Expand All @@ -177,7 +177,7 @@ def test_fetch_all_parameters_missing(stubbed_client, caplog):
assert caplog.record_tuples == [
(
"dynaconf.aws_loader",
logging.WARN,
logging.INFO,
"Parameter with path /foobar/testing does not exist in AWS SSM.",
)
]
Expand Down

0 comments on commit 47278f3

Please sign in to comment.