|
21 | 21 | DOCUMENTATION = """ |
22 | 22 | lookup: keepass |
23 | 23 | author: Victor Zemtsov <viczem.dev@gmail.com> |
24 | | - version_added: '0.6.0' |
| 24 | + version_added: '0.7.1' |
25 | 25 | short_description: Fetching data from KeePass file |
26 | 26 | description: |
27 | 27 | - This lookup returns a value of a property of a KeePass entry |
@@ -76,10 +76,11 @@ def run(self, terms, variables=None, **kwargs): |
76 | 76 | if not os.path.isfile(var_key): |
77 | 77 | raise AnsibleError("KeePass: '%s' is not found" % var_key) |
78 | 78 |
|
79 | | - # Check password (required) |
| 79 | + # Check password (optional) |
80 | 80 | var_psw = self._var(variables_.get("keepass_psw", "")) |
81 | | - if not var_psw: |
82 | | - raise AnsibleError("KeePass: 'keepass_psw' is not set") |
| 81 | + |
| 82 | + if not var_key and not var_psw: |
| 83 | + raise AnsibleError("KeePass: 'keepass_psw' and/or 'keepass_key' is not set") |
83 | 84 |
|
84 | 85 | # TTL of keepass socket (optional, default: 60 seconds) |
85 | 86 | var_ttl = self._var(str(variables_.get("keepass_ttl", "60"))) |
@@ -121,7 +122,6 @@ def run(self, terms, variables=None, **kwargs): |
121 | 122 | if resp[1] == "0": |
122 | 123 | success = True |
123 | 124 | else: |
124 | | - sock.send(_rq("close")) |
125 | 125 | raise AnsibleError("KeePass: wrong dbx password") |
126 | 126 | sock.close() |
127 | 127 | break |
@@ -229,13 +229,14 @@ def _keepass_socket(kdbx, kdbx_key, sock_path, ttl=60, kdbx_password=None): |
229 | 229 |
|
230 | 230 | # CMD: password |
231 | 231 | if kp is None: |
232 | | - if arg_len == 0: |
233 | | - conn.send(_resp("password", 1)) |
234 | | - break |
235 | | - if cmd == "password" and arg[0]: |
| 232 | + if cmd == "password" and arg_len > 0: |
236 | 233 | kp = PyKeePass(kdbx, arg[0], kdbx_key) |
237 | 234 | conn.send(_resp("password", 0)) |
238 | 235 | break |
| 236 | + elif cmd == "password" and kdbx_key: |
| 237 | + kp = PyKeePass(kdbx, None, kdbx_key) |
| 238 | + conn.send(_resp("password", 0)) |
| 239 | + break |
239 | 240 | else: |
240 | 241 | conn.send(_resp("password", 1)) |
241 | 242 | break |
|
0 commit comments