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
From openssl-passphrase-options(1):
Pass phrase arguments can be formatted as follows.
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.
.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.0.1.tar.gz
.
File metadata
- Download URL: passarg-0.0.1.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6025f02f2424a41664f3b9a167a9cafac2f7a16e1cb72689c2e750a8cd26b57e |
|
MD5 | 2c4d75172d930f03e69ea2e6b2d27c7d |
|
BLAKE2b-256 | b2d386a23e6d3c1c01060b57a6910adc796935747a95f8d4d3beec50d9ef8037 |
File details
Details for the file passarg-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: passarg-0.0.1-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-requests/2.32.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8dd8a1d4c120b62300a8129069201d5926cee6e55c2a2313e5dd9e6324aa8382 |
|
MD5 | 8b73337d009565a4cc031ff9a11cf99d |
|
BLAKE2b-256 | c5ccb3088e0b8285e1b7cb7cc1480ca236deea8cdf5a5ef9087d94d2ebf7e4a5 |