1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-01-13 17:16:23 +01:00

Report a config error when trying to load credentials_mgr_class that does't exist

This commit is contained in:
Daniel Mach 2022-03-24 14:35:43 +01:00
parent 8a85789573
commit 90a1cb838b
3 changed files with 15 additions and 2 deletions

View File

@ -151,7 +151,7 @@ def run(prg, argv=None):
raise
print(e, file=sys.stderr)
except (oscerr.ConfigError, oscerr.NoConfigfile) as e:
print(e.msg, file=sys.stderr)
print(e, file=sys.stderr)
except configparser.Error as e:
print(e.message, file=sys.stderr)
except oscerr.OscIOError as e:

View File

@ -15,6 +15,9 @@ try:
except ImportError:
gnomekeyring = None
from . import conf
from . import oscerr
class AbstractCredentialsManagerDescriptor(object):
def name(self):
@ -184,7 +187,11 @@ class KeyringCredentialsManager(AbstractCredentialsManager):
self._backend_cls_name = options
def _load_backend(self):
try:
keyring_backend = keyring.core.load_keyring(self._backend_cls_name)
except ModuleNotFoundError:
msg = "Invalid credentials_mgr_class: {}".format(self._backend_cls_name)
raise oscerr.ConfigError(msg, conf.config['conffile'])
keyring.set_keyring(keyring_backend)
@classmethod

View File

@ -22,6 +22,9 @@ class ConfigError(OscBaseError):
self.msg = msg
self.file = fname
def __str__(self):
return "Error in config file {}\n {}".format(self.file, self.msg)
class ConfigMissingApiurl(ConfigError):
"""Exception raised when a apiurl does not exist in the config file"""
def __init__(self, msg, fname, url):
@ -46,6 +49,9 @@ class NoConfigfile(OscBaseError):
self.file = fname
self.msg = msg
def __str__(self):
return "Config file cannot be found: {}\n {}".format(self.file, self.msg)
class ExtRuntimeError(OscBaseError):
"""Exception raised when there is a runtime error of an external tool"""
def __init__(self, msg, fname):