Exemplo n.º 1
0
    def test_context_config_all_keys_accounted_for(self):
        updater = ConfigUpdater('postgres')
        used_keys = (
            frozenset(updater.AppendListFields) |
            frozenset(updater.ExtendDictFields) |
            frozenset(updater.ClobberFields) |
            frozenset({'unlogged'})
        )

        self.assertEqual(used_keys, frozenset(updater.ConfigKeys))
Exemplo n.º 2
0
    def __init__(
        self,
        active_project: RuntimeConfig,
        own_project: Project,
        fqn: List[str],
        node_type: NodeType,
    ):
        self._config = None
        self._active_project: RuntimeConfig = active_project
        self._own_project: Project = own_project

        self._model = ModelParts(
            fqn=fqn,
            resource_type=node_type,
            package_name=self._own_project.project_name,
        )

        self._updater = ConfigUpdater(active_project.credentials.type)

        # the config options defined within the model
        self.in_model_config: Dict[str, Any] = {}
Exemplo n.º 3
0
    def _get_v1_config_paths(
        self,
        config: Dict[str, Any],
        path: FQNPath,
        paths: MutableSet[FQNPath],
    ) -> PathSet:
        keys = ConfigUpdater(self.credentials.type).ConfigKeys

        for key, value in config.items():
            if isinstance(value, dict):
                if key in keys:
                    if path not in paths:
                        paths.add(path)
                else:
                    self._get_v1_config_paths(value, path + (key, ), paths)
            else:
                if path not in paths:
                    paths.add(path)

        return frozenset(paths)
Exemplo n.º 4
0
class LegacyContextConfig:
    def __init__(
        self,
        active_project: RuntimeConfig,
        own_project: Project,
        fqn: List[str],
        node_type: NodeType,
    ):
        self._config = None
        self._active_project: RuntimeConfig = active_project
        self._own_project: Project = own_project

        self._model = ModelParts(
            fqn=fqn,
            resource_type=node_type,
            package_name=self._own_project.project_name,
        )

        self._updater = ConfigUpdater(active_project.credentials.type)

        # the config options defined within the model
        self.in_model_config: Dict[str, Any] = {}

    def get_default(self) -> Dict[str, Any]:
        defaults = {"enabled": True, "materialized": "view"}

        if self._model.resource_type == NodeType.Seed:
            defaults['materialized'] = 'seed'
        elif self._model.resource_type == NodeType.Snapshot:
            defaults['materialized'] = 'snapshot'

        if self._model.resource_type == NodeType.Test:
            defaults['severity'] = 'ERROR'

        return defaults

    def build_config_dict(self, base: bool = False) -> Dict[str, Any]:
        defaults = self.get_default()
        active_config = self.load_config_from_active_project()

        if self._active_project.project_name == self._own_project.project_name:
            cfg = self._updater.merge(defaults, active_config,
                                      self.in_model_config)
        else:
            own_config = self.load_config_from_own_project()

            cfg = self._updater.merge(defaults, own_config,
                                      self.in_model_config, active_config)

        return cfg

    def _translate_adapter_aliases(self, config: Dict[str, Any]):
        return self._active_project.credentials.translate_aliases(config)

    def update_in_model_config(self, config: Dict[str, Any]) -> None:
        config = self._translate_adapter_aliases(config)
        self._updater.update_into(self.in_model_config, config)

    def load_config_from_own_project(self) -> Dict[str, Any]:
        return self._updater.get_project_config(self._model, self._own_project)

    def load_config_from_active_project(self) -> Dict[str, Any]:
        return self._updater.get_project_config(
            self._model,
            self._active_project,
        )
Exemplo n.º 5
0
 def vars_for(
     self, node: IsFQNResource, adapter_type: str
 ) -> Mapping[str, Any]:
     updater = ConfigUpdater(adapter_type)
     return updater.get_project_config(node, self).get('vars', {})