onepassword_doc: fix 1Password Connect support (#9625)
Fix 1Password Connect support for onepassword_doc.pull/9722/head
parent
1f92a69992
commit
4e0de41a85
|
@ -0,0 +1,2 @@
|
|||
bugfixes:
|
||||
- "onepassword_doc lookup plugin - ensure that 1Password Connect support also works for this plugin (https://github.com/ansible-collections/community.general/pull/9625)."
|
|
@ -553,9 +553,7 @@ class OnePassCLIv2(OnePassCLIBase):
|
|||
environment_update = {"OP_SECRET_KEY": self.secret_key}
|
||||
return self._run(args, command_input=to_bytes(self.master_password), environment_update=environment_update)
|
||||
|
||||
def get_raw(self, item_id, vault=None, token=None):
|
||||
args = ["item", "get", item_id, "--format", "json"]
|
||||
|
||||
def _add_parameters_and_run(self, args, vault=None, token=None):
|
||||
if self.account_id:
|
||||
args.extend(["--account", self.account_id])
|
||||
|
||||
|
@ -582,6 +580,10 @@ class OnePassCLIv2(OnePassCLIBase):
|
|||
|
||||
return self._run(args)
|
||||
|
||||
def get_raw(self, item_id, vault=None, token=None):
|
||||
args = ["item", "get", item_id, "--format", "json"]
|
||||
return self._add_parameters_and_run(args, vault=vault, token=token)
|
||||
|
||||
def signin(self):
|
||||
self._check_required_params(['master_password'])
|
||||
|
||||
|
|
|
@ -46,28 +46,13 @@ RETURN = """
|
|||
"""
|
||||
|
||||
from ansible_collections.community.general.plugins.lookup.onepassword import OnePass, OnePassCLIv2
|
||||
from ansible.errors import AnsibleLookupError
|
||||
from ansible.module_utils.common.text.converters import to_bytes
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
|
||||
|
||||
class OnePassCLIv2Doc(OnePassCLIv2):
|
||||
def get_raw(self, item_id, vault=None, token=None):
|
||||
args = ["document", "get", item_id]
|
||||
if vault is not None:
|
||||
args = [*args, f"--vault={vault}"]
|
||||
|
||||
if self.service_account_token:
|
||||
if vault is None:
|
||||
raise AnsibleLookupError("'vault' is required with 'service_account_token'")
|
||||
|
||||
environment_update = {"OP_SERVICE_ACCOUNT_TOKEN": self.service_account_token}
|
||||
return self._run(args, environment_update=environment_update)
|
||||
|
||||
if token is not None:
|
||||
args = [*args, to_bytes("--session=") + token]
|
||||
|
||||
return self._run(args)
|
||||
return self._add_parameters_and_run(args, vault=vault, token=token)
|
||||
|
||||
|
||||
class LookupModule(LookupBase):
|
||||
|
|
Loading…
Reference in New Issue