(self, var: str, default: Optional[str] = None)
The env_var() function. Return the environment variable named 'var'.
        If there is no such environment variable set, return the default.

        If the default is None, raise an exception for an undefined variable.
The env_var() function. Return the environment variable named 'var'.
        If there is no such environment variable set, return the default.
The env_var () function . Return the environment variable named var . If there is no such environment variable set return the default .
def env_var(self, var: str, default: Optional[str] = None) -> str:
        """The env_var() function. Return the environment variable named 'var'.
        If there is no such environment variable set, return the default.

        If the default is None, raise an exception for an undefined variable.
        """
        return_value = None
        if var.startswith(SECRET_ENV_PREFIX):
            disallow_secret_env_var(var)
        if var in os.environ:
            return_value = os.environ[var]
        elif default is not None:
            return_value = default

        if return_value is not None:
            # Save the env_var value in the manifest and the var name in the source_file.
            # If this is compiling, do not save because it's irrelevant to parsing.
            if self.model and not hasattr(self.model, 'compiled'):
                self.manifest.env_vars[var] = return_value
                # hooks come from dbt_project.yml which doesn't have a real file_id
                if self.model.file_id in self.manifest.files:
                    source_file = self.manifest.files[self.model.file_id]
                    # Schema files should never get here
                    if source_file.parse_file_type != 'schema':
                        source_file.env_vars.append(var)
            return return_value
        else:
            msg = f"Env var required but not provided: '{var}'"
            raise_parsing_error(msg)
def env_var ( self , var : str , default : Optional [ str ] = None ) -> str : return_value = None if var . startswith ( SECRET_ENV_PREFIX ) : disallow_secret_env_var ( var ) if var in os . environ : return_value = os . environ [ var ] elif default is not None : return_value = default if return_value is not None : # Save the env_var value in the manifest and the var name in the source_file. # If this is compiling, do not save because it's irrelevant to parsing. if self . model and not hasattr ( self . model , 'compiled' ) : self . manifest . env_vars [ var ] = return_value # hooks come from dbt_project.yml which doesn't have a real file_id if self . model . file_id in self . manifest . files : source_file = self . manifest . files [ self . model . file_id ] # Schema files should never get here if source_file . parse_file_type != 'schema' : source_file . env_vars . append ( var ) return return_value else : msg = f"Env var required but not provided: '{var}'" raise_parsing_error ( msg )