Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import keyring.backend
import pytest
import six
from supernova import credentials, utils
class TestKeyring(keyring.backend.KeyringBackend):
"""A test keyring which always outputs same password
"""
priority = 1
def set_password(self, servicename, username, password):
pass
def get_password(self, servicename, username):
return "password from TestKeyring"
def delete_password(self, servicename, username, password):
pass
class TestCredentials(object):
self._storage[servicename] = dict()
self._storage[servicename][username] = password
def get_password(self, servicename, username):
if servicename in self._storage:
return self._storage[servicename].get(username)
def delete_password(self, servicename, username):
if servicename in self._storage:
if username in self._storage[servicename]:
del self._storage[servicename][username]
if not self._storage[servicename]:
del self._storage[servicename]
class BrokenKeyring(KeyringBackend):
priority = 1
def set_password(self, servicename, username, password):
raise KeyringError()
def get_password(self, servicename, username):
raise KeyringError()
def delete_password(self, servicename, username):
raise KeyringError()
@pytest.fixture
def keyring(): # type: () -> KeyringBackend
k = DictKeyring()
set_keyring(k)
from uuid import uuid4
import pytest
from keyring import get_keyring
from keyring import set_keyring
from keyring.backend import KeyringBackend
from keyring.errors import KeyringError
from poetry.utils.helpers import keyring_repository_password_del
from poetry.utils.helpers import keyring_repository_password_get
from poetry.utils.helpers import keyring_repository_password_set
from poetry.utils.helpers import keyring_service_name
class DictKeyring(KeyringBackend):
priority = 1
def __init__(self):
self._storage = dict()
def set_password(self, servicename, username, password):
if servicename not in self._storage:
self._storage[servicename] = dict()
self._storage[servicename][username] = password
def get_password(self, servicename, username):
if servicename in self._storage:
return self._storage[servicename].get(username)
def delete_password(self, servicename, username):
if servicename in self._storage:
GPG_KEYDIR = os.path.join(TMP, 'gpg-keydir')
# The keyring library uses `getcwd()`, let's make sure we in a good directory
# before importing keyring
if not os.path.isdir(GPG_KEYDIR):
os.makedirs(GPG_KEYDIR)
os.chdir(GPG_KEYDIR)
# Import external deps
try:
import keyring
import keyring.backend
class TestKeyring(keyring.backend.KeyringBackend):
'''
A test keyring which always outputs same password
'''
def __init__(self):
self.__storage = {}
def supported(self):
return 0
def set_password(self, servicename, username, password):
self.__storage.setdefault(servicename, {}).update({username: password})
return 0
def get_password(self, servicename, username):
return self.__storage.setdefault(servicename, {}).get(username, None)
from keyring.backend import KeyringBackend
from node_launcher.constants import IS_WINDOWS, IS_MACOS, IS_LINUX
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)
from lbry.conf import Config
from lbry.extras.daemon.loggly_handler import get_loggly_handler
from lbry.extras.daemon.Components import DHT_COMPONENT, HASH_ANNOUNCER_COMPONENT, PEER_PROTOCOL_SERVER_COMPONENT
from lbry.extras.daemon.Daemon import Daemon
from lbry.extras.daemon.loggly_handler import get_loggly_handler
log = logging.getLogger(__name__)
log.setLevel(logging.DEBUG)
lbrynet_android_utils = autoclass('io.lbry.browser.Utils')
service = autoclass('io.lbry.browser.LbrynetService').serviceInstance
platform.platform = lambda: 'Android %s (API %s)' % (lbrynet_android_utils.getAndroidRelease(), lbrynet_android_utils.getAndroidSdk())
build_type.BUILD = 'dev' if lbrynet_android_utils.isDebug() else 'release'
# Keyring backend
class LbryAndroidKeyring(KeyringBackend):
priority = 1
def __init__(self):
self._keystore = lbrynet_android_utils.initKeyStore(service.getApplicationContext())
def set_password(self, servicename, username, password):
context = service.getApplicationContext()
lbrynet_android_utils.setPassword(servicename, username, password, context, self._keystore)
def get_password(self, servicename, username):
context = service.getApplicationContext()
return lbrynet_android_utils.getPassword(servicename, username, context, self._keystore)
def delete_password(self, servicename, username):
context = service.getApplicationContext()
lbrynet_android_utils.deletePassword(servicename, username, context, self._keystore)
import itertools
from keyring.util import properties
from keyring.backend import KeyringBackend
from keyring import errors
class MultipartKeyringWrapper(KeyringBackend):
"""A wrapper around an existing keyring that breaks the password into
smaller parts to handle implementations that have limits on the maximum
length of passwords i.e. Windows Vault
"""
def __init__(self, keyring, max_password_size=512):
self._keyring = keyring
self._max_password_size = max_password_size
@properties.ClassProperty
@classmethod
def priority(cls):
return 0
def get_password(self, service, username):
from keyring import errors
from keyring import credentials
from keyring.py27compat import input, pickle
from keyring.backend import KeyringBackend
from keyring.util import properties
from keyring.errors import ExceptionRaisedContext
class EnvironCredential(credentials.EnvironCredential):
"""Retrieve credentials from specifically named environment variables
"""
def __init__(self):
super(EnvironCredential, self).__init__('GOOGLE_KEYRING_USER',
'GOOGLE_KEYRING_PASSWORD')
class DocsKeyring(KeyringBackend):
"""Backend that stores keyring on Google Docs.
Note that login and any other initialisation is deferred until it is
actually required to allow this keyring class to be added to the
global _all_keyring list.
"""
keyring_title = 'GoogleKeyring'
# status enums
OK = 1
FAIL = 0
CONFLICT = -1
def __init__(self, credential, source, crypter,
collection=None, client=None,
can_create=True, input_getter=input
):
return .8
filename = 'wincrypto_pass.cfg'
def encrypt(self, password):
"""Encrypt the password using the CryptAPI.
"""
return _win_crypto.encrypt(password)
def decrypt(self, password_encrypted):
"""Decrypt the password using the CryptAPI.
"""
return _win_crypto.decrypt(password_encrypted)
class RegistryKeyring(KeyringBackend):
"""
RegistryKeyring is a keyring which use Windows CryptAPI to encrypt
the user's passwords and store them under registry keys
"""
@properties.ClassProperty
@classmethod
def priority(self):
"""
Preferred on Windows when pywin32 isn't installed
"""
if platform.system() != 'Windows':
raise RuntimeError("Requires Windows")
if not has_wincrypto():
raise RuntimeError("Requires ctypes")
return 2
"""
simplekeyring.py
A simple keyring class for the keyring_demo.py
Created by Kang Zhang on 2009-07-12
"""
from keyring.backend import KeyringBackend
class SimpleKeyring(KeyringBackend):
"""Simple Keyring is a keyring which can store only one
password in memory.
"""
def __init__(self):
self.password = ''
def supported(self):
return 0
def get_password(self, service, username):
return self.password
def set_password(self, service, username, password):
self.password = password
return 0