def def1(username, password): """ Example showing option default values. The defaults will be used if an option is not provided. """ echo_setup(def1, def1.name, 'username', 'hostname') echo_input(username=username, password=password) echo_result(def1.name, username)
def def2(username, password): """ Example showing defaults from click context default map: https://click.palletsprojects.com/en/7.x/commands/#context-defaults The defaults will be used if an option is not provided. """ echo_setup(def2, def2.name, 'username') echo_input(username=username, password=password) echo_result(def2.name, username)
def simple_cmd(username, password, clean_up): """ Example of click_keyring using defaults. The password will be saved to keyring with service name matching the click command name (in this case "simple_cmd"). This can be overridden by setting `prefix` and/or `keyring_option` on the decorator. """ echo_setup(simple_cmd, simple_cmd.name, 'username') echo_input(username=username, password=password) echo_result(simple_cmd.name, username)
def cmd1(hostname, username, password): """ Example using custom options for the keyring service name. The password will be saved to keyring with service name: `{prefix value}{hostname value}` Setting a custom prefix allows credentials stored by this command to be used by other commands with the same `prefix` and `other_options` values """ echo_setup(cmd1, 'example', 'username', 'hostname') echo_input(username=username, hostname=hostname, password=password) echo_result('example', username, hostname)
def cmd2(hostname, userid, password): """ Example using custom username option. The password will be saved to keyring with service name: `{prefix value}{hostname value}` The user option must be set explicitly to "userid" because it differs from the default "username" Since cmd1 and cmd2 have the same service name format, the same keyring entries will be used for both. """ echo_setup(cmd2, 'example', 'userid', 'hostname') echo_input(userid=userid, hostname=hostname, password=password) echo_result('example', userid, hostname)
def encrypt_cmd(username, password, clean_up): """ Example of click_keyring with encryption. Encrypting the password protects it from other applications that may access the os credential storage system. The password will be encrypted using fernet symmetric encryption (https://cryptography.io/en/latest/fernet/) You must set the `CLICK_KEYRING_KEY` environment variable to a valid encryption key. The same key used to save a credential must also be used to retrieve it later. """ echo_setup(encrypt_cmd, encrypt_cmd.name, 'username') echo_input(username=username, password=password) echo_result(encrypt_cmd.name, username) decrypt_result(encrypt_cmd.name, username)