From 7bfce168a35fc4419978fd3c5c7aa35d95687ccd Mon Sep 17 00:00:00 2001 From: Mark Horninger <13180040+spam-n-eggs@users.noreply.github.com> Date: Sun, 10 Mar 2024 22:42:34 -0400 Subject: [PATCH] Mjh/fix issues with message (#24) * Fix the ansible error * Rolled version * made the wrapping of the error more pythonic * Fixed exception handling a little more * Fixed exception handling a little more * Fixed exception handling a little more * Wrapping just the message? * Moving over to a regular old exception * Wrapping just the message * Forget about wrapping the error * Forget about wrapping the error * Forget about wrapping the error * Fixing error detections * Fixed sanity test issues --- galaxy.yml | 2 +- plugins/inventory/netbird.py | 12 ++++-------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/galaxy.yml b/galaxy.yml index a36ae81..a29a826 100644 --- a/galaxy.yml +++ b/galaxy.yml @@ -8,7 +8,7 @@ namespace: dominion_solutions name: netbird # The version of the collection. Must be compatible with semantic versioning -version: 0.1.5 +version: 0.1.6 # The path to the Markdown (.md) readme file. This path is relative to the root of the collection readme: README.md diff --git a/plugins/inventory/netbird.py b/plugins/inventory/netbird.py index 3eead23..0534119 100644 --- a/plugins/inventory/netbird.py +++ b/plugins/inventory/netbird.py @@ -93,7 +93,6 @@ from ansible.utils.display import Display # Specific for the NetbirdAPI Class import json -import re try: import requests @@ -151,8 +150,8 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable): """Get the inventory from the Netbird API""" try: self.peers = self.client.ListPeers() - except Exception as e: - raise AnsibleError(f"Could not retrieve the Netbird inventory: {e}") + except Exception: + raise AnsibleError("Could not retrieve the Netbird inventory. Check the API Key and URL.") def _filter_by_config(self): """Filter peers by user specified configuration.""" @@ -290,11 +289,8 @@ class NetbirdApi: } peers = [] response = requests.request("GET", url, headers=headers) - if response.status_code in [401]: - raise ConnectionRefusedError(f"{response.status_code}: {response.text}\nPlease check the API Key and URL.") - - elif re.match('4\\d\\d', response.status_code): - raise ConnectionError(f"{response.status_code}: {response.text}\nPlease check the API Key and URL.") + if response.status_code in [401, 404]: + raise Exception(f"{response.status_code}: {response.text}\nPlease check the API Key and URL.") peer_json = json.loads(response.text) for current_peer_map in peer_json: