Skip to content

Commit 7bfce16

Browse files
authored
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
1 parent b5c798e commit 7bfce16

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

galaxy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace: dominion_solutions
88
name: netbird
99

1010
# The version of the collection. Must be compatible with semantic versioning
11-
version: 0.1.5
11+
version: 0.1.6
1212

1313
# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
1414
readme: README.md

plugins/inventory/netbird.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@
9393

9494
# Specific for the NetbirdAPI Class
9595
import json
96-
import re
9796

9897
try:
9998
import requests
@@ -151,8 +150,8 @@ def _get_peer_inventory(self):
151150
"""Get the inventory from the Netbird API"""
152151
try:
153152
self.peers = self.client.ListPeers()
154-
except Exception as e:
155-
raise AnsibleError(f"Could not retrieve the Netbird inventory: {e}")
153+
except Exception:
154+
raise AnsibleError("Could not retrieve the Netbird inventory. Check the API Key and URL.")
156155

157156
def _filter_by_config(self):
158157
"""Filter peers by user specified configuration."""
@@ -290,11 +289,8 @@ def ListPeers(self):
290289
}
291290
peers = []
292291
response = requests.request("GET", url, headers=headers)
293-
if response.status_code in [401]:
294-
raise ConnectionRefusedError(f"{response.status_code}: {response.text}\nPlease check the API Key and URL.")
295-
296-
elif re.match('4\\d\\d', response.status_code):
297-
raise ConnectionError(f"{response.status_code}: {response.text}\nPlease check the API Key and URL.")
292+
if response.status_code in [401, 404]:
293+
raise Exception(f"{response.status_code}: {response.text}\nPlease check the API Key and URL.")
298294

299295
peer_json = json.loads(response.text)
300296
for current_peer_map in peer_json:

0 commit comments

Comments
 (0)