Skip to content

Commit

Permalink
Fix masking
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Sorokin <dmd40in@gmail.com>
  • Loading branch information
DimedS committed Feb 9, 2024
1 parent b675485 commit 516ff75
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
24 changes: 16 additions & 8 deletions kedro-telemetry/kedro_telemetry/masking.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,30 @@ def _get_cli_structure(
return output


def _mask_unrecognized_arg(arg: str, vocabulary: Set[str]) -> str:
return arg if arg in vocabulary else MASK


def _mask_kedro_cli(cli_struct: Dict[str, Any], command_args: List[str]) -> List[str]:
"""Takes a dynamic vocabulary (based on `KedroCLI`) and returns
a masked CLI input"""
output = []
vocabulary = _get_vocabulary(cli_struct)
mask_next = False
for arg in command_args:
if arg.startswith("-"):
for arg_part in arg.split("="):
if arg_part in vocabulary:
output.append(arg_part)
elif arg_part:
output.append(MASK)
elif arg in vocabulary:
output.append(arg)
elif arg:
if "=" in arg:
arg_left = arg.split("=")[0]
output.append(_mask_unrecognized_arg(arg_left, vocabulary))
output.append(MASK)
else:
mask_next = True
output.append(_mask_unrecognized_arg(arg, vocabulary))
elif mask_next:
output.append(MASK)
mask_next = False
else:
output.append(_mask_unrecognized_arg(arg, vocabulary))
return output


Expand Down
15 changes: 8 additions & 7 deletions kedro-telemetry/kedro_telemetry/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,6 @@ def before_command_run(
):
"""Hook implementation to send command run data to Heap"""
try:
# get KedroCLI and its structure from actual project root
cli = KedroCLI(project_path=Path.cwd())
cli_struct = _get_cli_structure(cli_obj=cli, get_help=False)
masked_command_args = _mask_kedro_cli(
cli_struct=cli_struct, command_args=command_args
)
main_command = masked_command_args[0] if masked_command_args else "kedro"
if not project_metadata: # in package mode
return

Expand All @@ -78,6 +71,14 @@ def before_command_run(
)
return

# get KedroCLI and its structure from actual project root
cli = KedroCLI(project_path=Path.cwd())
cli_struct = _get_cli_structure(cli_obj=cli, get_help=False)
masked_command_args = _mask_kedro_cli(
cli_struct=cli_struct, command_args=command_args
)
main_command = masked_command_args[0] if masked_command_args else "kedro"

logger.debug("You have opted into product usage analytics.")
hashed_username = _get_hashed_username()
project_properties = _get_project_properties(
Expand Down

0 comments on commit 516ff75

Please sign in to comment.