Ejemplo n.º 1
0
    def from_credentials(
            cls,
            credentials: Credentials,
            threads: int,
            profile_name: str,
            target_name: str,
            user_cfg: Optional[Dict[str, Any]] = None) -> 'Profile':
        """Create a profile from an existing set of Credentials and the
        remaining information.

        :param credentials: The credentials dict for this profile.
        :param threads: The number of threads to use for connections.
        :param profile_name: The profile name used for this profile.
        :param target_name: The target name used for this profile.
        :param user_cfg: The user-level config block from the
            raw profiles, if specified.
        :raises DbtProfileError: If the profile is invalid.
        :returns: The new Profile object.
        """
        if user_cfg is None:
            user_cfg = {}
        config = UserConfig.from_dict(user_cfg)

        profile = cls(profile_name=profile_name,
                      target_name=target_name,
                      config=config,
                      threads=threads,
                      credentials=credentials)
        profile.validate()
        return profile
Ejemplo n.º 2
0
 def __init__(self, profile_name, target_name, config, threads,
              credentials):
     self.profile_name = profile_name
     self.target_name = target_name
     if isinstance(config, dict):
         config = UserConfig.from_dict(config)
     self.config = config
     self.threads = threads
     self.credentials = credentials
Ejemplo n.º 3
0
def read_user_config(directory):
    try:
        user_cfg = None
        profile = read_profile(directory)
        if profile:
            user_cfg = profile.get('config', {})
        return UserConfig.from_dict(user_cfg)
    except (RuntimeException, ValidationError):
        return UserConfig()
Ejemplo n.º 4
0
def read_user_config(directory: str) -> UserConfig:
    try:
        profile = read_profile(directory)
        if profile:
            user_cfg = coerce_dict_str(profile.get('config', {}))
            if user_cfg is not None:
                return UserConfig.from_dict(user_cfg)
    except (RuntimeException, ValidationError):
        pass
    return UserConfig()