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

[PR #9633/8749da77 backport][stable-10] onepassword_ssh_key: avoid inheriting from OnePassCLIv2 #9639

Merged
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/9633-onepassword_ssh_key.yml
Original file line number Diff line number Diff line change
@@ -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)."
13 changes: 4 additions & 9 deletions plugins/lookup/onepassword_ssh_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,8 @@
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":
Expand All @@ -87,8 +84,6 @@ def get_ssh_key(self, item_id, vault=None, token=None, ssh_format=False):
)
return private_key_field.get("value", "")


class LookupModule(LookupBase):
def run(self, terms, variables=None, **kwargs):
self.set_options(var_options=variables, direct=kwargs)

Expand All @@ -114,11 +109,11 @@ def run(self, terms, variables=None, **kwargs):
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
]
Loading