mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-15 23:15:52 +08:00
Merge pull request #10023 from Ultimaker/CURA-8332_Cura_crashes_when_access_to_keyring_is_denied
CURA-8332: Cura crashes when access to keyring is denied
This commit is contained in:
commit
aabbdd2040
@ -1,10 +1,10 @@
|
|||||||
# Copyright (c) 2021 Ultimaker B.V.
|
# Copyright (c) 2021 Ultimaker B.V.
|
||||||
# Cura is released under the terms of the LGPLv3 or higher.
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
from typing import Type, TYPE_CHECKING, Optional, List, Union
|
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, KeyringError
|
from keyring.errors import NoKeyringError, PasswordSetError, KeyringLocked
|
||||||
|
|
||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
|
|
||||||
@ -14,24 +14,13 @@ if TYPE_CHECKING:
|
|||||||
# Need to do some extra workarounds on windows:
|
# Need to do some extra workarounds on windows:
|
||||||
import sys
|
import sys
|
||||||
from UM.Platform import Platform
|
from UM.Platform import Platform
|
||||||
|
|
||||||
|
|
||||||
class _KeychainDenied(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
if Platform.isWindows() and hasattr(sys, "frozen"):
|
if Platform.isWindows() and hasattr(sys, "frozen"):
|
||||||
import win32timezone
|
import win32timezone
|
||||||
from keyring.backends.Windows import WinVaultKeyring
|
from keyring.backends.Windows import WinVaultKeyring
|
||||||
keyring.set_keyring(WinVaultKeyring())
|
keyring.set_keyring(WinVaultKeyring())
|
||||||
if Platform.isOSX() and hasattr(sys, "frozen"):
|
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 as _KeychainDeniedMacOS
|
|
||||||
KeychainDenied: Union[Type[_KeychainDenied], Type[_KeychainDeniedMacOS]] = _KeychainDeniedMacOS
|
|
||||||
keyring.set_keyring(Keyring())
|
keyring.set_keyring(Keyring())
|
||||||
else:
|
|
||||||
KeychainDenied = _KeychainDenied
|
|
||||||
|
|
||||||
|
|
||||||
# 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"]
|
||||||
@ -50,7 +39,7 @@ 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 KeychainDenied:
|
except KeyringLocked:
|
||||||
self._store_secure = False
|
self._store_secure = False
|
||||||
Logger.log("i", "Access to the keyring was denied.")
|
Logger.log("i", "Access to the keyring was denied.")
|
||||||
return getattr(instance, self._name)
|
return getattr(instance, self._name)
|
||||||
@ -63,7 +52,7 @@ class KeyringAttribute:
|
|||||||
if value is not None:
|
if value is not None:
|
||||||
try:
|
try:
|
||||||
keyring.set_password("cura", self._keyring_name, value)
|
keyring.set_password("cura", self._keyring_name, value)
|
||||||
except PasswordSetError:
|
except (PasswordSetError, KeyringLocked):
|
||||||
self._store_secure = False
|
self._store_secure = False
|
||||||
if self._name not in DONT_EVER_STORE_LOCALLY:
|
if self._name not in DONT_EVER_STORE_LOCALLY:
|
||||||
setattr(instance, self._name, value)
|
setattr(instance, self._name, value)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user