def locked_get(self):
"""Retrieve Credential from file.
Returns:
oauth2client.client.Credentials
"""
credentials = None
content = keyring.get_password(self._service_name, self._user_name)
if content is not None:
try:
credentials = Credentials.new_from_json(content)
credentials.set_store(self)
except ValueError:
pass
return credentials
python类get_password()的实例源码
def locked_get(self):
"""Retrieve Credential from file.
Returns:
oauth2client.client.Credentials
"""
credentials = None
content = keyring.get_password(self._service_name, self._user_name)
if content is not None:
try:
credentials = Credentials.new_from_json(content)
credentials.set_store(self)
except ValueError:
pass
return credentials
def locked_get(self):
"""Retrieve Credential from file.
Returns:
oauth2client.client.Credentials
"""
credentials = None
content = keyring.get_password(self._service_name, self._user_name)
if content is not None:
try:
credentials = client.Credentials.new_from_json(content)
credentials.set_store(self)
except ValueError:
pass
return credentials
keyring_storage.py 文件源码
项目:office-interoperability-tools
作者: milossramek
项目源码
文件源码
阅读 20
收藏 0
点赞 0
评论 0
def locked_get(self):
"""Retrieve Credential from file.
Returns:
oauth2client.client.Credentials
"""
credentials = None
content = keyring.get_password(self._service_name, self._user_name)
if content is not None:
try:
credentials = Credentials.new_from_json(content)
credentials.set_store(self)
except ValueError:
pass
return credentials
def locked_get(self):
"""Retrieve Credential from file.
Returns:
oauth2client.client.Credentials
"""
credentials = None
content = keyring.get_password(self._service_name, self._user_name)
if content is not None:
try:
credentials = client.Credentials.new_from_json(content)
credentials.set_store(self)
except ValueError:
pass
return credentials
def test06(self):
"""Get password from :mod:`keyring`
"""
password = ''.join(random.choice(string.ascii_letters) for _ in range(64))
params = {
'driver': 'postgresql+psycopg2',
'host': 'my.server.com',
'port': 5432,
'user': 'myuser',
'password': None,
'database': 'mydb'
}
# set the password
client.Client.store_password(params, password)
# retrieve password directly from keyring
pw = keyring.get_password(service_name='my.server.com:postgresql+psycopg2', username='myuser')
self.assertEqual(pw, password)
s = client.Client.get_connection_string(params, hide_password=False)
self.assertEqual(s, "postgresql+psycopg2://myuser:{:s}@my.server.com:5432/mydb"
"".format(password))
def get_user_credentials(self): # pragma: no cover
# reason: hard to test methods that shows modal dialogs
username, remember, remember_pswd = self._get_credentials_from_qsettings()
if remember_pswd and username:
# get password from keyring
try:
password = keyring.get_password('github', username)
except RuntimeError:
# no safe keyring backend
_logger().warn('failed to retrieve password from keyring...')
else:
return username, password, remember, remember_pswd
# ask for credentials
username, password, remember, remember_pswd = DlgGitHubLogin.login(
self.parent_widget, username, remember, remember_pswd)
if remember:
self._store_credentials(username, password, remember, remember_pswd)
return username, password, remember, remember_pswd
def auth_token(self):
# Now is where it gets complicated since we
# want to look into the keyring module, if it
# exists and see if anything was provided in that
# file that we can use.
if not HAS_KEYRING or not self.args.os_cache:
return None
token = None
try:
block = keyring.get_password('zunclient_auth',
self._make_key())
if block:
token, _management_url, _tenant_id = block.split('|', 2)
except all_errors:
pass
return token
def locked_get(self):
"""Retrieve Credential from file.
Returns:
oauth2client.client.Credentials
"""
credentials = None
content = keyring.get_password(self._service_name, self._user_name)
if content is not None:
try:
credentials = client.Credentials.new_from_json(content)
credentials.set_store(self)
except ValueError:
pass
return credentials
def locked_get(self):
"""Retrieve Credential from file.
Returns:
oauth2client.client.Credentials
"""
credentials = None
content = keyring.get_password(self._service_name, self._user_name)
if content is not None:
try:
credentials = Credentials.new_from_json(content)
credentials.set_store(self)
except ValueError:
pass
return credentials
credential_store.py 文件源码
项目:jira_reporting_scripts
作者: andrew-hamlin-sp
项目源码
文件源码
阅读 18
收藏 0
点赞 0
评论 0
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
def locked_get(self):
"""Retrieve Credential from file.
Returns:
oauth2client.client.Credentials
"""
credentials = None
content = keyring.get_password(self._service_name, self._user_name)
if content is not None:
try:
credentials = Credentials.new_from_json(content)
credentials.set_store(self)
except ValueError:
pass
return credentials
def locked_get(self):
"""Retrieve Credential from file.
Returns:
oauth2client.client.Credentials
"""
credentials = None
content = keyring.get_password(self._service_name, self._user_name)
if content is not None:
try:
credentials = Credentials.new_from_json(content)
credentials.set_store(self)
except ValueError:
pass
return credentials
def test_get_Fernet_returns_a_key():
fake = Faker()
appname= '_'.join(['test_a_netcrawl_', fake.word(), fake.word()])
username= '_'.join(['test_u_netcrawl_', fake.word(), fake.word()])
key= manage._get_fernet_key(appname, username)
assert isinstance(key, fernet.Fernet), 'Key [{}] is wrong type'.format(
type(key))
assert keyring.get_password(appname, username) is not None
keyring.delete_password(appname, username)
assert keyring.get_password(appname, username) is None
#===============================================================================
# def test_check_credentials_no_error():
# config.cc.check_credentials()
#===============================================================================
def _get_fernet_key(app_name= 'netcrawl',
username= 'netcrawl'):
proc= 'manage._get_fernet_key'
# Retrieve the encryption key from storage or generate one
key= keyring.get_password(app_name, username)
if key is None:
log('Creating encryption key', v= logging.N, proc= proc)
key = Fernet.generate_key()
keyring.set_password(app_name, username, str(key, encoding='utf-8'))
else:
key= bytes(key, encoding='utf-8')
# Create a Fernet key from the base key
return Fernet(key)
del(key)
def locked_get(self):
"""Retrieve Credential from file.
Returns:
oauth2client.client.Credentials
"""
credentials = None
content = keyring.get_password(self._service_name, self._user_name)
if content is not None:
try:
credentials = Credentials.new_from_json(content)
credentials.set_store(self)
except ValueError:
pass
return credentials
def get_password(self, service_name, username=None, section=None, prefix=None):
if section is None:
section = service_name
if prefix is not None:
user_option = "{}_username"
else:
user_option = 'username'
if username is None:
username = self.get_safe(section, user_option, fallback=None)
pw = keyring.get_password(service_name, username)
if pw is None:
if username is None:
msg = "username was not found in settings for section '{}' & option '{}'".format(
section, user_option)
else:
msg = "password was not found for username {} and service name {}".format(
username, service_name)
raise KeyError(msg)
self.set_safe(section, user_option, username)
return pw
def set_password(self, service_name, username, password, **kwargs):
keyring.set_password(service_name, username, password)
self.get_password(service_name, username, **kwargs)
def locked_get(self):
"""Retrieve Credential from file.
Returns:
oauth2client.client.Credentials
"""
credentials = None
content = keyring.get_password(self._service_name, self._user_name)
if content is not None:
try:
credentials = Credentials.new_from_json(content)
credentials.set_store(self)
except ValueError:
pass
return credentials
def decrypt_cookie_db(self):
if self.platform == OperatingSystem.LINUX:
import keyring
from Crypto.Protocol.KDF import PBKDF2
salt = b'saltysalt'
length = 16
# If running Chrome on OSX
if sys.platform == 'darwin':
my_pass = keyring.get_password('Chrome Safe Storage', 'Chrome')
my_pass = my_pass.encode('utf8')
iterations = 1003
self.cookie_file = os.path.expanduser('~/Library/Application Support/Google/Chrome/Default/Cookies')
# If running Chromium on Linux
elif 'linux' in sys.platform:
my_pass = 'peanuts'.encode('utf8')
iterations = 1
self.cookie_file = os.path.expanduser('~/.config/chromium/Default/Cookies')
self.key = PBKDF2(my_pass, salt, length, iterations)
return self.linux_decrypt_value
elif self.platform == OperatingSystem.WINDOWS:
return self.windows_decrypt_value
def locked_get(self):
"""Retrieve Credential from file.
Returns:
oauth2client.client.Credentials
"""
credentials = None
content = keyring.get_password(self._service_name, self._user_name)
if content is not None:
try:
credentials = Credentials.new_from_json(content)
credentials.set_store(self)
except ValueError:
pass
return credentials
def locked_get(self):
"""Retrieve Credential from file.
Returns:
oauth2client.client.Credentials
"""
credentials = None
content = keyring.get_password(self._service_name, self._user_name)
if content is not None:
try:
credentials = Credentials.new_from_json(content)
credentials.set_store(self)
except ValueError:
pass
return credentials
def locked_get(self):
"""Retrieve Credential from file.
Returns:
oauth2client.client.Credentials
"""
credentials = None
content = keyring.get_password(self._service_name, self._user_name)
if content is not None:
try:
credentials = Credentials.new_from_json(content)
credentials.set_store(self)
except ValueError:
pass
return credentials
def locked_get(self):
"""Retrieve Credential from file.
Returns:
oauth2client.client.Credentials
"""
credentials = None
content = keyring.get_password(self._service_name, self._user_name)
if content is not None:
try:
credentials = Credentials.new_from_json(content)
credentials.set_store(self)
except ValueError:
pass
return credentials
def locked_get(self):
"""Retrieve Credential from file.
Returns:
oauth2client.client.Credentials
"""
credentials = None
content = keyring.get_password(self._service_name, self._user_name)
if content is not None:
try:
credentials = Credentials.new_from_json(content)
credentials.set_store(self)
except ValueError:
pass
return credentials
def locked_get(self):
"""Retrieve Credential from file.
Returns:
oauth2client.client.Credentials
"""
credentials = None
content = keyring.get_password(self._service_name, self._user_name)
if content is not None:
try:
credentials = Credentials.new_from_json(content)
credentials.set_store(self)
except ValueError:
pass
return credentials
def locked_get(self):
"""Retrieve Credential from file.
Returns:
oauth2client.client.Credentials
"""
credentials = None
content = keyring.get_password(self._service_name, self._user_name)
if content is not None:
try:
credentials = Credentials.new_from_json(content)
credentials.set_store(self)
except ValueError:
pass
return credentials
def locked_get(self):
"""Retrieve Credential from file.
Returns:
oauth2client.client.Credentials
"""
credentials = None
content = keyring.get_password(self._service_name, self._user_name)
if content is not None:
try:
credentials = Credentials.new_from_json(content)
credentials.set_store(self)
except ValueError:
pass
return credentials
def locked_get(self):
"""Retrieve Credential from file.
Returns:
oauth2client.client.Credentials
"""
credentials = None
content = keyring.get_password(self._service_name, self._user_name)
if content is not None:
try:
credentials = client.Credentials.new_from_json(content)
credentials.set_store(self)
except ValueError:
pass
return credentials
def locked_get(self):
"""Retrieve Credential from file.
Returns:
oauth2client.client.Credentials
"""
credentials = None
content = keyring.get_password(self._service_name, self._user_name)
if content is not None:
try:
credentials = client.Credentials.new_from_json(content)
credentials.set_store(self)
except ValueError:
pass
return credentials