diff --git a/kedro-telemetry/kedro_telemetry/masking.py b/kedro-telemetry/kedro_telemetry/masking.py index fe5f0a3f6..cfe637e3e 100644 --- a/kedro-telemetry/kedro_telemetry/masking.py +++ b/kedro-telemetry/kedro_telemetry/masking.py @@ -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 diff --git a/kedro-telemetry/kedro_telemetry/plugin.py b/kedro-telemetry/kedro_telemetry/plugin.py index 0e654734f..b76f9163f 100644 --- a/kedro-telemetry/kedro_telemetry/plugin.py +++ b/kedro-telemetry/kedro_telemetry/plugin.py @@ -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 @@ -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(