diff --git a/onepwd/galaxy.yml b/onepwd/galaxy.yml index 2209b76..1824e1d 100644 --- a/onepwd/galaxy.yml +++ b/onepwd/galaxy.yml @@ -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 diff --git a/onepwd/plugins/lookup/onepwd.py b/onepwd/plugins/lookup/onepwd.py index 111a500..9f23c74 100644 --- a/onepwd/plugins/lookup/onepwd.py +++ b/onepwd/plugins/lookup/onepwd.py @@ -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 diff --git a/onepwd/setup.py b/onepwd/setup.py index ceab77b..bef15ff 100644 --- a/onepwd/setup.py +++ b/onepwd/setup.py @@ -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", diff --git a/onepwd/src/onepwd/__init__.py b/onepwd/src/onepwd/__init__.py index 7002f7d..ac9392c 100644 --- a/onepwd/src/onepwd/__init__.py +++ b/onepwd/src/onepwd/__init__.py @@ -22,7 +22,7 @@ def __init__(self, item_name, vault): self.message = message -class UnauthorizedErrorError(Exception): +class UnauthorizedError(Exception): pass @@ -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)