From 0331798f84dc7ee7b628e35a7fcff637b760d6b5 Mon Sep 17 00:00:00 2001 From: "patchback[bot]" <45432694+patchback[bot]@users.noreply.github.com> Date: Mon, 27 Jan 2025 07:27:43 +0100 Subject: [PATCH] [PR #9633/8749da77 backport][stable-10] onepassword_ssh_key: avoid inheriting from OnePassCLIv2 (#9639) onepassword_ssh_key: avoid inheriting from OnePassCLIv2 (#9633) * Avoid inheriting from OnePassCLIv2. * Add changelog fragment. (cherry picked from commit 8749da775684127ae8ec13c65afe94da666d5fd1) Co-authored-by: Felix Fontein --- changelogs/fragments/9633-onepassword_ssh_key.yml | 2 ++ plugins/lookup/onepassword_ssh_key.py | 13 ++++--------- 2 files changed, 6 insertions(+), 9 deletions(-) create mode 100644 changelogs/fragments/9633-onepassword_ssh_key.yml diff --git a/changelogs/fragments/9633-onepassword_ssh_key.yml b/changelogs/fragments/9633-onepassword_ssh_key.yml new file mode 100644 index 0000000000..bd4676319e --- /dev/null +++ b/changelogs/fragments/9633-onepassword_ssh_key.yml @@ -0,0 +1,2 @@ +minor_changes: + - "onepassword_ssh_key - refactor to move code to lookup class (https://github.com/ansible-collections/community.general/pull/9633)." diff --git a/plugins/lookup/onepassword_ssh_key.py b/plugins/lookup/onepassword_ssh_key.py index a352e7270e..253d8c68f4 100644 --- a/plugins/lookup/onepassword_ssh_key.py +++ b/plugins/lookup/onepassword_ssh_key.py @@ -58,11 +58,8 @@ from ansible.errors import AnsibleLookupError from ansible.plugins.lookup import LookupBase -class OnePassCLIv2SSHKey(OnePassCLIv2): - - def get_ssh_key(self, item_id, vault=None, token=None, ssh_format=False): - rc, out, err = self.get_raw(item_id, vault=vault, token=token) - +class LookupModule(LookupBase): + def get_ssh_key(self, out, item_id, ssh_format=False): data = json.loads(out) if data.get("category") != "SSH_KEY": @@ -87,8 +84,6 @@ class OnePassCLIv2SSHKey(OnePassCLIv2): ) return private_key_field.get("value", "") - -class LookupModule(LookupBase): def run(self, terms, variables=None, **kwargs): self.set_options(var_options=variables, direct=kwargs) @@ -114,11 +109,11 @@ class LookupModule(LookupBase): account_id=account_id, connect_host=connect_host, connect_token=connect_token, - cli_class=OnePassCLIv2SSHKey, + cli_class=OnePassCLIv2, ) op.assert_logged_in() return [ - op._cli.get_ssh_key(term, vault, token=op.token, ssh_format=ssh_format) + self.get_ssh_key(op.get_raw(term, vault), term, ssh_format=ssh_format) for term in terms ]