From 6ce3b5db8ed9b880265459691b824d071504ae27 Mon Sep 17 00:00:00 2001 From: Aseem Bansal Date: Wed, 3 Jul 2024 12:25:15 +0530 Subject: [PATCH] feat(cli): add more details to get cli (#10815) --- metadata-ingestion/src/datahub/cli/cli_utils.py | 8 +++++++- metadata-ingestion/src/datahub/cli/get_cli.py | 13 +++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/metadata-ingestion/src/datahub/cli/cli_utils.py b/metadata-ingestion/src/datahub/cli/cli_utils.py index 1bb3b01e078dd..d8939ddcff09c 100644 --- a/metadata-ingestion/src/datahub/cli/cli_utils.py +++ b/metadata-ingestion/src/datahub/cli/cli_utils.py @@ -522,6 +522,7 @@ def get_aspects_for_entity( aspects: List[str], typed: bool = False, cached_session_host: Optional[Tuple[Session, str]] = None, + details: bool = False, ) -> Dict[str, Union[dict, _Aspect]]: # Process non-timeseries aspects non_timeseries_aspects = [a for a in aspects if a not in TIMESERIES_ASPECT_MAP] @@ -553,7 +554,12 @@ def get_aspects_for_entity( aspect_name ) - aspect_dict = a["value"] + if details: + aspect_dict = a + for k in ["name", "version", "type"]: + del aspect_dict[k] + else: + aspect_dict = a["value"] if not typed: aspect_map[aspect_name] = aspect_dict elif aspect_py_class: diff --git a/metadata-ingestion/src/datahub/cli/get_cli.py b/metadata-ingestion/src/datahub/cli/get_cli.py index 6b779f8565a7f..46e2fdf5b1f79 100644 --- a/metadata-ingestion/src/datahub/cli/get_cli.py +++ b/metadata-ingestion/src/datahub/cli/get_cli.py @@ -21,10 +21,17 @@ def get() -> None: @get.command() @click.option("--urn", required=False, type=str) @click.option("-a", "--aspect", required=False, multiple=True, type=str) +@click.option( + "--details/--no-details", + required=False, + is_flag=True, + default=False, + help="Whether to print details from database which help in audit.", +) @click.pass_context @upgrade.check_upgrade @telemetry.with_telemetry() -def urn(ctx: Any, urn: Optional[str], aspect: List[str]) -> None: +def urn(ctx: Any, urn: Optional[str], aspect: List[str], details: bool) -> None: """ Get metadata for an entity with an optional list of aspects to project. This works for both versioned aspects and timeseries aspects. For timeseries aspects, it fetches the latest value. @@ -39,7 +46,9 @@ def urn(ctx: Any, urn: Optional[str], aspect: List[str]) -> None: logger.debug(f"Using urn from args {urn}") click.echo( json.dumps( - get_aspects_for_entity(entity_urn=urn, aspects=aspect, typed=False), + get_aspects_for_entity( + entity_urn=urn, aspects=aspect, typed=False, details=details + ), sort_keys=True, indent=2, )