Skip to content

Commit

Permalink
Merge pull request #772 from nolar/security-only-fstrings
Browse files Browse the repository at this point in the history
Use only pure f-strings for logs, avoid %s/%r formatting
  • Loading branch information
nolar authored May 14, 2021
2 parents 9674f06 + 2de5a6c commit 8d8059f
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs/walkthrough/creation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ We will use the official Kubernetes client library (``pip install kubernetes``):
body=data,
)
logger.info(f"PVC child is created: %s", obj)
logger.info(f"PVC child is created: {obj}")
And let us try it in action (assuming the operator is running in the background):

Expand Down
2 changes: 1 addition & 1 deletion docs/walkthrough/deletion.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ Let's extend the creation handler:
body=data,
)
logger.info(f"PVC child is created: %s", obj)
logger.info(f"PVC child is created: {obj}")
return {'pvc-name': obj.metadata.name}
Expand Down
4 changes: 2 additions & 2 deletions docs/walkthrough/updates.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ with one additional line:
body=data,
)
logger.info(f"PVC child is created: %s", obj)
logger.info(f"PVC child is created: {obj}")
return {'pvc-name': obj.metadata.name}
Expand Down Expand Up @@ -98,7 +98,7 @@ and patches the PVC with the new size from the EVC::
body=pvc_patch,
)

logger.info(f"PVC child is updated: %s", obj)
logger.info(f"PVC child is updated: {obj}")

Now, let's change the EVC's size:

Expand Down
2 changes: 1 addition & 1 deletion kopf/_cogs/aiokits/aiotasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ async def guard(
raise
except Exception as e:
if logger is not None:
logger.exception(f"{capname} has failed: %s", e)
logger.exception(f"{capname} has failed: {e}")
raise
else:
if logger is not None and not finishable:
Expand Down
2 changes: 1 addition & 1 deletion kopf/_cogs/clients/watching.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ async def continuous_watch(

# Ensure that the event is something we understand and can handle.
if raw_type not in ['ADDED', 'MODIFIED', 'DELETED']:
logger.warning("Ignoring an unsupported event type: %r", raw_input)
logger.warning(f"Ignoring an unsupported event type: {raw_input!r}")
continue

# Keep the latest seen resource version for continuation of the stream on disconnects.
Expand Down
6 changes: 3 additions & 3 deletions kopf/_core/actions/execution.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,18 +304,18 @@ async def execute_handler_once(

# Definitely a temporary error, regardless of the error strictness.
except TemporaryError as e:
logger.error(f"{handler} failed temporarily: %s", str(e) or repr(e))
logger.error(f"{handler} failed temporarily: {str(e) or repr(e)}")
return Outcome(final=False, exception=e, delay=e.delay, subrefs=subrefs)

# Same as permanent errors below, but with better logging for our internal cases.
except HandlerTimeoutError as e:
logger.error(f"%s", str(e) or repr(e)) # already formatted
logger.error(f"{str(e) or repr(e)}") # already formatted
return Outcome(final=True, exception=e, subrefs=subrefs)
# TODO: report the handling failure somehow (beside logs/events). persistent status?

# Definitely a permanent error, regardless of the error strictness.
except PermanentError as e:
logger.error(f"{handler} failed permanently: %s", str(e) or repr(e))
logger.error(f"{handler} failed permanently: {str(e) or repr(e)}")
return Outcome(final=True, exception=e, subrefs=subrefs)
# TODO: report the handling failure somehow (beside logs/events). persistent status?

Expand Down
2 changes: 1 addition & 1 deletion kopf/_core/engines/probing.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ async def get_health(

# Log with the actual URL: normalised, with hostname/port set.
url = urllib.parse.urlunsplit([parts.scheme, f'{host}:{port}', path, '', ''])
logger.debug("Serving health status at %s", url)
logger.debug(f"Serving health status at {url}")
if ready_flag is not None:
ready_flag.set()

Expand Down
4 changes: 2 additions & 2 deletions kopf/_core/reactor/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,9 +406,9 @@ async def process_changing_cause(

# Inform on the current cause/event on every processing cycle. Even if there are
# no handlers -- to show what has happened and why the diff-base is patched.
logger.debug(f"{title.capitalize()} is in progress: %r", body)
logger.debug(f"{title.capitalize()} is in progress: {body!r}")
if cause.diff and cause.old is not None and cause.new is not None:
logger.debug(f"{title.capitalize()} diff: %r", cause.diff)
logger.debug(f"{title.capitalize()} diff: {cause.diff!r}")

if cause_handlers:
outcomes = await execution.execute_handlers_once(
Expand Down
2 changes: 1 addition & 1 deletion kopf/_core/reactor/queueing.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,4 +363,4 @@ async def _wait_for_depletion(

# The last check if the termination is going to be graceful or not.
if streams:
logger.warning("Unprocessed streams left for %r.", list(streams.keys()))
logger.warning(f"Unprocessed streams left for {list(streams.keys())!r}.")
4 changes: 2 additions & 2 deletions kopf/_core/reactor/running.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,9 +436,9 @@ async def _stop_flag_checker(
if result is None:
logger.info("Stop-flag is raised. Operator is stopping.")
elif isinstance(result, signal.Signals):
logger.info("Signal %s is received. Operator is stopping.", result.name)
logger.info(f"Signal {result.name!s} is received. Operator is stopping.")
else:
logger.info("Stop-flag is set to %r. Operator is stopping.", result)
logger.info(f"Stop-flag is set to {result!r}. Operator is stopping.")


async def _ultimate_termination(
Expand Down

0 comments on commit 8d8059f

Please sign in to comment.