Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onepassword_doc: fix 1Password Connect support #9625

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragments/9625-onepassword_doc.yml
Original file line number Diff line number Diff line change
@@ -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)."
8 changes: 5 additions & 3 deletions plugins/lookup/onepassword.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,9 +553,7 @@ def full_signin(self):
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])

Expand All @@ -582,6 +580,10 @@ def get_raw(self, item_id, vault=None, token=None):

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)
Copy link
Contributor

@samdoran samdoran Jan 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another approach could be moving this to a new _run() method on the OnePassCLIv2 class.


def signin(self):
self._check_required_params(['master_password'])

Expand Down
17 changes: 1 addition & 16 deletions plugins/lookup/onepassword_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,13 @@
"""

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):
Expand Down
Loading