Skip to content

Commit ce483b6

Browse files
authored
[Backport 1.7.latest] convert SECRET_ENV_PREFIX from DBT_ENV_SECRET_ to DBT_ENV_SECRET (#10052) (#10055)
* convert SECRET_ENV_PREFIX from DBT_ENV_SECRET_ to DBT_ENV_SECRET * changelog # Conflicts: # tests/functional/context_methods/test_secret_env_vars.py
1 parent 1da6ab2 commit ce483b6

File tree

6 files changed

+20
-14
lines changed

6 files changed

+20
-14
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
kind: Under the Hood
2+
body: Remove the final underscore from secret environment variable constants.
3+
time: 2024-04-26T09:02:22.481158-05:00
4+
custom:
5+
Author: emmyoop
6+
Issue: "10052"

core/dbt/constants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
SECRET_ENV_PREFIX = "DBT_ENV_SECRET_"
1+
SECRET_ENV_PREFIX = "DBT_ENV_SECRET"
22
DEFAULT_ENV_PLACEHOLDER = "DBT_DEFAULT_PLACEHOLDER"
33
METADATA_ENV_PREFIX = "DBT_ENV_CUSTOM_ENV_"
44

core/dbt/context/secret.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def env_var(self, var: str, default: Optional[str] = None) -> str:
2121
2222
If the default is None, raise an exception for an undefined variable.
2323
24-
In this context *only*, env_var will accept env vars prefixed with DBT_ENV_SECRET_.
24+
In this context *only*, env_var will accept env vars prefixed with DBT_ENV_SECRET.
2525
It will return the name of the secret env var, wrapped in 'start' and 'end' identifiers.
2626
The actual value will be subbed in later in SecretRenderer.render_value()
2727
"""

tests/functional/context_methods/test_env_vars.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ def setup(self):
5555
os.environ["DBT_TEST_ENV_VAR"] = "1"
5656
os.environ["DBT_TEST_USER"] = "root"
5757
os.environ["DBT_TEST_PASS"] = "password"
58-
os.environ[SECRET_ENV_PREFIX + "SECRET"] = "secret_variable"
58+
os.environ[SECRET_ENV_PREFIX + "_SECRET"] = "secret_variable"
5959
os.environ["DBT_TEST_NOT_SECRET"] = "regular_variable"
6060
os.environ["DBT_TEST_IGNORE_DEFAULT"] = "ignored_default"
6161
yield
6262
del os.environ["DBT_TEST_ENV_VAR"]
6363
del os.environ["DBT_TEST_USER"]
64-
del os.environ[SECRET_ENV_PREFIX + "SECRET"]
64+
del os.environ[SECRET_ENV_PREFIX + "_SECRET"]
6565
del os.environ["DBT_TEST_NOT_SECRET"]
6666
del os.environ["DBT_TEST_IGNORE_DEFAULT"]
6767

tests/functional/context_methods/test_secret_env_vars.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ def test_disallow_secret(self, project):
7373
class TestAllowSecretProfilePackage(FirstDependencyProject):
7474
@pytest.fixture(scope="class", autouse=True)
7575
def setup(self):
76-
os.environ[SECRET_ENV_PREFIX + "USER"] = "root"
77-
os.environ[SECRET_ENV_PREFIX + "PASS"] = "password"
78-
os.environ[SECRET_ENV_PREFIX + "PACKAGE"] = "first_dependency"
76+
os.environ[SECRET_ENV_PREFIX + "_USER"] = "root"
77+
os.environ[SECRET_ENV_PREFIX + "_PASS"] = "password"
78+
os.environ[SECRET_ENV_PREFIX + "_PACKAGE"] = "first_dependency"
7979
yield
80-
del os.environ[SECRET_ENV_PREFIX + "USER"]
81-
del os.environ[SECRET_ENV_PREFIX + "PASS"]
82-
del os.environ[SECRET_ENV_PREFIX + "PACKAGE"]
80+
del os.environ[SECRET_ENV_PREFIX + "_USER"]
81+
del os.environ[SECRET_ENV_PREFIX + "_PASS"]
82+
del os.environ[SECRET_ENV_PREFIX + "_PACKAGE"]
8383

8484
@pytest.fixture(scope="class")
8585
def models(self):
@@ -114,7 +114,7 @@ def test_allow_secrets(self, project, first_dependency):
114114
class TestCloneFailSecretScrubbed:
115115
@pytest.fixture(scope="class", autouse=True)
116116
def setup(self):
117-
os.environ[SECRET_ENV_PREFIX + "GIT_TOKEN"] = "abc123"
117+
os.environ[SECRET_ENV_PREFIX + "_GIT_TOKEN"] = "abc123"
118118

119119
@pytest.fixture(scope="class")
120120
def models(self):

tests/functional/partial_parsing/test_pp_vars.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ def dbt_profile_target(self):
358358

359359
# user is secret and password is not. postgres on macos doesn't care if the password
360360
# changes so we have to change the user. related: https://github.com/dbt-labs/dbt-core/pull/4250
361-
os.environ[SECRET_ENV_PREFIX + "USER"] = "root"
361+
os.environ[SECRET_ENV_PREFIX + "_USER"] = "root"
362362
os.environ["ENV_VAR_PASS"] = "password"
363363
return {
364364
"type": "postgres",
@@ -373,15 +373,15 @@ def dbt_profile_target(self):
373373
def test_profile_secret_env_vars(self, project):
374374

375375
# Initial run
376-
os.environ[SECRET_ENV_PREFIX + "USER"] = "root"
376+
os.environ[SECRET_ENV_PREFIX + "_USER"] = "root"
377377
os.environ["ENV_VAR_PASS"] = "password"
378378

379379
results = run_dbt(["run"])
380380
manifest = get_manifest(project.project_root)
381381
env_vars_checksum = manifest.state_check.profile_env_vars_hash.checksum
382382

383383
# Change a secret var, it shouldn't register because we shouldn't save secrets.
384-
os.environ[SECRET_ENV_PREFIX + "USER"] = "fake_user"
384+
os.environ[SECRET_ENV_PREFIX + "_USER"] = "fake_user"
385385
# we just want to see if the manifest has included
386386
# the secret in the hash of environment variables.
387387
(results, log_output) = run_dbt_and_capture(["run"], expect_pass=True)

0 commit comments

Comments
 (0)