|
15 | 15 | """
|
16 | 16 | import logging
|
17 | 17 |
|
18 |
| -import gi # https://pygobject.readthedocs.io/en/latest/getting_started.html |
19 |
| - |
20 |
| -# pylint: disable=no-name-in-module |
21 |
| -gi.require_version("Secret", "1") # Would require a package gir1.2-secret-1 |
22 |
| -# pylint: disable=wrong-import-position |
23 |
| -from gi.repository import Secret # Would require a package gir1.2-secret-1 |
24 |
| - |
25 |
| - |
26 | 18 | logger = logging.getLogger(__name__)
|
27 | 19 |
|
| 20 | +try: |
| 21 | + import gi # https://github.com/AzureAD/microsoft-authentication-extensions-for-python/wiki/Encryption-on-Linux |
| 22 | +except ImportError: |
| 23 | + logger.exception( |
| 24 | + """Runtime dependency of PyGObject is missing. |
| 25 | +Depends on your Linux distro, you could install it system-wide by something like: |
| 26 | + sudo apt install python3-gi python3-gi-cairo gir1.2-secret-1 |
| 27 | +If necessary, please refer to PyGObject's doc: |
| 28 | +https://pygobject.readthedocs.io/en/latest/getting_started.html |
| 29 | +""") |
| 30 | + raise |
| 31 | + |
| 32 | +try: |
| 33 | + # pylint: disable=no-name-in-module |
| 34 | + gi.require_version("Secret", "1") # Would require a package gir1.2-secret-1 |
| 35 | + # pylint: disable=wrong-import-position |
| 36 | + from gi.repository import Secret # Would require a package gir1.2-secret-1 |
| 37 | +except (ValueError, ImportError): |
| 38 | + logger.exception( |
| 39 | + """Require a package "gir1.2-secret-1" which could be installed by: |
| 40 | + sudo apt install gir1.2-secret-1 |
| 41 | + """) |
| 42 | + raise |
| 43 | + |
28 | 44 | class LibSecretAgent(object):
|
29 | 45 | """A loader/saver built on top of low-level libsecret"""
|
30 | 46 | # Inspired by https://developer.gnome.org/libsecret/unstable/py-examples.html
|
@@ -111,9 +127,12 @@ def trial_run():
|
111 | 127 | assert agent.load() == payload # This line is probably not reachable
|
112 | 128 | agent.clear()
|
113 | 129 | except (gi.repository.GLib.Error, AssertionError):
|
114 |
| - message = ( |
115 |
| - "libsecret did not perform properly. Please refer to " |
116 |
| - "https://github.com/AzureAD/microsoft-authentication-extensions-for-python/wiki/Encryption-on-Linux") # pylint: disable=line-too-long |
| 130 | + message = """libsecret did not perform properly. |
| 131 | +* If you encountered error "Remote error from secret service: |
| 132 | + org.freedesktop.DBus.Error.ServiceUnknown", |
| 133 | + you may need to install gnome-keyring package. |
| 134 | +* Headless mode (such as in an ssh session) is not supported. |
| 135 | +""" |
117 | 136 | logger.exception(message) # This log contains trace stack for debugging
|
118 | 137 | logger.warning(message) # This is visible by default
|
119 | 138 | raise
|
|
0 commit comments