mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-25 07:33:57 -06:00
Don't check against generic exception
Define the KeychainDenied exception locally in non-Mac operating systems. CURA-8332
This commit is contained in:
parent
7785142831
commit
9fd0ac333e
1 changed files with 6 additions and 6 deletions
|
@ -4,7 +4,7 @@ from typing import Type, TYPE_CHECKING, Optional, List
|
||||||
|
|
||||||
import keyring
|
import keyring
|
||||||
from keyring.backend import KeyringBackend
|
from keyring.backend import KeyringBackend
|
||||||
from keyring.errors import NoKeyringError, PasswordSetError
|
from keyring.errors import NoKeyringError, PasswordSetError, KeyringError
|
||||||
|
|
||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
|
|
||||||
|
@ -22,6 +22,9 @@ if Platform.isOSX() and hasattr(sys, "frozen"):
|
||||||
from keyring.backends.macOS import Keyring
|
from keyring.backends.macOS import Keyring
|
||||||
from keyring.backends.macOS.api import KeychainDenied
|
from keyring.backends.macOS.api import KeychainDenied
|
||||||
keyring.set_keyring(Keyring())
|
keyring.set_keyring(Keyring())
|
||||||
|
else:
|
||||||
|
class KeychainDenied(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
# Even if errors happen, we don't want this stored locally:
|
# Even if errors happen, we don't want this stored locally:
|
||||||
DONT_EVER_STORE_LOCALLY: List[str] = ["refresh_token"]
|
DONT_EVER_STORE_LOCALLY: List[str] = ["refresh_token"]
|
||||||
|
@ -40,12 +43,9 @@ class KeyringAttribute:
|
||||||
self._store_secure = False
|
self._store_secure = False
|
||||||
Logger.logException("w", "No keyring backend present")
|
Logger.logException("w", "No keyring backend present")
|
||||||
return getattr(instance, self._name)
|
return getattr(instance, self._name)
|
||||||
except Exception as e:
|
except KeychainDenied:
|
||||||
self._store_secure = False
|
self._store_secure = False
|
||||||
if Platform.isOSX() and hasattr(sys, "frozen") and type(e) == KeychainDenied:
|
Logger.log("i", "Access to the keyring was denied.")
|
||||||
Logger.log("i", "Access to the keyring was denied.")
|
|
||||||
else:
|
|
||||||
Logger.logException("w", f"Something went wrong while trying to retrieve the password from the Keyring. Exception: {e}")
|
|
||||||
return getattr(instance, self._name)
|
return getattr(instance, self._name)
|
||||||
else:
|
else:
|
||||||
return getattr(instance, self._name)
|
return getattr(instance, self._name)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue