OpenSSL-style password argument handling.
Project description
passarg: OpenSSL password/-phrase argument
The passarg ("password argument") module implements OpenSSL-style password/passphrase argument handling.
Quickstart
from argparse import ArgumentParser
import passarg
parser = ArgumentParser()
parser.add_argument('--pass-in', metavar='SPEC', default='env:MY_PASS_IN')
parser.add_argument('--pass-out', metavar='SPEC', default='env:MY_PASS_OUT')
args = parser.parse_args()
with passarg.reader() as read_passarg:
pass_in = read_passarg(args.pass_in)
pass_out = read_passarg(args.pass_out)
The program above then by default reads the input/output passphrases
from the environment variables ${MY_PASS_IN}
and ${MY_PASS_OUT}
;
if run with --pass-in file:dec-pass.txt --pass-out stdin
,
then it reads the input/output passphrases
from the file dec-pass.txt
and the standard input respectively.
Passphrase Argument Syntax
passarg supports the following OpenSSL-compatible arguments (openssl-passphrase-options(1)):
-
pass:password
The actual password is password. Since the password is visible to utilities (like 'ps' under Unix) this form should only be used where security is not important.
-
env:var
Obtain the password from the environment variable var. Since the environment of other processes is visible on certain platforms (e.g. ps under certain Unix OSes) this option should be used with caution.
-
file:pathname
Reads the password from the specified file pathname, which can be a regular file, device, or named pipe. Only the first line, up to the newline character, is read from the stream.
If the same pathname argument is supplied to both -passin and -passout arguments, the first line will be used for the input password, and the next line will be used for the output password.
-
fd:number
Reads the password from the file descriptor number. This can be useful for sending data via a pipe, for example. The same line handling as described for file: applies to passwords read from file descriptors.
fd: is not supported on Windows.
-
stdin
Reads the password from standard input. The same line handling as described for file: applies to passwords read from standard input.
passarg also supports the following non-OpenSSL extensions:
-
prompt[:text]
Prompts the password using Python getpass(). If text is given, it is used as the prompt. Otherwise, the getpass default (
Password:
) is used. -
op:[//Vault/]TitleOrID[/field]
Fetches the given item using the 1Password CLI. Vault is optional and defaults to
Private
orEmployee
; field is also optional and defaults topassword
.
.env ("dotenv") File Support
passarg can be combined with python-dotenv to add support for dotenv files.
Simply call load_dotenv before entering the passarg.reader()
context:
from argparse import ArgumentParser
import dotenv
import passarg
parser = ArgumentParser()
parser.add_argument('--api-key', metavar='SPEC', default='env:MY_API_KEY')
parser.add_argument('--env-file', metavar='PATH', default='.env')
args = parser.parse_args()
dotenv.load_dotenv(args.env_file)
with passarg.reader() as read_passarg:
api_key = read_passarg(args.api_key)
Then it can be run in the directory with an .env
file like:
MY_API_KEY=MySuperSecretKeyOmigod
Passargs Sharing Same File-like Source
As explained in Passphrase Argument Syntax above, multiple passphrase arguments can share the same file-like source, with each source reading one line from the source.
The order of calls to read_passarg()
matters, and should be documented.
For example, the Quickstart example above
reads --pass-in
first then --pass-out
,
implementing the same input-password-first ordering as with OpenSSL.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file passarg-0.1.0.tar.gz
.
File metadata
- Download URL: passarg-0.1.0.tar.gz
- Upload date:
- Size: 7.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b11ab9591256138ab926b3a1275dae1ad95018b83861f47602c798e24d77f35 |
|
MD5 | 6740a97fdf1dc70fe859f11ec7b44719 |
|
BLAKE2b-256 | 3102c287bdd5328a6078ff92b6b841c0358e7c9b4794641b434eb423099a1088 |
File details
Details for the file passarg-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: passarg-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2d1c2d24fcb8db8a33bb841c54cfdfa0a4b0054fbf2a796762c87e3ef68f960e |
|
MD5 | 86879f74e23608db4b8fcdcefab32ccc |
|
BLAKE2b-256 | 819142ae33d2458b5fd73dd53bee412fb6e0cd60e030cf078829f68a50ad4edc |