Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(cli): extract method, change wording #7134

Merged
merged 2 commits into from
Jan 25, 2023
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 metadata-ingestion/src/datahub/cli/delete_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@ def delete(
"""Delete metadata from datahub using a single urn or a combination of filters"""

cli_utils.test_connectivity_complain_exit("delete")
# one of urn / platform / env / query must be provided
# one of these must be provided
if not urn and not platform and not env and not query and not registry_id:
raise click.UsageError(
"You must provide either an urn or a platform or an env or a query for me to delete anything"
"You must provide one of urn / platform / env / query / registry_id in order to delete entities."
)

include_removed: bool
Expand Down
7 changes: 3 additions & 4 deletions metadata-ingestion/src/datahub/cli/put_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import click
from click_default_group import DefaultGroup

from datahub.cli.cli_utils import get_url_and_token, post_entity
from datahub.cli.cli_utils import post_entity
from datahub.emitter.mcp import MetadataChangeProposalWrapper
from datahub.ingestion.graph.client import DataHubGraph, DataHubGraphConfig
from datahub.ingestion.graph.client import get_default_graph
from datahub.metadata.schema_classes import (
DataPlatformInfoClass as DataPlatformInfo,
PlatformTypeClass,
Expand Down Expand Up @@ -97,8 +97,7 @@ def platform(
displayName=display_name or platform_name,
logoUrl=logo,
)
(url, token) = get_url_and_token()
datahub_graph = DataHubGraph(DataHubGraphConfig(server=url, token=token))
datahub_graph = get_default_graph()
jjoyce0510 marked this conversation as resolved.
Show resolved Hide resolved
datahub_graph.emit(
MetadataChangeProposalWrapper(
entityUrn=str(platform_urn), aspect=data_platform_info
Expand Down
6 changes: 2 additions & 4 deletions metadata-ingestion/src/datahub/cli/state_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import click
from click_default_group import DefaultGroup

from datahub.cli.cli_utils import get_url_and_token
from datahub.ingestion.graph.client import DataHubGraph, DataHubGraphConfig
from datahub.ingestion.graph.client import get_default_graph
from datahub.ingestion.source.state.checkpoint import Checkpoint
from datahub.ingestion.source.state.entity_removal_state import GenericCheckpointState
from datahub.ingestion.source.state.stale_entity_removal_handler import (
Expand Down Expand Up @@ -44,8 +43,7 @@ def inspect(
# Note that the platform-instance argument is not generated consistently,
# and is not always equal to the platform_instance config.

(url, token) = get_url_and_token()
jjoyce0510 marked this conversation as resolved.
Show resolved Hide resolved
datahub_graph = DataHubGraph(DataHubGraphConfig(server=url, token=token))
datahub_graph = get_default_graph()
checkpoint_provider = DatahubIngestionCheckpointingProvider(datahub_graph, "cli")

job_name = StaleEntityRemovalHandler.compute_job_id(platform)
Expand Down
7 changes: 6 additions & 1 deletion metadata-ingestion/src/datahub/ingestion/graph/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from requests.adapters import Response
from requests.models import HTTPError

from datahub.cli.cli_utils import get_boolean_env_variable
from datahub.cli.cli_utils import get_boolean_env_variable, get_url_and_token
from datahub.configuration.common import ConfigModel, GraphError, OperationalError
from datahub.emitter.mce_builder import Aspect
from datahub.emitter.rest_emitter import DatahubRestEmitter
Expand Down Expand Up @@ -452,3 +452,8 @@ def get_aspect_counts(self, aspect: str, urn_like: Optional[str] = None) -> int:
args["urnLike"] = urn_like
results = self._post_generic(self._get_aspect_count_endpoint(), args)
return results["value"]


def get_default_graph() -> DataHubGraph:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice!

(url, token) = get_url_and_token()
return DataHubGraph(DataHubGraphConfig(server=url, token=token))