Skip to content

Commit

Permalink
fix(sdk): cleanup empty secret names (#12367)
Browse files Browse the repository at this point in the history
  • Loading branch information
anshbansal authored Jan 16, 2025
1 parent b7b541c commit 7eaadb0
Showing 1 changed file with 12 additions and 21 deletions.
33 changes: 12 additions & 21 deletions metadata-ingestion/src/datahub/secret/datahub_secrets_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit 7eaadb0

Please sign in to comment.