Skip to content

Commit eb4af4f

Browse files
authored
Make BaseSecretsBackend.build_path generic (#7948)
Currently the arguments required for it are `connections_prefix` and `conn_id` . Changing this to `path_prefix` and `secret_id` allows using that method for retrieving variables too
1 parent 1bdd5ff commit eb4af4f

File tree

5 files changed

+11
-15
lines changed

5 files changed

+11
-15
lines changed

β€Žairflow/providers/amazon/aws/secrets/systems_manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def get_conn_uri(self, conn_id: str) -> Optional[str]:
6969
:type conn_id: str
7070
"""
7171

72-
ssm_path = self.build_path(connections_prefix=self.connections_prefix, conn_id=conn_id)
72+
ssm_path = self.build_path(self.connections_prefix, conn_id)
7373
try:
7474
response = self.client.get_parameter(
7575
Name=ssm_path, WithDecryption=False

β€Žairflow/providers/google/cloud/secrets/secrets_manager.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,7 @@ def get_conn_uri(self, conn_id: str) -> Optional[str]:
110110
:param conn_id: connection id
111111
:type conn_id: str
112112
"""
113-
secret_id = self.build_path(
114-
connections_prefix=self.connections_prefix,
115-
conn_id=conn_id,
116-
sep=self.sep
117-
)
113+
secret_id = self.build_path(self.connections_prefix, conn_id, self.sep)
118114
# always return the latest version of the secret
119115
secret_version = "latest"
120116
name = self.client.secret_version_path(self.project_id, secret_id, secret_version)

β€Žairflow/providers/hashicorp/secrets/vault.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def get_conn_uri(self, conn_id: str) -> Optional[str]:
150150
:param conn_id: connection id
151151
:type conn_id: str
152152
"""
153-
secret_path = self.build_path(connections_prefix=self.connections_path, conn_id=conn_id)
153+
secret_path = self.build_path(self.connections_path, conn_id)
154154

155155
try:
156156
if self.kv_engine_version == 1:

β€Žairflow/secrets/base_secrets.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,18 @@ def __init__(self, **kwargs):
3030
pass
3131

3232
@staticmethod
33-
def build_path(connections_prefix: str, conn_id: str, sep: str = "/") -> str:
33+
def build_path(path_prefix: str, secret_id: str, sep: str = "/") -> str:
3434
"""
3535
Given conn_id, build path for Secrets Backend
3636
37-
:param connections_prefix: prefix of the secret to read to get Connections
38-
:type connections_prefix: str
39-
:param conn_id: connection id
40-
:type conn_id: str
37+
:param path_prefix: Prefix of the path to get secret
38+
:type path_prefix: str
39+
:param secret_id: Secret id
40+
:type secret_id: str
4141
:param sep: separator used to concatenate connections_prefix and conn_id. Default: "/"
4242
:type sep: str
4343
"""
44-
return f"{connections_prefix}{sep}{conn_id}"
44+
return f"{path_prefix}{sep}{secret_id}"
4545

4646
def get_conn_uri(self, conn_id: str) -> Optional[str]:
4747
"""

β€Žtests/secrets/test_secrets_backends.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ def tearDown(self) -> None:
5252
clear_db_variables()
5353

5454
@parameterized.expand([
55-
('default', {"connections_prefix": "PREFIX", "conn_id": "ID"}, "PREFIX/ID"),
56-
('with_sep', {"connections_prefix": "PREFIX", "conn_id": "ID", "sep": "-"}, "PREFIX-ID")
55+
('default', {"path_prefix": "PREFIX", "secret_id": "ID"}, "PREFIX/ID"),
56+
('with_sep', {"path_prefix": "PREFIX", "secret_id": "ID", "sep": "-"}, "PREFIX-ID")
5757
])
5858
def test_build_path(self, _, kwargs, output):
5959
build_path = BaseSecretsBackend.build_path

0 commit comments

Comments
 (0)