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
This commit is contained in:
parent
b5c798ea0e
commit
7bfce168a3
|
|
@ -8,7 +8,7 @@ namespace: dominion_solutions
|
||||||
name: netbird
|
name: netbird
|
||||||
|
|
||||||
# The version of the collection. Must be compatible with semantic versioning
|
# 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
|
# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
|
||||||
readme: README.md
|
readme: README.md
|
||||||
|
|
|
||||||
|
|
@ -93,7 +93,6 @@ from ansible.utils.display import Display
|
||||||
|
|
||||||
# Specific for the NetbirdAPI Class
|
# Specific for the NetbirdAPI Class
|
||||||
import json
|
import json
|
||||||
import re
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import requests
|
import requests
|
||||||
|
|
@ -151,8 +150,8 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
||||||
"""Get the inventory from the Netbird API"""
|
"""Get the inventory from the Netbird API"""
|
||||||
try:
|
try:
|
||||||
self.peers = self.client.ListPeers()
|
self.peers = self.client.ListPeers()
|
||||||
except Exception as e:
|
except Exception:
|
||||||
raise AnsibleError(f"Could not retrieve the Netbird inventory: {e}")
|
raise AnsibleError("Could not retrieve the Netbird inventory. Check the API Key and URL.")
|
||||||
|
|
||||||
def _filter_by_config(self):
|
def _filter_by_config(self):
|
||||||
"""Filter peers by user specified configuration."""
|
"""Filter peers by user specified configuration."""
|
||||||
|
|
@ -290,11 +289,8 @@ class NetbirdApi:
|
||||||
}
|
}
|
||||||
peers = []
|
peers = []
|
||||||
response = requests.request("GET", url, headers=headers)
|
response = requests.request("GET", url, headers=headers)
|
||||||
if response.status_code in [401]:
|
if response.status_code in [401, 404]:
|
||||||
raise ConnectionRefusedError(f"{response.status_code}: {response.text}\nPlease check the API Key and URL.")
|
raise Exception(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.")
|
|
||||||
|
|
||||||
peer_json = json.loads(response.text)
|
peer_json = json.loads(response.text)
|
||||||
for current_peer_map in peer_json:
|
for current_peer_map in peer_json:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue