本文整理汇总了Python中keyring.set_password方法的典型用法代码示例。如果您正苦于以下问题:Python keyring.set_password方法的具体用法?Python keyring.set_password怎么用?Python keyring.set_password使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类keyring
的用法示例。
在下文中一共展示了keyring.set_password方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: write_temporary_credential
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import set_password [as 别名]
def write_temporary_credential(host, account, user, id_token, store_temporary_credential=False):
if not id_token:
logger.debug("no ID token is given when try to store temporary credential")
return
if IS_MACOS or IS_WINDOWS:
if not keyring:
logger.debug("Dependency 'keyring' is not installed, cannot cache id token. You might experience "
"multiple authentication pop ups while using ExternalBrowser Authenticator. To avoid "
"this please install keyring module using the following command : pip install "
"snowflake-connector-python[secure-local-storage]")
return
new_target = convert_target(host, user)
try:
keyring.set_password(new_target, user.upper(), id_token)
except keyring.errors.KeyringError as ke:
logger.debug("Could not store id_token to keyring, %s", str(ke))
elif IS_LINUX and store_temporary_credential:
write_temporary_credential_file(host, account, user, id_token)
else:
logger.debug("connection parameter client_store_temporary_credential not set or OS not support")
示例2: set_password
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import set_password [as 别名]
def set_password(self, name, username, password):
if not self.is_available():
return
import keyring
import keyring.errors
name = self.get_entry_name(name)
try:
keyring.set_password(name, username, password)
except (RuntimeError, keyring.errors.KeyringError) as e:
raise KeyRingError(
"Unable to store the password for {} in the key ring: {}".format(
name, str(e)
)
)
示例3: set_secret
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import set_password [as 别名]
def set_secret(self, secret_name: str, secret_value: Any):
"""
Set a secret in the keyring group.
Parameters
----------
secret_name : str
Name of the secret
secret_value : Any
Secret value
"""
if self.debug:
print(f"Saving {secret_name} to keyring {self.keyring}")
self._secret_names.add(secret_name)
keyring.set_password(self.keyring, secret_name, secret_value)
示例4: login
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import set_password [as 别名]
def login(self):
# Get RACKSPACE_USERNAME and RACKSPACE_API_KEY envvars
# prompt for them interactively.
# The envvar approach works scripted commands, while the interactive
# mode is preferred for executing on the command line (by a human).
self._rax_username = get_username()
self._rax_api_key = get_api_key(self.rax_username)
# TODO(larsbutler): perform login against the rackspace identity api
# store them in keyring:
keyring.set_password(
const.NAMESPACE, 'rackspace_username', self.rax_username
)
keyring.set_password(
const.NAMESPACE, 'rackspace_api_key', self.rax_api_key
)
print('login successful!')
示例5: get_keychain_key
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import set_password [as 别名]
def get_keychain_key(self):
key_from_env = os.environ.get("CUMULUSCI_KEY")
try:
key_from_keyring = keyring.get_password("cumulusci", "CUMULUSCI_KEY")
has_functioning_keychain = True
except Exception as e:
keychain_exception = e
key_from_keyring = None
has_functioning_keychain = False
# If no key in environment or file, generate one
key = key_from_env or key_from_keyring
if key is None:
if has_functioning_keychain:
key = random_alphanumeric_underscore(length=16)
else:
raise KeychainKeyNotFound(
"Unable to store CumulusCI encryption key. "
"You can configure it manually by setting the CUMULUSCI_KEY "
"environment variable to a random 16-character string. "
f"ERROR: {keychain_exception}"
)
if has_functioning_keychain and not key_from_keyring:
keyring.set_password("cumulusci", "CUMULUSCI_KEY", key)
return key
示例6: check_org_expired
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import set_password [as 别名]
def check_org_expired(self, org_name, org_config):
if org_config.scratch and org_config.date_created and org_config.expired:
click.echo(click.style("The scratch org is expired", fg="yellow"))
self.keychain.create_scratch_org(
org_name,
org_config.config_name,
days=org_config.days,
set_password=org_config.set_password,
)
click.echo(
click.style(
"Org config was refreshed, attempting to recreate scratch org",
fg="yellow",
)
)
org_config = self.keychain.get_org(org_name)
org_config.create_org()
return org_config
示例7: reset_credentials
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import set_password [as 别名]
def reset_credentials(self, service_name, username, new_secret_items=None):
"""
Removes a username/password from KeyRing
and replaces with a new one if desired.
:param service_name: (str)
The service name to remove.
:param username: (str)
The username to remove the password for.
:param new_secret_items: (list, default None)
The new secret item(s) to assign to the username if desired.
:return: (None)
"""
try:
keyring.delete_password(service_name, username)
except keyring.errors.PasswordDeleteError:
pass
if new_secret_items:
new_pass = self._join_password_items(new_secret_items)
keyring.set_password(service_name, username, new_pass)
示例8: update_connection
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import set_password [as 别名]
def update_connection(self, data):
if 'key' not in data:
data['key'] = str(uuid.uuid4()).replace('-', '')
key = data.pop('key')
if os.path.exists(CONNECTIONS_FILE):
with open(CONNECTIONS_FILE) as f:
content = json.load(f)
else:
content = {}
password = data.pop('password', None)
content[key] = data
with open(CONNECTIONS_FILE, 'w') as f:
json.dump(content, f)
if password is not None:
data['password'] = password
conn = self.get_connection(key)
if not (conn and conn.has_session_password()):
keyring.set_password('runsqlrun', key, password)
self.update_connections()
return key
示例9: dump_profile
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import set_password [as 别名]
def dump_profile(profile):
'''保存帐户的配置信息.
这里会检查用户是否愿意保存密码, 如果需要保存密码的话, 就调用keyring来存
放密码.
但如果密码为空, 就不再存放它了.
'''
profile = profile.copy()
path = os.path.join(Config.CONF_DIR, profile['username'])
if profile['remember-password'] and profile['password']:
for i in range(RETRIES):
try:
keyring.set_password(Config.DBUS_APP_NAME, profile['username'],
profile['password'])
break
except dbus.exceptions.DBusException:
logger.error(traceback.format_exc())
profile['password'] = ''
with open(path, 'w') as fh:
json.dump(profile, fh)
示例10: _initialize_credentials
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import set_password [as 别名]
def _initialize_credentials(self, auth_token_resp):
"""
The auth_token_resp body is of the form:
{
"access_token": "foo",
"refresh_token": "bar",
"id_token": "baz",
"token_type": "Bearer"
}
"""
response_body = auth_token_resp.json()
if "access_token" not in response_body:
raise ValueError('Expected "access_token" in response from oauth server')
if "refresh_token" in response_body:
self._refresh_token = response_body["refresh_token"]
access_token = response_body["access_token"]
refresh_token = response_body["refresh_token"]
_keyring.set_password(_keyring_service_name, _keyring_access_token_storage_key, access_token)
_keyring.set_password(_keyring_service_name, _keyring_refresh_token_storage_key, refresh_token)
self._credentials = Credentials(access_token=access_token)
示例11: set
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import set_password [as 别名]
def set(self, namespace, path, value, to_keyring=False):
path = '%s.%s' % (namespace, path)
if to_keyring:
keyring.set_password(APPNAME, path, value)
else:
utils.rset(self.values, path, value)
示例12: set_password
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import set_password [as 别名]
def set_password(self, account, password):
try:
import keyring
keyring.set_password(self.identifier, account, password)
except ImportError:
pass
示例13: locked_put
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import set_password [as 别名]
def locked_put(self, credentials):
"""Write Credentials to file.
Args:
credentials: Credentials, the credentials to store.
"""
keyring.set_password(self._service_name, self._user_name,
credentials.to_json())
示例14: locked_delete
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import set_password [as 别名]
def locked_delete(self):
"""Delete Credentials file.
Args:
credentials: Credentials, the credentials to store.
"""
keyring.set_password(self._service_name, self._user_name, '')
示例15: set_pypi_token
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import set_password [as 别名]
def set_pypi_token(self, name, token):
if not self.keyring.is_available():
self._config.auth_config_source.add_property(
"pypi-token.{}".format(name), token
)
else:
self.keyring.set_password(name, "__token__", token)