diff --git a/bwpass.py b/bwpass.py index 9f04150..28cd98c 100644 --- a/bwpass.py +++ b/bwpass.py @@ -4,12 +4,12 @@ from subprocess import check_output, CalledProcessError from bundlewrap.exceptions import FaultUnavailable from bundlewrap.utils import Fault -from bundlewrap.utils.dict import merge_dict +from bundlewrap.utils.dicts import merge_dict from bundlewrap.utils.text import bold, yellow from bundlewrap.utils.ui import io ENVIRONMENT = merge_dict(environ, { - 'PASSWORD_STORE_DIR': expanduser(environ.get('BW_PASS_DIR', '~/.password-store')). + 'PASSWORD_STORE_DIR': expanduser(environ.get('BW_PASS_DIR', '~/.password-store')), }) DUMMY_MODE = environ.get('BW_PASS_DUMMY_MODE', '0') == '1' @@ -41,10 +41,21 @@ def _get_contents_from_pass(identifier: str): identifier, )) - cache[identifier] = {} - cache[identifier]['password'] = pass_output[0] + if not pass_output: + raise ValueError('BUG: `pass show {}` did not return any output!'.format( + identifier + )) - # TODO import all other options set in pass + cache[identifier] = { + 'password': pass_output[0].strip(), + 'attrs': {}, + } + + if len(pass_output) > 1: + for line in pass_output[1:]: + attr, value = line.split(':', 1) + + cache[identifier]['attrs'][attr] = value.strip() return cache[identifier] @@ -63,3 +74,26 @@ def password(identifier): _password, identifier=identifier, ) + + +def _attr(identifier, attr): + if DUMMY_MODE: + return 'PASS DUMMY {} ATTRIBUTE'.format(attr) + else: + secret = _get_contents_from_pass(identifier) + try: + return secret['attrs'][attr] + except KeyError: + raise FaultUnavailable('attribute {} not found for identifier {}'.format( + attr, + identifier, + )) + + +def attr(identifier, attr): + return Fault( + 'bwpass attribute {}'.format(attr), + _attr, + identifier=identifier, + attr=attr, + ) diff --git a/setup.py b/setup.py index 13ce1a2..ed7dc63 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup setup( name="bundlewrap-pass", - version="0.0.1", + version="1.0.0", description="Get passwordstore entries via bundlewrap", author="Franziska Kunsmann", author_email="hi@kunsmann.eu", @@ -10,7 +10,7 @@ setup( py_modules=['bwpass'], keywords=["configuration", "config", "management"], classifiers=[ -# "Development Status :: 5 - Production/Stable", + "Development Status :: 5 - Production/Stable", "Intended Audience :: System Administrators", "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", "Natural Language :: English",