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

Ops 6558 improve 1password lookup #98

Merged
merged 5 commits into from
Sep 12, 2024
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: 1 addition & 1 deletion onepwd/galaxy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace: dbildungscloud
name: onepwd

# The version of the collection. Must be compatible with semantic versioning
version: 2.4.0
version: 2.5.0

# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
readme: README.md
Expand Down
14 changes: 13 additions & 1 deletion onepwd/plugins/lookup/onepwd.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ def run(self, terms, variables=None, **kwargs):
secret_name=kwargs.get('secret_name', '')
vault=kwargs.get('vault', None)
field=kwargs.get('field', None)
ignore_not_found=kwargs.get('ignore_not_found', False)
values=[]
values.append(onepwd.get_single_secret(op, secret_name, field=field, vault=vault))
try:
values.append(onepwd.get_single_secret(op, secret_name, field=field, vault=vault))
except onepwd.UnauthorizedError:
raise AnsibleError("Unauthorized")
except onepwd.DuplicateItemsError:
raise AnsibleError(f"More than one item named {secret_name} in vault {vault}")
except onepwd.UnknownResourceItem:
if ignore_not_found:
return []
raise AnsibleError(f"No item named {secret_name} in vault {vault}")
except onepwd.UnknownError as unknown_error:
raise AnsibleError(unknown_error)
return values
2 changes: 1 addition & 1 deletion onepwd/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="onepwd",
version="2.2.1",
version="2.5.0",
author="HPI Schulcloud",
author_email="devops@dbildungscloud.de",
description="Utilities to work with 1password",
Expand Down
12 changes: 3 additions & 9 deletions onepwd/src/onepwd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def __init__(self, item_name, vault):
self.message = message


class UnauthorizedErrorError(Exception):
class UnauthorizedError(Exception):
pass


Expand Down Expand Up @@ -181,17 +181,11 @@ def delete_item(self, item_name, vault=None):
def get(self, resource, item_name, vault=None):
vault_flag = get_optional_flag(vault=vault)
op_command = f"{self.op} {resource} get '{item_name}' {vault_flag} --session={self.session_token}"
try:
return json.loads(run_op_command_in_shell(op_command))
except subprocess.CalledProcessError:
raise UnknownResourceItem(f"{resource}: {item_name}")
return json.loads(run_op_command_in_shell(op_command))

def get_document(self, item_name):
op_command = f"{self.op} document get '{item_name}' --session={self.session_token}"
try:
return run_op_command_in_shell(op_command)
except subprocess.CalledProcessError:
raise UnknownResourceItem(f"document: {item_name}")
return run_op_command_in_shell(op_command)

def create_document_from_file(self, path, title, vault=None):
vault_flag = get_optional_flag(vault=vault)
Expand Down