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: