Пример #1
0
    def _build_adapter_profile(
            self, section: str, full_configs: Union[str, 'StringIO',
                                                    dict]) -> AdapterProfile:
        profile = full_configs[section]['profile']
        credentials = full_configs['credpath']

        def lookup_profile_from_creds(creds_dict: dict, profile: str,
                                      section: str) -> dict:
            """Finds the specified profile for the section in a given dict"""
            section = section if section.endswith('s') else section + 's'
            try:
                for creds_profile in creds_dict[section]:
                    if creds_profile['name'] == profile:
                        return creds_profile
                raise KeyError(profile)
            except KeyError as err:
                raise ValueError(
                    f'Credentials missing required section: {err}')

        try:
            profile_dict = lookup_profile_from_creds(
                self._get_dict_from_anything(credentials,
                                             CREDENTIALS_JSON_SCHEMA), profile,
                section)
        except FileNotFoundError as err:
            err.strerror = "Credentials specified in replica.yml not found. " + err.strerror
            raise

        adapter = fetch_adapter(profile_dict['adapter'], section)

        del profile_dict['name']
        del profile_dict['adapter']
        adapter = adapter()
        adapter.credentials = Credentials(**profile_dict)
        return AdapterProfile(profile, adapter)
Пример #2
0
 def _build_target(full_creds: dict) -> AdapterProfile:
     adapter_type = fetch_adapter(full_creds['target']['adapter'], 'target')
     adapter_args = full_creds['target'].get('adapter_args')
     if not adapter_args:
         adapter_args = dict()
     adapter = adapter_type(**adapter_args)
     adapter.replica_meta = {
         attr: full_creds[attr]
         for attr in (
             'name',
             'short_description',
             'long_description',
         )
     }
     return AdapterProfile(full_creds['target']['adapter'], adapter)
Пример #3
0
 def _build_target(full_config: dict) -> AdapterProfile:
     adapter_type = fetch_adapter(full_config['target']['adapter'],
                                  'target')
     adapter_args = full_config['target'].get('adapter_args')
     if not adapter_args:
         adapter_args = dict()
     metadata = {
         attr: full_config[attr]
         for attr in (
             'name',
             'short_description',
             'long_description',
         )
     }
     metadata['config_json'] = json.dumps(full_config)
     adapter_args['replica_metadata'] = metadata
     adapter = adapter_type(**adapter_args)
     return AdapterProfile(full_config['target']['adapter'], adapter)
 def _build_target(self,full_creds:dict)->AdapterProfile:
     adapter=fetch_adapter(full_creds['target']['adapter'],'target')()
     adapter.replica_meta={attr:full_creds[attr] for attr in ('name','short_description','long_description',)}
     return AdapterProfile(full_creds['target']['adapter'],
                           adapter)