我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用keyring.get_keyring()。
def keygen(get_keyring=get_keyring): """Generate a public/private key pair.""" WheelKeys, keyring = get_keyring() ed25519ll = signatures.get_ed25519ll() wk = WheelKeys().load() keypair = ed25519ll.crypto_sign_keypair() vk = native(urlsafe_b64encode(keypair.vk)) sk = native(urlsafe_b64encode(keypair.sk)) kr = keyring.get_keyring() kr.set_password("wheel", vk, sk) sys.stdout.write("Created Ed25519 keypair with vk={0}\n".format(vk)) sys.stdout.write("in {0!r}\n".format(kr)) sk2 = kr.get_password('wheel', vk) if sk2 != sk: raise WheelError("Keyring is broken. Could not retrieve secret key.") sys.stdout.write("Trusting {0} to sign and verify all packages.\n".format(vk)) wk.add_signer('+', vk) wk.trust('+', vk) wk.save()
def get_credentials(username, password): if not username: username = getpass.getuser() _needs_storage = True if not password: # retrieve password from system storage if keyring.get_keyring(): password = keyring.get_password(KEYRING_NAME, username) if password: _needs_storage = False if not password: password = getpass.getpass('Enter password for {}: '.format(username)) if _needs_storage and keyring.get_keyring(): try: keyring.set_password(KEYRING_NAME, username, password) except keyring.errors.PasswordSetError as err: Log.error(err) return username, password