Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

passarg-0.0.2.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

passarg-0.0.2-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file passarg-0.0.2.tar.gz.

File metadata

  • Download URL: passarg-0.0.2.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.32.3

File hashes

Hashes for passarg-0.0.2.tar.gz
Algorithm Hash digest
SHA256 bd938a90aa63bcac778f76fa36424f5764032def55808eba22c63b4eaf4c45ab
MD5 84b0ef49f8bba4298936d37e375d1a05
BLAKE2b-256 d5ba4872affec63e3dc08342bfad5fdc9f2d64fa32c902eb524d560a1692e572

See more details on using hashes here.

File details

Details for the file passarg-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: passarg-0.0.2-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

Hashes for passarg-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c5f8a0e354d6b582f22e1a747d348d8e1a1af5886ca2fb7ed8578c13f7548528
MD5 057e4d57c5cac9301606310cc6c3ca0b
BLAKE2b-256 2226bc6f7db649bfe0ace6a5ce2c4aa2a6d382c6558d1de7275c52f39131ec33

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page