def save_keyring_credentials(api_key, user_id, ring=_KEYRING): '''Saves the user's credentials.''' if sys.platform.startswith('win'): keyring.set_keyring(WinVaultKeyring()) if sys.platform.startswith('darwin'): keyring.set_keyring(Keyring()) value = _encoded(api_key, user_id) if __debug__: log(f'storing "{value}" to keyring {_KEYRING}') keyring.set_password(ring, getpass.getuser(), value)
def keyring_credentials(ring=_KEYRING): '''Looks up the user's credentials.''' if sys.platform.startswith('win'): keyring.set_keyring(WinVaultKeyring()) if sys.platform.startswith('darwin'): keyring.set_keyring(Keyring()) value = keyring.get_password(ring, getpass.getuser()) if __debug__: log(f'got "{value}" from keyring {_KEYRING}') return _decoded(value) if value else (None, None)
def save_keyring_credentials(service, user, pswd, host=None, port=None): '''Saves the user, password, host and port info for 'service'.''' user = user if user else '' pswd = pswd if pswd else '' host = host if host else '' port = port if port else '' if sys.platform.startswith('win'): keyring.set_keyring(WinVaultKeyring()) keyring.set_password(service, 'credentials', _encoded(user, pswd, host, port))
def __init__(self): if IS_WINDOWS: from keyring.backends.Windows import WinVaultKeyring as Keyring elif IS_MACOS: from keyring.backends.OS_X import Keyring elif IS_LINUX: from keyring.backends.SecretService import Keyring else: raise NotImplementedError() self.backend = Keyring()
def keyring_credentials(service, user=None): '''Looks up the user's credentials for the given 'service' using the keyring/keychain facility on this computer. If 'user' is None, this uses the fake user named "credentials". The latter makes it possible to access a service with a different user login name than the user's current login name without having to ask the user for the alternative name every time. ''' if sys.platform.startswith('win'): keyring.set_keyring(WinVaultKeyring()) value = keyring.get_password(service, user if user else 'credentials') return _decoded(value) if value else (None, None, None, None)
def set_keyring(self): if platform.system() == WINDOWS: keyring.set_keyring(WinVaultKeyring()) elif os.environ.get(OVERRIDE_KEYRING_ENV_VAR ) == "true": # Used in builds when running tests keyring.set_keyring(PlaintextKeyring()) elif platform.system() == MAC: keyring.set_keyring(keyring.backends.OS_X.Keyring()) elif platform.system() == LINUX: keyring.set_keyring(FiggyKeyring()) else: Utils.stc_error_exit( "Only OSX and MAC and Linux with installed SecretStorage are supported for " "OKTA + Keyring integration.")
class SystemKeyring(KeyringBackend): backend: KeyringBackend def __init__(self): if IS_WINDOWS: from keyring.backends.Windows import WinVaultKeyring as Keyring elif IS_MACOS: from keyring.backends.OS_X import Keyring elif IS_LINUX: from keyring.backends.SecretService import Keyring else: raise NotImplementedError() self.backend = Keyring() def set_password(self, service, username, password): return self.backend.set_password(service, username, password) def get_password(self, service, username): return self.backend.get_password(service, username) def delete_password(self, service, username): return self.backend.delete_password(service, username)
BITCOIN_DATA_PATH: Dict[OperatingSystem, str] = { DARWIN: expanduser('~/Library/Application Support/Bitcoin/'), LINUX: expanduser('~/.bitcoin'), WINDOWS: os.path.join(APPDATA, 'Bitcoin') } UPGRADE = 'Please download the latest version of the Node Launcher: ' \ '<a href="https://github.com/PierreRochard/node-launcher/releases/">' \ 'https://github.com/PierreRochard/node-launcher/releases' \ '</a>' GIGABYTE = 1000000000 if IS_WINDOWS: from keyring.backends.Windows import WinVaultKeyring keyring = WinVaultKeyring() if IS_MACOS: from keyring.backends.OS_X import Keyring keyring = Keyring() if IS_LINUX: from keyring.backends.SecretService import Keyring keyring = Keyring() # How many megabytes to keep # Total Bitcoin (mainnet) data directory size minus blocks is ~3 GB # We are targeting 10 GB, so 10 - 3 = 7 MAINNET_PRUNE = 7000 TESTNET_PRUNE = 1000
import keyring from keyring.backend import KeyringBackend from keyring.errors import NoKeyringError, PasswordSetError from UM.Logger import Logger if TYPE_CHECKING: from cura.OAuth2.Models import BaseModel # Need to do some extra workarounds on windows: import sys from UM.Platform import Platform if Platform.isWindows() and hasattr(sys, "frozen"): import win32timezone from keyring.backends.Windows import WinVaultKeyring keyring.set_keyring(WinVaultKeyring()) if Platform.isOSX() and hasattr(sys, "frozen"): from keyring.backends.macOS import Keyring keyring.set_keyring(Keyring()) # Even if errors happen, we don't want this stored locally: DONT_EVER_STORE_LOCALLY: List[str] = ["refresh_token"] class KeyringAttribute: """ Descriptor for attributes that need to be stored in the keyring. With Fallback behaviour to the preference cfg file """ def __get__(self, instance: "BaseModel", owner: type) -> Optional[str]: if self._store_secure: # type: ignore try:
def fake_vault_creds(): keyring.set_keyring(WinVaultKeyring()) keyring.set_password("test_app", "test_user", "test_passw") yield keyring.delete_password("test_app", "test_user")