예제 #1
0
    def create_profiles_file(self, profiles_file, sample_adapter):
        # Line below raises an exception if the specified adapter is not found
        load_plugin(sample_adapter)
        adapter_path = get_include_paths(sample_adapter)[0]
        sample_profiles_path = adapter_path / 'sample_profiles.yml'

        if not sample_profiles_path.exists():
            raise RuntimeException(f'No sample profile for {sample_adapter}')

        if not os.path.exists(profiles_file):
            shutil.copyfile(sample_profiles_path, profiles_file)
            return True

        return False
예제 #2
0
def _nt_setup(config, args):
    """
    On windows, we have to do a some things that dbt does dynamically at
    process load.

    These things are inherited automatically on posix, where fork() keeps
    everything in memory.
    """
    # reset flags
    flags.set_from_args(args)
    # reload the active plugin
    load_plugin(config.credentials.type)

    # reset tracking, etc
    config.config.set_values(args.profiles_dir)
예제 #3
0
    def _spawn_setup(self):
        """
        Because we're using spawn, we have to do a some things that dbt does
        dynamically at process load.

        These things are inherited automatically in fork mode, where fork()
        keeps everything in memory.
        """
        # reset flags
        dbt.flags.set_from_args(self.task.args)
        # reload the active plugin
        load_plugin(self.task.config.credentials.type)
        # register it
        register_adapter(self.task.config)

        # reset tracking, etc
        self.task.config.config.set_values(self.task.args.profiles_dir)
예제 #4
0
    def _credentials_from_profile(profile, profile_name, target_name):
        # credentials carry their 'type' in their actual type, not their
        # attributes. We do want this in order to pick our Credentials class.
        if 'type' not in profile:
            raise DbtProfileError(
                'required field "type" not found in profile {} and target {}'.
                format(profile_name, target_name))

        typename = profile.pop('type')

        try:
            cls = load_plugin(typename)
            credentials = cls(**profile)
        except RuntimeException as e:
            raise DbtProfileError(
                'Credentials in profile "{}", target "{}" invalid: {}'.format(
                    profile_name, target_name, str(e)))
        return credentials
예제 #5
0
    def _credentials_from_profile(profile, profile_name, target_name):
        # credentials carry their 'type' in their actual type, not their
        # attributes. We do want this in order to pick our Credentials class.
        if 'type' not in profile:
            raise DbtProfileError(
                'required field "type" not found in profile {} and target {}'
                .format(profile_name, target_name))

        typename = profile.pop('type')

        try:
            cls = load_plugin(typename)
            credentials = cls(**profile)
        except RuntimeException as e:
            raise DbtProfileError(
                'Credentials in profile "{}", target "{}" invalid: {}'
                .format(profile_name, target_name, str(e))
            )
        return credentials
예제 #6
0
    def _credentials_from_profile(profile, profile_name, target_name):
        # avoid an import cycle
        from dbt.adapters.factory import load_plugin
        # credentials carry their 'type' in their actual type, not their
        # attributes. We do want this in order to pick our Credentials class.
        if 'type' not in profile:
            raise DbtProfileError(
                'required field "type" not found in profile {} and target {}'.
                format(profile_name, target_name))

        typename = profile.pop('type')
        try:
            cls = load_plugin(typename)
            credentials = cls.from_dict(profile)
        except (RuntimeException, ValidationError) as e:
            msg = str(e) if isinstance(e, RuntimeException) else e.message
            raise DbtProfileError(
                'Credentials in profile "{}", target "{}" invalid: {}'.format(
                    profile_name, target_name, msg)) from e

        return credentials