本文整理汇总了Python中keyring.get_keyring方法的典型用法代码示例。如果您正苦于以下问题:Python keyring.get_keyring方法的具体用法?Python keyring.get_keyring怎么用?Python keyring.get_keyring使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类keyring
的用法示例。
在下文中一共展示了keyring.get_keyring方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: keygen
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import get_keyring [as 别名]
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()
示例2: _initialize_keyring
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import get_keyring [as 别名]
def _initialize_keyring():
try:
import keyring
except ImportError:
return
def _only_builtin(backend):
return (
backend.__module__.startswith('keyring.backends.') and
'chain' not in backend.__module__
)
keyring.core.init_backend(_only_builtin)
logger.debug('Keyring backend : %s', keyring.get_keyring())
# a value is required for the python config file that gets generated on some operating systems.
示例3: run
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import get_keyring [as 别名]
def run(self):
"""
Read the configuration file
For any 'keyring'-based parameters: prompt the user to set or edit the value.
"""
opts = {"__any_secrets__": False}
for section in self.config.sections():
items = dict((item.lower(), self.config.get(section, item)) for item in self.config.options(section))
items["__any_secrets__"] = False
opts.update({section: items})
print(u"Secrets are stored with '{}'".format(type(keyring.get_keyring()).__module__))
try:
self.list_parameters(opts)
except (KeyboardInterrupt, EOFError):
print()
if opts.get("__any_secrets__"):
print(u"Done.")
else:
print(u"Nothing to do.")
示例4: keygen
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import get_keyring [as 别名]
def keygen(get_keyring=get_keyring):
"""Generate a public/private key pair."""
warn_signatures()
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)
print("Created Ed25519 keypair with vk={}".format(vk))
print("in {!r}".format(kr))
sk2 = kr.get_password('wheel', vk)
if sk2 != sk:
raise WheelError("Keyring is broken. Could not retrieve secret key.")
print("Trusting {} to sign and verify all packages.".format(vk))
wk.add_signer('+', vk)
wk.trust('+', vk)
wk.save()
示例5: get_keyring
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import get_keyring [as 别名]
def get_keyring():
try:
from ..signatures import keys
import keyring
assert keyring.get_keyring().priority
except (ImportError, AssertionError):
raise WheelError("Install wheel[signatures] (requires keyring, keyrings.alt, pyxdg) for signatures.")
return keys.WheelKeys, keyring
示例6: sign
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import get_keyring [as 别名]
def sign(wheelfile, replace=False, get_keyring=get_keyring):
"""Sign a wheel"""
WheelKeys, keyring = get_keyring()
ed25519ll = signatures.get_ed25519ll()
wf = WheelFile(wheelfile, append=True)
wk = WheelKeys().load()
name = wf.parsed_filename.group('name')
sign_with = wk.signers(name)[0]
sys.stdout.write("Signing {0} with {1}\n".format(name, sign_with[1]))
vk = sign_with[1]
kr = keyring.get_keyring()
sk = kr.get_password('wheel', vk)
keypair = ed25519ll.Keypair(urlsafe_b64decode(binary(vk)),
urlsafe_b64decode(binary(sk)))
record_name = wf.distinfo_name + '/RECORD'
sig_name = wf.distinfo_name + '/RECORD.jws'
if sig_name in wf.zipfile.namelist():
raise WheelError("Wheel is already signed.")
record_data = wf.zipfile.read(record_name)
payload = {"hash":"sha256=" + native(urlsafe_b64encode(hashlib.sha256(record_data).digest()))}
sig = signatures.sign(payload, keypair)
wf.zipfile.writestr(sig_name, json.dumps(sig, sort_keys=True))
wf.zipfile.close()
示例7: _check
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import get_keyring [as 别名]
def _check(self):
try:
import keyring
except Exception as e:
logger.debug("An error occurred while importing keyring: {}".format(str(e)))
self._is_available = False
return
backend = keyring.get_keyring()
name = backend.name.split(" ")[0]
if name == "fail":
logger.debug("No suitable keyring backend found")
self._is_available = False
elif "plaintext" in backend.name.lower():
logger.debug("Only a plaintext keyring backend is available. Not using it.")
self._is_available = False
elif name == "chainer":
try:
import keyring.backend
backends = keyring.backend.get_all_keyring()
self._is_available = any(
[
b.name.split(" ")[0] not in ["chainer", "fail"]
and "plaintext" not in b.name.lower()
for b in backends
]
)
except Exception:
self._is_available = False
if not self._is_available:
logger.warning("No suitable keyring backends were found")
示例8: get_keyring
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import get_keyring [as 别名]
def get_keyring():
"This function requires keyring!"
return None
示例9: get_keyring
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import get_keyring [as 别名]
def get_keyring():
try:
from ..signatures import keys
import keyring
assert keyring.get_keyring().priority
except (ImportError, AssertionError):
raise WheelError(
"Install wheel[signatures] (requires keyring, keyrings.alt, pyxdg) for signatures.")
return keys.WheelKeys, keyring
示例10: sign
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import get_keyring [as 别名]
def sign(wheelfile, replace=False, get_keyring=get_keyring):
"""Sign a wheel"""
WheelKeys, keyring = get_keyring()
ed25519ll = signatures.get_ed25519ll()
wf = WheelFile(wheelfile, append=True)
wk = WheelKeys().load()
name = wf.parsed_filename.group('name')
sign_with = wk.signers(name)[0]
sys.stdout.write("Signing {0} with {1}\n".format(name, sign_with[1]))
vk = sign_with[1]
kr = keyring.get_keyring()
sk = kr.get_password('wheel', vk)
keypair = ed25519ll.Keypair(urlsafe_b64decode(binary(vk)),
urlsafe_b64decode(binary(sk)))
record_name = wf.distinfo_name + '/RECORD'
sig_name = wf.distinfo_name + '/RECORD.jws'
if sig_name in wf.zipfile.namelist():
raise WheelError("Wheel is already signed.")
record_data = wf.zipfile.read(record_name)
payload = {"hash": "sha256=" + native(urlsafe_b64encode(hashlib.sha256(record_data).digest()))}
sig = signatures.sign(payload, keypair)
wf.zipfile.writestr(sig_name, json.dumps(sig, sort_keys=True))
wf.zipfile.close()
示例11: get_keyring
# 需要导入模块: import keyring [as 别名]
# 或者: from keyring import get_keyring [as 别名]
def get_keyring():
try:
from ..signatures import keys
import keyring
except ImportError:
raise WheelError("Install wheel[signatures] (requires keyring, pyxdg) for signatures.")
return keys.WheelKeys, keyring