config: Keyring debug logging cleanup
This commit is contained in:
parent
b88cf4a8b2
commit
9bd4d90e41
@ -21,12 +21,18 @@ else:
|
|||||||
|
|
||||||
def fetch():
|
def fetch():
|
||||||
if not dbus:
|
if not dbus:
|
||||||
logger.debug('Keyring lookup failed as D-Bus not installed.')
|
logger.debug('Fetching from keyring failed: dbus not installed.')
|
||||||
return []
|
return []
|
||||||
|
|
||||||
bus = _bus()
|
try:
|
||||||
if not _secrets_running(bus):
|
bus = dbus.SessionBus()
|
||||||
logger.debug('Keyring lookup failed as Secrets service not running.')
|
except dbus.exceptions.DBusException as e:
|
||||||
|
logger.debug('Fetching from keyring failed: %s', e)
|
||||||
|
return []
|
||||||
|
|
||||||
|
if not bus.name_has_owner('org.freedesktop.secrets'):
|
||||||
|
logger.debug(
|
||||||
|
'Fetching from keyring failed: secrets service not running.')
|
||||||
return []
|
return []
|
||||||
|
|
||||||
service = _serivce(bus)
|
service = _serivce(bus)
|
||||||
@ -41,7 +47,7 @@ def fetch():
|
|||||||
items, prompt = service.Unlock(locked)
|
items, prompt = service.Unlock(locked)
|
||||||
if prompt != '/':
|
if prompt != '/':
|
||||||
_prompt(bus, prompt).Dismiss()
|
_prompt(bus, prompt).Dismiss()
|
||||||
logger.debug('Keyring lookup failed as it is locked.')
|
logger.debug('Fetching from keyring failed: keyring is locked.')
|
||||||
return []
|
return []
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
@ -59,14 +65,19 @@ def set(section, key, value):
|
|||||||
Indicates if storage failed or succeded.
|
Indicates if storage failed or succeded.
|
||||||
"""
|
"""
|
||||||
if not dbus:
|
if not dbus:
|
||||||
logger.debug('Saving secret %s/%s failed as D-Bus not installed.',
|
logger.debug('Saving %s/%s to keyring failed: dbus not installed.',
|
||||||
section, key)
|
section, key)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
bus = _bus()
|
try:
|
||||||
if not _secrets_running(bus):
|
bus = dbus.SessionBus()
|
||||||
|
except dbus.exceptions.DBusException as e:
|
||||||
|
logger.debug('Saving %s/%s to keyring failed: %s', section, key, e)
|
||||||
|
return False
|
||||||
|
|
||||||
|
if not bus.name_has_owner('org.freedesktop.secrets'):
|
||||||
logger.debug(
|
logger.debug(
|
||||||
'Saving secret %s/%s failed as Secrets service not running.',
|
'Saving %s/%s to keyring failed: secrets service not running.',
|
||||||
section, key)
|
section, key)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -90,32 +101,18 @@ def set(section, key, value):
|
|||||||
item, prompt = collection.CreateItem(properties, secret, True)
|
item, prompt = collection.CreateItem(properties, secret, True)
|
||||||
except dbus.exceptions.DBusException as e:
|
except dbus.exceptions.DBusException as e:
|
||||||
# TODO: catch IsLocked errors etc.
|
# TODO: catch IsLocked errors etc.
|
||||||
logger.debug('Saving secret %s/%s failed: %s', section, key, e)
|
logger.debug('Saving %s/%s to keyring failed: %s', section, key, e)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if prompt == '/':
|
if prompt == '/':
|
||||||
return True
|
return True
|
||||||
|
|
||||||
_prompt(bus, prompt).Dismiss()
|
_prompt(bus, prompt).Dismiss()
|
||||||
logger.debug('Saving secret %s/%s failed as keyring is locked',
|
logger.debug('Saving secret %s/%s failed: Keyring is locked',
|
||||||
section, key)
|
section, key)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def _bus():
|
|
||||||
if not dbus:
|
|
||||||
return None
|
|
||||||
try:
|
|
||||||
return dbus.SessionBus()
|
|
||||||
except dbus.exceptions.DBusException as e:
|
|
||||||
logger.debug('Unable to connect to dbus: %s', e)
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
def _secrets_running(bus):
|
|
||||||
return bus and bus.name_has_owner('org.freedesktop.secrets')
|
|
||||||
|
|
||||||
|
|
||||||
def _serivce(bus):
|
def _serivce(bus):
|
||||||
return _interface(bus, '/org/freedesktop/secrets',
|
return _interface(bus, '/org/freedesktop/secrets',
|
||||||
'org.freedesktop.Secret.Service')
|
'org.freedesktop.Secret.Service')
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user