From 7eaadb03b6da03c4e48d9f61340c579d7354205a Mon Sep 17 00:00:00 2001 From: Aseem Bansal Date: Thu, 16 Jan 2025 23:26:21 +0530 Subject: [PATCH] fix(sdk): cleanup empty secret names (#12367) --- .../datahub/secret/datahub_secrets_client.py | 33 +++++++------------ 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/metadata-ingestion/src/datahub/secret/datahub_secrets_client.py b/metadata-ingestion/src/datahub/secret/datahub_secrets_client.py index c60aeff5db2f3f..6cd542c03a4260 100644 --- a/metadata-ingestion/src/datahub/secret/datahub_secrets_client.py +++ b/metadata-ingestion/src/datahub/secret/datahub_secrets_client.py @@ -11,34 +11,25 @@ class DataHubSecretsClient: def __init__(self, graph: DataHubGraph): self.graph = graph + def _cleanup_secret_name(self, secret_names: List[str]) -> List[str]: + """Remove empty strings from the list of secret names.""" + return [secret_name for secret_name in secret_names if secret_name] + def get_secret_values(self, secret_names: List[str]) -> Dict[str, Optional[str]]: if len(secret_names) == 0: return {} - request_json = { - "query": """query getSecretValues($input: GetSecretValuesInput!) {\n - getSecretValues(input: $input) {\n - name\n - value\n - }\n + res_data = self.graph.execute_graphql( + query="""query getSecretValues($input: GetSecretValuesInput!) { + getSecretValues(input: $input) { + name + value + } }""", - "variables": {"input": {"secrets": secret_names}}, - } - # TODO: Use graph.execute_graphql() instead. - - # Fetch secrets using GraphQL API f - response = self.graph._session.post( - f"{self.graph.config.server}/api/graphql", json=request_json + variables={"input": {"secrets": self._cleanup_secret_name(secret_names)}}, ) - response.raise_for_status() - - # Verify response - res_data = response.json() - if "errors" in res_data: - raise Exception("Failed to retrieve secrets from DataHub.") - # Convert list of name, value secret pairs into a dict and return - secret_value_list = res_data["data"]["getSecretValues"] + secret_value_list = res_data["getSecretValues"] secret_value_dict = dict() for secret_value in secret_value_list: secret_value_dict[secret_value["name"]] = secret_value["value"]