Skip to content
This repository has been archived by the owner on Sep 14, 2020. It is now read-only.

[305] Hide authorisation headers of exceptions' reprs #306

Merged
merged 3 commits into from
Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions kopf/clients/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@ async def post_event(
except aiohttp.ClientResponseError as e:
# Events are helpful but auxiliary, they should not fail the handling cycle.
# Yet we want to notice that something went wrong (in logs).
logger.warning("Failed to post an event. Ignoring and continuing. "
f"Error: {e!r}. "
logger.warning(f"Failed to post an event. Ignoring and continuing. "
f"Status: {e.status}. Message: {e.message}. "
f"Event: type={type!r}, reason={reason!r}, message={message!r}.")
6 changes: 3 additions & 3 deletions kopf/reactor/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


class ActivityHandlerFn(Protocol):
def __call__(
def __call__( # lgtm[py/similar-function]
self,
*args: Any,
logger: Union[logging.Logger, logging.LoggerAdapter],
Expand All @@ -28,7 +28,7 @@ def __call__(


class ResourceHandlerFn(Protocol):
def __call__(
def __call__( # lgtm[py/similar-function]
self,
*args: Any,
type: str,
Expand All @@ -50,7 +50,7 @@ def __call__(


class WhenHandlerFn(Protocol):
def __call__(
def __call__( # lgtm[py/similar-function]
self,
*args: Any,
type: str,
Expand Down
2 changes: 1 addition & 1 deletion kopf/reactor/queueing.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ async def worker(
replenished.clear()
try:
await processor(event=event, replenished=replenished)
except Exception as e:
except Exception:
# TODO: processor is a functools.partial. make the prints a bit nicer by removing it.
logger.exception(f"{processor} failed with an exception. Ignoring the event.")
# raise
Expand Down
2 changes: 1 addition & 1 deletion kopf/reactor/running.py
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ async def _root_task_checker(
logger.debug(f"Root task {name!r} is cancelled.")
raise
except Exception as e:
logger.error(f"Root task {name!r} is failed: %r", e)
logger.error(f"Root task {name!r} is failed: %s", e)
raise # fail the process and its exit status
else:
logger.warning(f"Root task {name!r} is finished unexpectedly.")
Expand Down
2 changes: 1 addition & 1 deletion kopf/reactor/states.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def with_outcome(
success=bool(outcome.final and outcome.exception is None),
failure=bool(outcome.final and outcome.exception is not None),
retries=(self.retries if self.retries is not None else 0) + 1,
message=None if outcome.exception is None else f'{outcome.exception}',
message=None if outcome.exception is None else str(outcome.exception),
_origin=self._origin,
)

Expand Down
24 changes: 24 additions & 0 deletions tests/k8s/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,27 @@ async def test_message_is_cut_to_max_length(
assert '...' in data['message']
assert data['message'].startswith('start')
assert data['message'].endswith('end')


@pytest.mark.parametrize('status', [555, 500, 404, 403, 401])
async def test_headers_are_not_leaked(
resp_mocker, aresponses, hostname, assert_logs, status):

post_mock = resp_mocker(return_value=aresponses.Response(status=status, reason='boo!'))
aresponses.add(hostname, EVENTS_CORE_V1_CRD.get_url(namespace='ns'), 'post', post_mock)

obj = {'apiVersion': 'group/version',
'kind': 'kind',
'metadata': {'namespace': 'ns',
'name': 'name',
'uid': 'uid'}}
ref = build_object_reference(obj)
await post_event(ref=ref, type='type', reason='reason', message='message')

assert_logs([
f"Failed to post an event. .* Status: {status}. Message: boo!",
], prohibited=[
"ClientResponseError",
"RequestInfo",
"headers=",
])