1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Fix path detection for gopass (#4955)

* Fix path detection for gopass

As per fc8c9a2286/docs/features.md (initializing-a-password-store), gopass defaults to ~/.local/share/gopass/stores/root for its password store root location.

However, the user can also override this, and this will be stored in the gopass config file (ed7451678c/docs/config.md (configuration-options)).

This patch ensures that the config setting in gopass is respected, falling back to the default gopass path. pass' behaviour remains unchanged.

* Formatting improvements

Co-authored-by: Felix Fontein <felix@fontein.de>

* Add changelog fragment

* Formatting improvement

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>

Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
Sylvia van Os 2022-07-21 07:19:31 +02:00 committed by GitHub
parent be70d18e3f
commit c31e6413f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 5 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- passwordstore - fix password store path detection for gopass (https://github.com/ansible-collections/community.general/pull/4955).

View file

@ -21,8 +21,14 @@ DOCUMENTATION = '''
description: query key. description: query key.
required: True required: True
passwordstore: passwordstore:
description: location of the password store. description:
default: '~/.password-store' - Location of the password store.
- 'The value is decided by checking the following in order:'
- If set, this value is used.
- If C(directory) is set, that value will be used.
- If I(backend=pass), then C(~/.password-store) is used.
- If I(backend=gopass), then the C(path) field in C(~/.config/gopass/config.yml) is used,
falling back to C(~/.local/share/gopass/stores/root) if not defined.
directory: directory:
description: The directory of the password store. description: The directory of the password store.
env: env:
@ -428,11 +434,22 @@ class LookupModule(LookupBase):
raise AnsibleError("{0} is not a correct value for locktimeout".format(timeout)) raise AnsibleError("{0} is not a correct value for locktimeout".format(timeout))
unit_to_seconds = {"s": 1, "m": 60, "h": 3600} unit_to_seconds = {"s": 1, "m": 60, "h": 3600}
self.lock_timeout = int(timeout[:-1]) * unit_to_seconds[timeout[-1]] self.lock_timeout = int(timeout[:-1]) * unit_to_seconds[timeout[-1]]
directory = variables.get('passwordstore', os.environ.get('PASSWORD_STORE_DIR', None))
if directory is None:
if self.backend == 'gopass':
try:
with open(os.path.expanduser('~/.config/gopass/config.yml')) as f:
directory = yaml.safe_load(f)['path']
except (FileNotFoundError, KeyError, yaml.YAMLError):
directory = os.path.expanduser('~/.local/share/gopass/stores/root')
else:
directory = os.path.expanduser('~/.password-store')
self.paramvals = { self.paramvals = {
'subkey': 'password', 'subkey': 'password',
'directory': variables.get('passwordstore', os.environ.get( 'directory': directory,
'PASSWORD_STORE_DIR',
os.path.expanduser('~/.password-store'))),
'create': False, 'create': False,
'returnall': False, 'returnall': False,
'overwrite': False, 'overwrite': False,