def set_auth_from_encoded(self, value): try: auth = UserPasswordAuth.from_encoded_auth(value) except Exception: raise InvalidConfiguration("Invalid EPD_auth value") else: self.update(auth=auth)
def epd_auth_to_auth(epd_auth): ret.update(auth=UserPasswordAuth.from_encoded_auth(epd_auth))
def load_configuration_from_yaml(cls, filename_or_fp): # FIXME: local import to workaround circular import from enstaller.config import STORE_KIND_BROOD # Local import to workaround some freezing issues for jaguar and speed up # imports a bit when yaml is not used. import jsonschema from ruamel import yaml if isinstance(filename_or_fp, string_types): with open(filename_or_fp, "rt") as fp: data = yaml.load(fp) else: data = yaml.load(filename_or_fp) if data is None: data = {} else: try: jsonschema.validate(data, _SCHEMA) except jsonschema.ValidationError as e: msg = "Invalid configuration: {0!r}".format(e.message) raise InvalidConfiguration(msg) config = cls() if _AUTHENTICATION in data: authentication = data[_AUTHENTICATION] authentication_type = authentication.get(_AUTHENTICATION_TYPE, _AUTHENTICATION_TYPE_TOKEN) if authentication_type == _AUTHENTICATION_TYPE_SIMPLE: username = authentication[_USERNAME] password = authentication[_PASSWORD] auth = UserPasswordAuth(username, password) elif authentication_type == _AUTHENTICATION_TYPE_BASIC: auth_string = authentication[_AUTH_STRING] auth = UserPasswordAuth.from_encoded_auth(auth_string) elif authentication_type == _AUTHENTICATION_TYPE_TOKEN: token = authentication[_API_TOKEN] auth = APITokenAuth(token) else: msg = "Unknown authentication type {0!r}". \ format(authentication_type) raise InvalidConfiguration(msg) config.update(auth=auth) if _STORE_URL in data: config.update(store_url=data[_STORE_URL]) if _REPOSITORIES in data: config.set_repositories_from_names(data[_REPOSITORIES]) if _FILES_CACHE in data: files_cache = os.path.expanduser(data[_FILES_CACHE]). \ replace("{PLATFORM}", custom_plat) config._repository_cache = files_cache if _MAX_RETRIES in data: config.update(max_retries=data[_MAX_RETRIES]) if _SSL_VERIFY in data and not data[_SSL_VERIFY]: config.update(verify_ssl=data[_SSL_VERIFY]) config.update(use_webservice=False) if isinstance(filename_or_fp, string_types): config._filename = filename_or_fp config._store_kind = STORE_KIND_BROOD return config
def load_configuration_from_yaml(cls, filename_or_fp): # FIXME: local import to workaround circular import from enstaller.config import STORE_KIND_BROOD if isinstance(filename_or_fp, string_types): with open(filename_or_fp, "rt") as fp: data = yaml.load(fp) else: data = yaml.load(filename_or_fp) if data is None: data = {} else: try: jsonschema.validate(data, _SCHEMA) except jsonschema.ValidationError as e: msg = "Invalid configuration: {0!r}".format(e.message) raise InvalidConfiguration(msg) config = cls() if _AUTHENTICATION in data: authentication = data[_AUTHENTICATION] authentication_type = authentication.get(_AUTHENTICATION_TYPE, _AUTHENTICATION_TYPE_TOKEN) if authentication_type == _AUTHENTICATION_TYPE_SIMPLE: username = authentication[_USERNAME] password = authentication[_PASSWORD] auth = UserPasswordAuth(username, password) elif authentication_type == _AUTHENTICATION_TYPE_BASIC: auth_string = authentication[_AUTH_STRING] auth = UserPasswordAuth.from_encoded_auth(auth_string) elif authentication_type == _AUTHENTICATION_TYPE_TOKEN: token = authentication[_API_TOKEN] auth = APITokenAuth(token) else: msg = "Unknown authentication type {0!r}". \ format(authentication_type) raise InvalidConfiguration(msg) config.update(auth=auth) if _STORE_URL in data: config.update(store_url=data[_STORE_URL]) if _REPOSITORIES in data: config.set_repositories_from_names(data[_REPOSITORIES]) if _FILES_CACHE in data: files_cache = os.path.expanduser(data[_FILES_CACHE]). \ replace("{PLATFORM}", custom_plat) config._repository_cache = files_cache if _MAX_RETRIES in data: config.update(max_retries=data[_MAX_RETRIES]) if _SSL_VERIFY in data and not data[_SSL_VERIFY]: config.update(verify_ssl=data[_SSL_VERIFY]) config.update(use_webservice=False) if isinstance(filename_or_fp, string_types): config._filename = filename_or_fp config._store_kind = STORE_KIND_BROOD return config