commit 428030c3bc4385489a0c8ab80bb9fe396358a4e0 Author: Franziska Kunsmann Date: Sun Feb 14 11:30:44 2021 +0100 initial commit diff --git a/bwpass.py b/bwpass.py new file mode 100644 index 0000000..829dfdb --- /dev/null +++ b/bwpass.py @@ -0,0 +1,62 @@ +from os import environ +from os.path import expanduser +from subprocess import check_output, CalledProcessError + +from bundlewrap.exceptions import FaultUnavailable +from bundlewrap.utils import Fault +from bundlewrap.utils.text import bold, yellow +from bundlewrap.utils.ui import io + +PASSWORD_STORE_DIR = expanduser(environ.get('BW_PASS_DIR', '~/.password-store')) +DUMMY_MODE = environ.get('PW_PASS_DUMMY_MODE', '0') == '1' + +cache = {} + +def _get_contents_from_pass(identifier: str): + try: + return cache[identifier] + except KeyError: + # Not yet fetched from pass + pass + + with io.job('{p} fetching {identifier}'.format( + p=bold('pass'), + identifier=identifier, + )): + try: + pass_output = check_output( + ['pass', 'show', identifier], + env={ + 'PASSWORD_STORE_DIR': PASSWORD_STORE_DIR, + } + ).decode('UTF-8').splitlines() + except FileNotFoundError: + raise FaultUnavailable('pass not found') + except CalledProcessError as e: + raise FaultUnavailable('pass exited {} when trying to get secret "{}"'.format( + e.returncode, + identifier, + )) + + cache[identifier] = {} + cache[identifier]['password'] = pass_output[0] + + # TODO import all other options set in pass + + return cache[identifier] + + +def _password(identifier): + if DUMMY_MODE: + return 'PASS DUMMY PASSWORD' + else: + secret = _get_contents_from_pass(identifier) + return secret['password'] + + +def password(identifier): + return Fault( + 'bwpass password', + _password, + identifier=identifier, + ) diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..13ce1a2 --- /dev/null +++ b/setup.py @@ -0,0 +1,29 @@ +from setuptools import setup + +setup( + name="bundlewrap-pass", + version="0.0.1", + description="Get passwordstore entries via bundlewrap", + author="Franziska Kunsmann", + author_email="hi@kunsmann.eu", + license="GPLv3", + py_modules=['bwpass'], + keywords=["configuration", "config", "management"], + classifiers=[ +# "Development Status :: 5 - Production/Stable", + "Intended Audience :: System Administrators", + "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", + "Natural Language :: English", + "Operating System :: POSIX :: Linux", + "Programming Language :: Python", + "Programming Language :: Python :: 3.6", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Topic :: Software Development :: Libraries :: Python Modules", + "Topic :: System :: Installation/Setup", + "Topic :: System :: Systems Administration", + ], + install_requires=[ + "bundlewrap >= 4.0.0", + ], +)