initial commit

This commit is contained in:
Franzi 2021-02-14 11:30:44 +01:00
commit 428030c3bc
Signed by: kunsi
GPG key ID: 12E3D2136B818350
2 changed files with 91 additions and 0 deletions

62
bwpass.py Normal file
View file

@ -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,
)

29
setup.py Normal file
View file

@ -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",
],
)