-
Notifications
You must be signed in to change notification settings - Fork 40
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
Add secret manager in weather-dl. #374
base: main
Are you sure you want to change the base?
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
import typing as t | ||
import numpy as np | ||
from collections import OrderedDict | ||
from google.cloud import secretmanager | ||
from urllib.parse import urlparse | ||
|
||
from .clients import CLIENTS | ||
|
@@ -460,6 +461,23 @@ def prepare_target_name(config: Config) -> str: | |
return target | ||
|
||
|
||
def get_secret(secret_key: str) -> t.Dict: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional: please return a |
||
"""Retrieve the secret value from the Google Cloud Secret Manager. | ||
|
||
Parameters: | ||
secret_key (str): The name or identifier of the secret in the Google | ||
Cloud Secret Manager. | ||
|
||
Returns: | ||
dict: A dictionary containing the retrieved secret data. | ||
""" | ||
client = secretmanager.SecretManagerServiceClient() | ||
response = client.access_secret_version(request={"name": secret_key}) | ||
payload = response.payload.data.decode("UTF-8") | ||
secret_dict = json.loads(payload) | ||
return secret_dict | ||
|
||
|
||
def get_subsections(config: Config) -> t.List[t.Tuple[str, t.Dict]]: | ||
"""Collect parameter subsections from main configuration. | ||
|
||
|
@@ -471,17 +489,14 @@ def get_subsections(config: Config) -> t.List[t.Tuple[str, t.Dict]]: | |
For example: | ||
``` | ||
[parameters.alice] | ||
api_key=KKKKK1 | ||
api_url=UUUUU1 | ||
secret_key=projects/PROJECT_NAME/secrets/SECRET_NAME/versions/1 | ||
[parameters.bob] | ||
api_key=KKKKK2 | ||
api_url=UUUUU2 | ||
secret_key=projects/PROJECT_NAME/secrets/SECRET_NAME/versions/1 | ||
[parameters.eve] | ||
api_key=KKKKK3 | ||
api_url=UUUUU3 | ||
secret_key=projects/PROJECT_NAME/secrets/SECRET_NAME/versions/1 | ||
Comment on lines
+492
to
+496
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's keep these examples. |
||
``` | ||
""" | ||
return [(name, params) for name, params in config.kwargs.items() | ||
return [(name, get_secret(params.get('secret_key'))) for name, params in config.kwargs.items() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should support both API keys and secrets manager. |
||
if isinstance(params, dict)] or [('default', {})] | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a separate section that demos secrets mgr. Users should see examples of both ways of adding keys.