Mjh/14/error out on bad credentials (#23)
* Testing * Added a fixture that I was prevoiusly missing * Wrapped as an AnsibleException * Rolled Version Number * Going for the tri-fecta. Fixing #20, too
This commit is contained in:
parent
c9ef2888f5
commit
b16c650525
|
|
@ -28,23 +28,23 @@ body:
|
|||
attributes:
|
||||
label: Package Version
|
||||
description: What version of our Package are you running? Please be as specific as possible
|
||||
placeholder: 2.0.0
|
||||
placeholder: 0.1.5
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
id: php-version
|
||||
id: python-version
|
||||
attributes:
|
||||
label: PHP Version
|
||||
description: What version of PHP are you running? Please be as specific as possible
|
||||
placeholder: 8.2.0
|
||||
label: Python Version
|
||||
description: What version of Python are you running? Please be as specific as possible
|
||||
placeholder: 3.10.12
|
||||
validations:
|
||||
required: true
|
||||
- type: input
|
||||
id: laravel-version
|
||||
id: ansible-version
|
||||
attributes:
|
||||
label: Laravel Version
|
||||
label: Ansible Version
|
||||
description: What version of Laravel are you running? Please be as specific as possible
|
||||
placeholder: 9.0.0
|
||||
placeholder: 2.16.4
|
||||
validations:
|
||||
required: true
|
||||
- type: dropdown
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ namespace: dominion_solutions
|
|||
name: netbird
|
||||
|
||||
# The version of the collection. Must be compatible with semantic versioning
|
||||
version: 0.1.4
|
||||
version: 0.1.5
|
||||
|
||||
# The path to the Markdown (.md) readme file. This path is relative to the root of the collection
|
||||
readme: README.md
|
||||
|
|
|
|||
|
|
@ -93,6 +93,7 @@ from ansible.utils.display import Display
|
|||
|
||||
# Specific for the NetbirdAPI Class
|
||||
import json
|
||||
import re
|
||||
|
||||
try:
|
||||
import requests
|
||||
|
|
@ -148,7 +149,10 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
|||
|
||||
def _get_peer_inventory(self):
|
||||
"""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}")
|
||||
|
||||
def _filter_by_config(self):
|
||||
"""Filter peers by user specified configuration."""
|
||||
|
|
@ -286,6 +290,12 @@ 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.")
|
||||
|
||||
peer_json = json.loads(response.text)
|
||||
for current_peer_map in peer_json:
|
||||
current_peer = Peer(current_peer_map["hostname"], current_peer_map['dns_label'], current_peer_map["id"], current_peer_map)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,13 @@
|
|||
---
|
||||
plugin: dominion_solutions.netbird.netbird
|
||||
api_key: nbp_this_is_a_fake_api_key
|
||||
api_url: https://netbird.example.com/api/v1
|
||||
ip_style: plain
|
||||
strict: No
|
||||
netbird_connected: No
|
||||
netbird_groups:
|
||||
groups:
|
||||
keyed_groups:
|
||||
compose:
|
||||
ansible_ssh_host: ip
|
||||
ansible_ssh_port: 22
|
||||
|
|
@ -9,3 +9,4 @@ groups:
|
|||
strict: No
|
||||
keyed_groups:
|
||||
compose:
|
||||
ansible_ssh_host: ip
|
||||
|
|
|
|||
|
|
@ -111,3 +111,29 @@ def test_with_multiple_groups(inventory, netbird_api_multigroup):
|
|||
assert inventory.inventory.groups is not None
|
||||
assert 'All' in inventory.inventory.groups
|
||||
assert 'Development' in inventory.inventory.groups
|
||||
|
||||
|
||||
def test_with_multiple_groups(inventory, netbird_api_multigroup):
|
||||
loader = DataLoader()
|
||||
path = 'tests/unit/module_utils/inventories/fixtures/only_connected.netbird.yml'
|
||||
inventory._build_client = MagicMock()
|
||||
inventory.client = netbird_api_multigroup
|
||||
inventory.parse(InventoryData(), loader, path, False)
|
||||
assert inventory.inventory is not None
|
||||
assert inventory.inventory.hosts is not None
|
||||
assert inventory.inventory.groups is not None
|
||||
assert 'All' in inventory.inventory.groups
|
||||
assert 'Development' in inventory.inventory.groups
|
||||
|
||||
|
||||
def test_use_ip_address(inventory, netbird_api_multigroup):
|
||||
loader = DataLoader()
|
||||
path = 'tests/unit/module_utils/inventories/fixtures/ip_address.netbird.yml'
|
||||
inventory._build_client = MagicMock()
|
||||
inventory.client = netbird_api_multigroup
|
||||
inventory.parse(InventoryData(), loader, path, False)
|
||||
assert inventory.inventory is not None
|
||||
assert inventory.inventory.hosts is not None
|
||||
assert inventory.inventory.groups is not None
|
||||
assert 'All' in inventory.inventory.groups
|
||||
assert 'Development' in inventory.inventory.groups
|
||||
|
|
|
|||
Loading…
Reference in New Issue