Skip to content

Commit 686d7d5

Browse files
authored
Standardize SecretBackend class names (#7846)
- AwsSsmSecretsBackend -> SystemsManagerParameterStoreBackend - CloudSecretsManagerSecretsBackend -> CloudSecretsManagerBackend - VaultSecrets -> VaultBackend - EnvironmentVariablesSecretsBackend -> EnvironmentVariablesBackend - MetastoreSecretsBackend -> MetastoreBackend
1 parent 02b71f9 commit 686d7d5

File tree

12 files changed

+51
-47
lines changed

12 files changed

+51
-47
lines changed

airflow/providers/amazon/aws/secrets/ssm.py renamed to airflow/providers/amazon/aws/secrets/systems_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from airflow.utils.log.logging_mixin import LoggingMixin
2828

2929

30-
class AwsSsmSecretsBackend(BaseSecretsBackend, LoggingMixin):
30+
class SystemsManagerParameterStoreBackend(BaseSecretsBackend, LoggingMixin):
3131
"""
3232
Retrieves Connection object from AWS SSM Parameter Store
3333
@@ -36,7 +36,7 @@ class AwsSsmSecretsBackend(BaseSecretsBackend, LoggingMixin):
3636
.. code-block:: ini
3737
3838
[secrets]
39-
backend = airflow.providers.amazon.aws.secrets.ssm.AwsSsmSecretsBackend
39+
backend = airflow.providers.amazon.aws.secrets.systems_manager.SystemsManagerParameterStoreBackend
4040
backend_kwargs = {"connections_prefix": "/airflow/connections", "profile_name": null}
4141
4242
For example, if ssm path is ``/airflow/connections/smtp_default``, this would be accessible

airflow/providers/google/cloud/secrets/secrets_manager.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
from airflow.utils.log.logging_mixin import LoggingMixin
3434

3535

36-
class CloudSecretsManagerSecretsBackend(BaseSecretsBackend, LoggingMixin):
36+
class CloudSecretsManagerBackend(BaseSecretsBackend, LoggingMixin):
3737
"""
3838
Retrieves Connection object from GCP Secrets Manager
3939
@@ -42,7 +42,7 @@ class CloudSecretsManagerSecretsBackend(BaseSecretsBackend, LoggingMixin):
4242
.. code-block:: ini
4343
4444
[secrets]
45-
backend = airflow.providers.google.cloud.secrets.secrets_manager.CloudSecretsManagerSecretsBackend
45+
backend = airflow.providers.google.cloud.secrets.secrets_manager.CloudSecretsManagerBackend
4646
backend_kwargs = {"connections_prefix": "airflow/connections"}
4747
4848
For example, if secret id is ``airflow/connections/smtp_default``, this would be accessible

airflow/providers/hashicorp/secrets/vault.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from airflow.utils.log.logging_mixin import LoggingMixin
3030

3131

32-
class VaultSecrets(BaseSecretsBackend, LoggingMixin):
32+
class VaultBackend(BaseSecretsBackend, LoggingMixin):
3333
"""
3434
Retrieves Connection object from Hashicorp Vault
3535
@@ -38,7 +38,7 @@ class VaultSecrets(BaseSecretsBackend, LoggingMixin):
3838
.. code-block:: ini
3939
4040
[secrets]
41-
backend = airflow.providers.hashicorp.secrets.vault.VaultSecrets
41+
backend = airflow.providers.hashicorp.secrets.vault.VaultBackend
4242
backend_kwargs = {
4343
"connections_path": "connections",
4444
"url": "http://127.0.0.1:8200",

airflow/secrets/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@
3636

3737
CONFIG_SECTION = "secrets"
3838
DEFAULT_SECRETS_SEARCH_PATH = [
39-
"airflow.secrets.environment_variables.EnvironmentVariablesSecretsBackend",
40-
"airflow.secrets.metastore.MetastoreSecretsBackend",
39+
"airflow.secrets.environment_variables.EnvironmentVariablesBackend",
40+
"airflow.secrets.metastore.MetastoreBackend",
4141
]
4242

4343

airflow/secrets/environment_variables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
CONN_ENV_PREFIX = "AIRFLOW_CONN_"
2828

2929

30-
class EnvironmentVariablesSecretsBackend(BaseSecretsBackend):
30+
class EnvironmentVariablesBackend(BaseSecretsBackend):
3131
"""
3232
Retrieves Connection object from environment variable.
3333
"""

airflow/secrets/metastore.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
from airflow.utils.session import provide_session
2727

2828

29-
class MetastoreSecretsBackend(BaseSecretsBackend):
29+
class MetastoreBackend(BaseSecretsBackend):
3030
"""
3131
Retrieves Connection object from airflow metastore database.
3232
"""

docs/howto/use-alternative-secrets-backend.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,15 @@ See :ref:`AWS SSM Parameter Store <ssm_parameter_store_secrets>` for an example
5757
AWS SSM Parameter Store Secrets Backend
5858
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
5959

60-
To enable SSM parameter store, specify :py:class:`~airflow.providers.amazon.aws.secrets.ssm.AwsSsmSecretsBackend`
60+
To enable SSM parameter store, specify :py:class:`~airflow.providers.amazon.aws.secrets.systems_manager.SystemsManagerParameterStoreBackend`
6161
as the ``backend`` in ``[secrets]`` section of ``airflow.cfg``.
6262

6363
Here is a sample configuration:
6464

6565
.. code-block:: ini
6666
6767
[secrets]
68-
backend = airflow.providers.amazon.aws.secrets.ssm.AwsSsmSecretsBackend
68+
backend = airflow.providers.amazon.aws.secrets.systems_manager.SystemsManagerParameterStoreBackend
6969
backend_kwargs = {"connections_prefix": "/airflow/connections", "profile_name": "default"}
7070
7171
If you have set ``connections_prefix`` as ``/airflow/connections``, then for a connection id of ``smtp_default``,
@@ -81,15 +81,15 @@ of the connection object.
8181
Hashicorp Vault Secrets Backend
8282
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8383

84-
To enable Hashicorp vault to retrieve connection, specify :py:class:`~airflow.providers.hashicorp.secrets.vault.VaultSecrets`
84+
To enable Hashicorp vault to retrieve connection, specify :py:class:`~airflow.providers.hashicorp.secrets.vault.VaultBackend`
8585
as the ``backend`` in ``[secrets]`` section of ``airflow.cfg``.
8686

8787
Here is a sample configuration:
8888

8989
.. code-block:: ini
9090
9191
[secrets]
92-
backend = airflow.providers.hashicorp.secrets.vault.VaultSecrets
92+
backend = airflow.providers.hashicorp.secrets.vault.VaultBackend
9393
backend_kwargs = {"connections_path": "connections", "mount_point": "airflow", "url": "http://127.0.0.1:8200"}
9494
9595
The default KV version engine is ``2``, pass ``kv_engine_version: 1`` in ``backend_kwargs`` if you use
@@ -147,7 +147,7 @@ of the connection object.
147147
GCP Secrets Manager Backend
148148
^^^^^^^^^^^^^^^^^^^^^^^^^^^
149149

150-
To enable GCP Secrets Manager to retrieve connection, specify :py:class:`~airflow.providers.google.cloud.secrets.secrets_manager.CloudSecretsManagerSecretsBackend`
150+
To enable GCP Secrets Manager to retrieve connection, specify :py:class:`~airflow.providers.google.cloud.secrets.secrets_manager.CloudSecretsManagerBackend`
151151
as the ``backend`` in ``[secrets]`` section of ``airflow.cfg``.
152152

153153
Available parameters to ``backend_kwargs``:
@@ -161,7 +161,7 @@ Here is a sample configuration:
161161
.. code-block:: ini
162162
163163
[secrets]
164-
backend = airflow.providers.google.cloud.secrets.secrets_manager.CloudSecretsManagerSecretsBackend
164+
backend = airflow.providers.google.cloud.secrets.secrets_manager.CloudSecretsManagerBackend
165165
backend_kwargs = {"connections_prefix": "airflow/connections"}
166166
167167
When ``gcp_key_path`` is not provided, it will use the Application Default Credentials in the current environment. You can set up the credentials with:

tests/providers/amazon/aws/secrets/test_ssm.py renamed to tests/providers/amazon/aws/secrets/test_systems_manager.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,15 @@
1919

2020
from moto import mock_ssm
2121

22-
from airflow.providers.amazon.aws.secrets.ssm import AwsSsmSecretsBackend
22+
from airflow.providers.amazon.aws.secrets.systems_manager import SystemsManagerParameterStoreBackend
2323

2424

2525
class TestSsmSecrets(TestCase):
26-
@mock.patch("airflow.providers.amazon.aws.secrets.ssm.AwsSsmSecretsBackend.get_conn_uri")
26+
@mock.patch("airflow.providers.amazon.aws.secrets.systems_manager."
27+
"SystemsManagerParameterStoreBackend.get_conn_uri")
2728
def test_aws_ssm_get_connections(self, mock_get_uri):
2829
mock_get_uri.return_value = "scheme://user:pass@host:100"
29-
conn_list = AwsSsmSecretsBackend().get_connections("fake_conn")
30+
conn_list = SystemsManagerParameterStoreBackend().get_connections("fake_conn")
3031
conn = conn_list[0]
3132
assert conn.host == 'host'
3233

@@ -38,7 +39,7 @@ def test_get_conn_uri(self):
3839
'Value': 'postgresql://airflow:airflow@host:5432/airflow'
3940
}
4041

41-
ssm_backend = AwsSsmSecretsBackend()
42+
ssm_backend = SystemsManagerParameterStoreBackend()
4243
ssm_backend.client.put_parameter(**param)
4344

4445
returned_uri = ssm_backend.get_conn_uri(conn_id="test_postgres")
@@ -48,7 +49,7 @@ def test_get_conn_uri(self):
4849
def test_get_conn_uri_non_existent_key(self):
4950
"""
5051
Test that if the key with connection ID is not present in SSM,
51-
AwsSsmSecretsBackend.get_connections should return None
52+
SystemsManagerParameterStoreBackend.get_connections should return None
5253
"""
5354
conn_id = "test_mysql"
5455
param = {
@@ -57,7 +58,7 @@ def test_get_conn_uri_non_existent_key(self):
5758
'Value': 'postgresql://airflow:airflow@host:5432/airflow'
5859
}
5960

60-
ssm_backend = AwsSsmSecretsBackend()
61+
ssm_backend = SystemsManagerParameterStoreBackend()
6162
ssm_backend.client.put_parameter(**param)
6263

6364
self.assertIsNone(ssm_backend.get_conn_uri(conn_id=conn_id))

tests/providers/google/cloud/secrets/test_secrets_manager.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from parameterized import parameterized
2323

2424
from airflow.models import Connection
25-
from airflow.providers.google.cloud.secrets.secrets_manager import CloudSecretsManagerSecretsBackend
25+
from airflow.providers.google.cloud.secrets.secrets_manager import CloudSecretsManagerBackend
2626

2727
CREDENTIALS = 'test-creds'
2828
KEY_FILE = 'test-file.json'
@@ -50,19 +50,19 @@ def test_get_conn_uri(self, connections_prefix, mock_client_callable, mock_get_c
5050
test_response.payload.data = CONN_URI.encode("UTF-8")
5151
mock_client.access_secret_version.return_value = test_response
5252

53-
secrets_manager_backend = CloudSecretsManagerSecretsBackend(connections_prefix=connections_prefix)
53+
secrets_manager_backend = CloudSecretsManagerBackend(connections_prefix=connections_prefix)
5454
returned_uri = secrets_manager_backend.get_conn_uri(conn_id=CONN_ID)
5555
self.assertEqual(CONN_URI, returned_uri)
5656
mock_client.secret_version_path.assert_called_once_with(
5757
PROJECT_ID, f"{connections_prefix}/{CONN_ID}", "latest"
5858
)
5959

6060
@mock.patch(MODULE_NAME + ".get_credentials_and_project_id")
61-
@mock.patch(MODULE_NAME + ".CloudSecretsManagerSecretsBackend.get_conn_uri")
61+
@mock.patch(MODULE_NAME + ".CloudSecretsManagerBackend.get_conn_uri")
6262
def test_get_connections(self, mock_get_uri, mock_get_creds):
6363
mock_get_creds.return_value = CREDENTIALS, PROJECT_ID
6464
mock_get_uri.return_value = CONN_URI
65-
conns = CloudSecretsManagerSecretsBackend().get_connections(conn_id=CONN_ID)
65+
conns = CloudSecretsManagerBackend().get_connections(conn_id=CONN_ID)
6666
self.assertIsInstance(conns, list)
6767
self.assertIsInstance(conns[0], Connection)
6868

@@ -77,7 +77,7 @@ def test_get_conn_uri_non_existent_key(self, mock_client_callable, mock_get_cred
7777

7878
connections_prefix = "airflow/connections"
7979

80-
secrets_manager_backend = CloudSecretsManagerSecretsBackend(connections_prefix=connections_prefix)
80+
secrets_manager_backend = CloudSecretsManagerBackend(connections_prefix=connections_prefix)
8181
with self.assertLogs(secrets_manager_backend.log, level="ERROR") as log_output:
8282
self.assertIsNone(secrets_manager_backend.get_conn_uri(conn_id=CONN_ID))
8383
self.assertEqual([], secrets_manager_backend.get_connections(conn_id=CONN_ID))

tests/providers/hashicorp/secrets/test_vault.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
from hvac.exceptions import InvalidPath, VaultError
2121

22-
from airflow.providers.hashicorp.secrets.vault import VaultSecrets
22+
from airflow.providers.hashicorp.secrets.vault import VaultBackend
2323

2424

2525
class TestVaultSecrets(TestCase):
@@ -52,7 +52,7 @@ def test_get_conn_uri(self, mock_hvac):
5252
"token": "s.7AU0I51yv1Q1lxOIg1F3ZRAS"
5353
}
5454

55-
test_client = VaultSecrets(**kwargs)
55+
test_client = VaultBackend(**kwargs)
5656
returned_uri = test_client.get_conn_uri(conn_id="test_postgres")
5757
self.assertEqual('postgresql://airflow:airflow@host:5432/airflow', returned_uri)
5858

@@ -79,7 +79,7 @@ def test_get_conn_uri_engine_version_1(self, mock_hvac):
7979
"kv_engine_version": 1
8080
}
8181

82-
test_client = VaultSecrets(**kwargs)
82+
test_client = VaultBackend(**kwargs)
8383
returned_uri = test_client.get_conn_uri(conn_id="test_postgres")
8484
mock_client.secrets.kv.v1.read_secret.assert_called_once_with(
8585
mount_point='airflow', path='connections/test_postgres')
@@ -107,7 +107,7 @@ def test_get_conn_uri_non_existent_key(self, mock_hvac):
107107
"token": "s.7AU0I51yv1Q1lxOIg1F3ZRAS"
108108
}
109109

110-
test_client = VaultSecrets(**kwargs)
110+
test_client = VaultBackend(**kwargs)
111111
self.assertIsNone(test_client.get_conn_uri(conn_id="test_mysql"))
112112
mock_client.secrets.kv.v2.read_secret_version.assert_called_once_with(
113113
mount_point='airflow', path='connections/test_mysql')
@@ -128,7 +128,7 @@ def test_auth_failure_raises_error(self, mock_hvac):
128128
}
129129

130130
with self.assertRaisesRegex(VaultError, "Vault Authentication Error!"):
131-
VaultSecrets(**kwargs).get_connections(conn_id='test')
131+
VaultBackend(**kwargs).get_connections(conn_id='test')
132132

133133
@mock.patch("airflow.providers.hashicorp.secrets.vault.hvac")
134134
def test_empty_token_raises_error(self, mock_hvac):
@@ -143,4 +143,4 @@ def test_empty_token_raises_error(self, mock_hvac):
143143
}
144144

145145
with self.assertRaisesRegex(VaultError, "token cannot be None for auth_type='token'"):
146-
VaultSecrets(**kwargs).get_connections(conn_id='test')
146+
VaultBackend(**kwargs).get_connections(conn_id='test')

0 commit comments

Comments
 (0)