Skip to content

Commit 4257908

Browse files
safoinmestefannica
authored andcommitted
Fix zenml deploy secret stores (zenml-io#2454)
* Refactor AWS and GCP secrets store configuration * Apply suggestions from code review Co-authored-by: Stefan Nica <[email protected]> --------- Co-authored-by: Stefan Nica <[email protected]>
1 parent eea9cb3 commit 4257908

File tree

2 files changed

+57
-34
lines changed

2 files changed

+57
-34
lines changed

src/zenml/zen_stores/secrets_stores/aws_secrets_store.py

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,23 +86,33 @@ def populate_config(cls, values: Dict[str, Any]) -> Dict[str, Any]:
8686
"""
8787
# Search for legacy attributes and populate the connector configuration
8888
# from them, if they exist.
89-
if (
90-
values.get("aws_access_key_id")
91-
and values.get("aws_secret_access_key")
92-
and values.get("region_name")
93-
):
94-
logger.warning(
95-
"The `aws_access_key_id`, `aws_secret_access_key` and "
96-
"`region_name` AWS secrets store attributes are deprecated and "
97-
"will be removed in a future version of ZenML. Please use the "
98-
"`auth_method` and `auth_config` attributes instead."
99-
)
100-
values["auth_method"] = AWSAuthenticationMethods.SECRET_KEY
101-
values["auth_config"] = dict(
102-
aws_access_key_id=values.get("aws_access_key_id"),
103-
aws_secret_access_key=values.get("aws_secret_access_key"),
104-
region=values.get("region_name"),
105-
)
89+
if values.get("region_name"):
90+
if not values.get("aws_access_key_id") or not values.get(
91+
"aws_secret_access_key"
92+
):
93+
logger.warning(
94+
"The `region_name` AWS secrets store attribute is deprecated "
95+
"and will be removed in a future version of ZenML. Please use "
96+
"the `auth_method` and `auth_config` attributes instead. "
97+
"Using an implicit authentication method for AWS Secrets."
98+
)
99+
values["auth_method"] = AWSAuthenticationMethods.IMPLICIT
100+
values["auth_config"] = dict(
101+
region=values.get("region_name"),
102+
)
103+
else:
104+
logger.warning(
105+
"The `aws_access_key_id`, `aws_secret_access_key` and "
106+
"`region_name` AWS secrets store attributes are deprecated and "
107+
"will be removed in a future version of ZenML. Please use the "
108+
"`auth_method` and `auth_config` attributes instead."
109+
)
110+
values["auth_method"] = AWSAuthenticationMethods.SECRET_KEY
111+
values["auth_config"] = dict(
112+
aws_access_key_id=values.get("aws_access_key_id"),
113+
aws_secret_access_key=values.get("aws_secret_access_key"),
114+
region=values.get("region_name"),
115+
)
106116

107117
return values
108118

src/zenml/zen_stores/secrets_stores/gcp_secrets_store.py

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,36 @@ def populate_config(cls, values: Dict[str, Any]) -> Dict[str, Any]:
9191
"""
9292
# Search for legacy attributes and populate the connector configuration
9393
# from them, if they exist.
94-
if values.get("project_id") and os.environ.get(
95-
"GOOGLE_APPLICATION_CREDENTIALS"
96-
):
97-
logger.warning(
98-
"The `project_id` GCP secrets store attribute and the "
99-
"`GOOGLE_APPLICATION_CREDENTIALS` environment variable are "
100-
"deprecated and will be removed in a future version of ZenML. "
101-
"Please use the `auth_method` and `auth_config` attributes "
102-
"instead."
103-
)
104-
values["auth_method"] = GCPAuthenticationMethods.SERVICE_ACCOUNT
105-
values["auth_config"] = dict(
106-
project_id=values.get("project_id"),
107-
)
108-
# Load the service account credentials from the file
109-
with open(os.environ["GOOGLE_APPLICATION_CREDENTIALS"]) as f:
110-
values["auth_config"]["service_account_json"] = f.read()
94+
if values.get("project_id"):
95+
if not os.environ.get("GOOGLE_APPLICATION_CREDENTIALS"):
96+
logger.warning(
97+
"The `project_id` GCP secrets store attribute is "
98+
"deprecated and will be removed in a future version of ZenML. "
99+
"Please use the `auth_method` and `auth_config` attributes "
100+
"instead. Using an implicit GCP authentication to access "
101+
"the GCP Secrets Manager API."
102+
)
103+
values["auth_method"] = GCPAuthenticationMethods.IMPLICIT
104+
values["auth_config"] = dict(
105+
project_id=values.get("project_id"),
106+
)
107+
else:
108+
logger.warning(
109+
"The `project_id` GCP secrets store attribute and the "
110+
"`GOOGLE_APPLICATION_CREDENTIALS` environment variable are "
111+
"deprecated and will be removed in a future version of ZenML. "
112+
"Please use the `auth_method` and `auth_config` attributes "
113+
"instead."
114+
)
115+
values[
116+
"auth_method"
117+
] = GCPAuthenticationMethods.SERVICE_ACCOUNT
118+
values["auth_config"] = dict(
119+
project_id=values.get("project_id"),
120+
)
121+
# Load the service account credentials from the file
122+
with open(os.environ["GOOGLE_APPLICATION_CREDENTIALS"]) as f:
123+
values["auth_config"]["service_account_json"] = f.read()
111124

112125
return values
113126

0 commit comments

Comments
 (0)