def set_key_custodian_passphrase(wkf): 'update a key custodian passphrase' user_id = prompt('User email: ') passphrase = prompt.secret('Current passphrase: ') creds = Creds(user_id, passphrase) _check_creds(wkf, creds) new_passphrase = prompt.secret('New passphrase: ', confirm=True) return wkf.set_key_custodian_passphrase(creds, new_passphrase)
def _ask_blackjack(): bottom = int(prompt.secret('Bottom card: ', confirm=True)) top = int(prompt('Top card: ')) total = top + bottom if total > 21: res = 'bust' elif total == 21: res = 'blackjack!' else: res = 'hit (if you feel lucky)' print(res) return
def _get_creds(kf, user=None, interactive=True, check_env=True, passphrase_file=None, user_env_var='PPROTECT_USER', pass_env_var='PPROTECT_PASSPHRASE'): if not interactive and not check_env: raise UsageError('expected at least one of check_env' ' and interactive to be True', 2) user_source = 'argument' passphrase, passphrase_source = None, None if passphrase_file: passphrase_file = os.path.abspath(passphrase_file) try: passphrase = open(passphrase_file, 'rb').read().decode('utf8') except IOError as ioe: if getattr(ioe, 'strerror', None): msg = '%s while reading passphrase from file at "%s"' % (ioe.strerror, passphrase_file) else: msg = 'Failed to read passphrase from file at "%s"' % passphrase_file raise UsageError(msg=msg) else: passphrase_source = "passphrase file: %s" % passphrase_file if user is None and user_env_var: user = os.getenv(user_env_var) user_source = 'env var: %s' % user_env_var if passphrase is None and pass_env_var: passphrase = os.getenv(pass_env_var) passphrase_source = 'env var: %s' % pass_env_var if interactive: msg = '' if user is None: msg = 'Verify credentials for %s' % kf.path elif passphrase is None: msg = 'Verify passphrase for %s (Using user %s from %s)' % (kf.path, user, user_source) if msg: echo.err(msg) if user is None: user = prompt('User email: ') user_source = 'stdin' if passphrase is None: passphrase = prompt.secret('Passphrase: ', confirm=False) passphrase_source = 'stdin' creds = Creds(_get_text(user or ''), _get_text(passphrase or ''), name_source=user_source, passphrase_source=passphrase_source) _check_creds(kf, creds) return creds
def _get_new_creds(confirm=True): user_id = prompt('User email: ') passphrase = prompt.secret('Passphrase: ', confirm=confirm) ret = Creds(user_id, passphrase) return ret