diff --git a/core/dbt/artifacts/schemas/run/v5/run.py b/core/dbt/artifacts/schemas/run/v5/run.py index 47cc0cb3b87..089113f1336 100644 --- a/core/dbt/artifacts/schemas/run/v5/run.py +++ b/core/dbt/artifacts/schemas/run/v5/run.py @@ -5,7 +5,6 @@ from datetime import datetime -from dbt.constants import SECRET_ENV_PREFIX from dbt.artifacts.resources import CompiledResource from dbt.artifacts.schemas.base import ( BaseArtifactMetadata, @@ -21,6 +20,7 @@ ExecutionResult, ) from dbt_common.clients.system import write_json +from dbt_common.constants import SECRET_ENV_PREFIX from dbt.exceptions import scrub_secrets diff --git a/core/dbt/config/renderer.py b/core/dbt/config/renderer.py index eee740893b8..2d97c55b7dd 100644 --- a/core/dbt/config/renderer.py +++ b/core/dbt/config/renderer.py @@ -4,12 +4,13 @@ from dbt.clients.jinja import get_rendered from dbt_common.clients.jinja import catch_jinja -from dbt.constants import SECRET_ENV_PREFIX, DEPENDENCIES_FILE_NAME +from dbt.constants import DEPENDENCIES_FILE_NAME, SECRET_PLACEHOLDER from dbt.context.target import TargetContext -from dbt.context.secret import SecretContext, SECRET_PLACEHOLDER +from dbt.context.secret import SecretContext from dbt.context.base import BaseContext from dbt.adapters.contracts.connection import HasCredentials from dbt.exceptions import DbtProjectError +from dbt_common.constants import SECRET_ENV_PREFIX from dbt_common.context import get_invocation_context from dbt_common.exceptions import CompilationError, RecursionError from dbt_common.utils import deep_map_render diff --git a/core/dbt/constants.py b/core/dbt/constants.py index 31e4d833185..feaf0957746 100644 --- a/core/dbt/constants.py +++ b/core/dbt/constants.py @@ -1,7 +1,7 @@ -# TODO: remove SECRET_ENV_PREFIX and import from dbt_common -SECRET_ENV_PREFIX = "DBT_ENV_SECRET_" DEFAULT_ENV_PLACEHOLDER = "DBT_DEFAULT_PLACEHOLDER" +SECRET_PLACEHOLDER = "$$$DBT_SECRET_START$$${}$$$DBT_SECRET_END$$$" + MAXIMUM_SEED_SIZE = 1 * 1024 * 1024 MAXIMUM_SEED_SIZE_NAME = "1MB" diff --git a/core/dbt/context/base.py b/core/dbt/context/base.py index 5ee266f8b6a..cfa5523ab06 100644 --- a/core/dbt/context/base.py +++ b/core/dbt/context/base.py @@ -11,7 +11,7 @@ from dbt import utils from dbt.clients.jinja import get_rendered from dbt.clients.yaml_helper import yaml, safe_load, SafeLoader, Loader, Dumper # noqa: F401 -from dbt.constants import SECRET_ENV_PREFIX, DEFAULT_ENV_PLACEHOLDER +from dbt.constants import DEFAULT_ENV_PLACEHOLDER, SECRET_PLACEHOLDER from dbt.contracts.graph.nodes import Resource from dbt.exceptions import ( SecretEnvVarLocationError, @@ -21,6 +21,7 @@ ZipStrictWrongTypeError, ) from dbt_common.context import get_invocation_context +from dbt_common.constants import SECRET_ENV_PREFIX from dbt_common.exceptions.macros import MacroReturn from dbt_common.events.functions import fire_event, get_invocation_id from dbt.events.types import JinjaLogInfo, JinjaLogDebug @@ -561,12 +562,10 @@ def log(msg: str, info: bool = False) -> str: {{ log("Running some_macro: " ~ arg1 ~ ", " ~ arg2) }} {% endmacro %}" """ - # Now, detect instances of the placeholder value ($$$DBT_SECRET_START...DBT_SECRET_END$$$) - # and replace them with the standard mask '*****' + # Detect instances of the placeholder value ($$$DBT_SECRET_START...DBT_SECRET_END$$$) + # and replace it with the standard mask '*****' if "DBT_SECRET_START" in str(msg): search_group = f"({SECRET_ENV_PREFIX}(.*))" - from dbt.context.secret import SECRET_PLACEHOLDER - pattern = SECRET_PLACEHOLDER.format(search_group).replace("$", r"\$") m = re.search( pattern, diff --git a/core/dbt/context/configured.py b/core/dbt/context/configured.py index c5c95bbfbcb..57e52c80e98 100644 --- a/core/dbt/context/configured.py +++ b/core/dbt/context/configured.py @@ -2,7 +2,8 @@ from dbt_common.context import get_invocation_context -from dbt.constants import SECRET_ENV_PREFIX, DEFAULT_ENV_PLACEHOLDER +from dbt.constants import DEFAULT_ENV_PLACEHOLDER +from dbt_common.constants import SECRET_ENV_PREFIX from dbt.adapters.contracts.connection import AdapterRequiredConfig from dbt.node_types import NodeType from dbt.utils import MultiDict diff --git a/core/dbt/context/providers.py b/core/dbt/context/providers.py index 90f0a508c8c..61bfffb59d7 100644 --- a/core/dbt/context/providers.py +++ b/core/dbt/context/providers.py @@ -25,7 +25,8 @@ from dbt.adapters.factory import get_adapter, get_adapter_package_names, get_adapter_type_names from dbt.clients.jinja import get_rendered, MacroGenerator, MacroStack, UnitTestMacroGenerator from dbt.config import RuntimeConfig, Project -from dbt.constants import SECRET_ENV_PREFIX, DEFAULT_ENV_PLACEHOLDER +from dbt.constants import DEFAULT_ENV_PLACEHOLDER +from dbt_common.constants import SECRET_ENV_PREFIX from dbt.context.base import contextmember, contextproperty, Var from dbt.context.configured import FQNLookup from dbt.context.context_config import ContextConfig diff --git a/core/dbt/context/secret.py b/core/dbt/context/secret.py index 6de99fd5e5b..4be330dc031 100644 --- a/core/dbt/context/secret.py +++ b/core/dbt/context/secret.py @@ -1,16 +1,14 @@ from typing import Any, Dict, Optional +from dbt_common.constants import SECRET_ENV_PREFIX from dbt_common.context import get_invocation_context from .base import BaseContext, contextmember -from dbt.constants import SECRET_ENV_PREFIX, DEFAULT_ENV_PLACEHOLDER +from dbt.constants import DEFAULT_ENV_PLACEHOLDER, SECRET_PLACEHOLDER from dbt.exceptions import EnvVarMissingError -SECRET_PLACEHOLDER = "$$$DBT_SECRET_START$$${}$$$DBT_SECRET_END$$$" - - class SecretContext(BaseContext): """This context is used in profiles.yml + packages.yml. It can render secret env vars that aren't usable elsewhere""" diff --git a/core/dbt/exceptions.py b/core/dbt/exceptions.py index 721e65b4c27..27e2f38babc 100644 --- a/core/dbt/exceptions.py +++ b/core/dbt/exceptions.py @@ -17,8 +17,7 @@ from dbt_common.dataclass_schema import ValidationError -from dbt.constants import SECRET_ENV_PREFIX - +from dbt_common.constants import SECRET_ENV_PREFIX if TYPE_CHECKING: import agate diff --git a/core/dbt/parser/manifest.py b/core/dbt/parser/manifest.py index 5e406d81d03..be41ee473a5 100644 --- a/core/dbt/parser/manifest.py +++ b/core/dbt/parser/manifest.py @@ -44,8 +44,8 @@ MANIFEST_FILE_NAME, PARTIAL_PARSE_FILE_NAME, SEMANTIC_MANIFEST_FILE_NAME, - SECRET_ENV_PREFIX, ) +from dbt_common.constants import SECRET_ENV_PREFIX from dbt_common.helper_types import PathSet from dbt_common.events.functions import fire_event, get_invocation_id, warn_or_error from dbt_common.events.types import ( diff --git a/tests/functional/dependencies/test_dependency_secrets.py b/tests/functional/dependencies/test_dependency_secrets.py index f1ac92e0b98..7e0b592409b 100644 --- a/tests/functional/dependencies/test_dependency_secrets.py +++ b/tests/functional/dependencies/test_dependency_secrets.py @@ -25,7 +25,7 @@ def packages(self): def test_allow_secrets(self, project): _, log_output = run_dbt_and_capture(["deps"]) - # this will not be written to logs or lock file + # this will not be written to logs assert not ("super secret" in log_output) assert "*****" in log_output assert not ("DBT_ENV_SECRET_FOR_LOGGING" in log_output)