Fixed issues with the groups list comprehension (#8)
This commit is contained in:
parent
8357f52f89
commit
d63c53574c
|
|
@ -0,0 +1,66 @@
|
||||||
|
name: Bug Report
|
||||||
|
description: Report an Issue or Bug with the Package
|
||||||
|
title: "[Bug]: "
|
||||||
|
labels: ["bug"]
|
||||||
|
body:
|
||||||
|
- type: markdown
|
||||||
|
attributes:
|
||||||
|
value: |
|
||||||
|
We're sorry to hear you have a problem. Can you help us solve it by providing the following details.
|
||||||
|
- type: textarea
|
||||||
|
id: what-happened
|
||||||
|
attributes:
|
||||||
|
label: What happened?
|
||||||
|
description: What did you expect to happen?
|
||||||
|
placeholder: I cannot currently do X thing because when I do, it breaks X thing.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: textarea
|
||||||
|
id: how-to-reproduce
|
||||||
|
attributes:
|
||||||
|
label: How to reproduce the bug
|
||||||
|
description: How did this occur, please add any config values used and provide a set of reliable steps if possible.
|
||||||
|
placeholder: When I do X I see Y.
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: input
|
||||||
|
id: package-version
|
||||||
|
attributes:
|
||||||
|
label: Package Version
|
||||||
|
description: What version of our Package are you running? Please be as specific as possible
|
||||||
|
placeholder: 2.0.0
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: input
|
||||||
|
id: php-version
|
||||||
|
attributes:
|
||||||
|
label: PHP Version
|
||||||
|
description: What version of PHP are you running? Please be as specific as possible
|
||||||
|
placeholder: 8.2.0
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: input
|
||||||
|
id: laravel-version
|
||||||
|
attributes:
|
||||||
|
label: Laravel Version
|
||||||
|
description: What version of Laravel are you running? Please be as specific as possible
|
||||||
|
placeholder: 9.0.0
|
||||||
|
validations:
|
||||||
|
required: true
|
||||||
|
- type: dropdown
|
||||||
|
id: operating-systems
|
||||||
|
attributes:
|
||||||
|
label: Which operating systems does with happen with?
|
||||||
|
description: You may select more than one.
|
||||||
|
multiple: true
|
||||||
|
options:
|
||||||
|
- macOS
|
||||||
|
- Windows
|
||||||
|
- Linux
|
||||||
|
- type: textarea
|
||||||
|
id: notes
|
||||||
|
attributes:
|
||||||
|
label: Notes
|
||||||
|
description: Use this field to provide any other notes that you feel might be relevant to the issue.
|
||||||
|
validations:
|
||||||
|
required: false
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
blank_issues_enabled: false
|
||||||
|
contact_links:
|
||||||
|
- name: Ask a question
|
||||||
|
url: https://github.com/dominion-solutions/ansible-netbird-role/discussions/new?category=q-a
|
||||||
|
about: Ask the community for help
|
||||||
|
- name: Request a feature
|
||||||
|
url: https://github.com/dominion-solutions/ansible-netbird-role/discussions/new?category=ideas
|
||||||
|
about: Share ideas for new features
|
||||||
|
- name: Report a security issue
|
||||||
|
url: https://github.com/dominion-solutions/ansible-netbird-role/security/policy
|
||||||
|
about: Learn how to notify us for sensitive bugs
|
||||||
|
|
@ -0,0 +1,48 @@
|
||||||
|
# Security Policy
|
||||||
|
|
||||||
|
If you discover any security related issues, please email compliance@dominion.solutions instead of using the issue tracker.
|
||||||
|
Please encrypt messages using our PGP Key below:
|
||||||
|
```
|
||||||
|
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||||
|
|
||||||
|
mQGNBGXZ4joBDADKC9XF05nU53n5EXE0JM0G2FrhZaPEpzJ47CFcOyvx3eHTOfwN
|
||||||
|
Z+Rtjgcugk66VNdj/fkwPpjj+Yj1ISchGDhOCXVlNnwiRdknGJ8uHZXlVYuPsVSF
|
||||||
|
voocOthFuRgM8CighScO4uPybHZUa4VwQ2+B48WFa/3FszLf6YlDWoBwljE3KVZD
|
||||||
|
WgTy/VvXx3Momwk+cher6W2eA8SuJEuixeX9mx7iu5kCjcvPBmvnDTfQS9zjKCuD
|
||||||
|
ymwJg9h+paFFcx+ObmdOnpoG7jiB4kXENFtaAIrYR/vroODZZQUnBGvvEASXbJh6
|
||||||
|
drEQu8t14l+qqaBCeGIbp/rM875VZPH7StAKRAhYG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87Je6Ykb350onCeKr6BtzU11A6RqXvdpFQQ3MQ1lDVF8J1XiXdKWE5X/KHjKR
|
||||||
|
/5iPPc93z7ttRgcnJ5kEbHJPKMLMmMU7rTF6Af9+sxjgoolPTMzcjyek1ilVKdKv
|
||||||
|
wNGl4zykRU8x8Qs=
|
||||||
|
=9AAX
|
||||||
|
-----END PGP PUBLIC KEY BLOCK-----
|
||||||
|
```
|
||||||
|
|
@ -15,6 +15,7 @@ jobs:
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
ref: main
|
ref: main
|
||||||
|
token: ${{ secrets.DEVOPS_BOT_PAT }}
|
||||||
|
|
||||||
- name: Update Changelog
|
- name: Update Changelog
|
||||||
uses: stefanzweifel/changelog-updater-action@v1
|
uses: stefanzweifel/changelog-updater-action@v1
|
||||||
|
|
@ -28,3 +29,4 @@ jobs:
|
||||||
branch: main
|
branch: main
|
||||||
commit_message: Update CHANGELOG
|
commit_message: Update CHANGELOG
|
||||||
file_pattern: CHANGELOG.md
|
file_pattern: CHANGELOG.md
|
||||||
|
push_options: --force
|
||||||
|
|
|
||||||
|
|
@ -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.1
|
version: 0.1.2
|
||||||
|
|
||||||
# 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
|
||||||
|
|
|
||||||
|
|
@ -106,7 +106,9 @@ display = Display()
|
||||||
|
|
||||||
class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
||||||
NAME = "dominion_solutions.netbird.netbird"
|
NAME = "dominion_solutions.netbird.netbird"
|
||||||
_load_name = NAME
|
|
||||||
|
def _cacheable_inventory(self):
|
||||||
|
return [p._raw_json for p in self.peers]
|
||||||
|
|
||||||
def _build_client(self, loader):
|
def _build_client(self, loader):
|
||||||
"""Build the Netbird API Client"""
|
"""Build the Netbird API Client"""
|
||||||
|
|
@ -129,7 +131,12 @@ class InventoryModule(BaseInventoryPlugin, Constructable, Cacheable):
|
||||||
def _add_groups(self):
|
def _add_groups(self):
|
||||||
""" Add peer groups to the inventory. """
|
""" Add peer groups to the inventory. """
|
||||||
self.netbird_groups = set(
|
self.netbird_groups = set(
|
||||||
filter(None, [group[0].get('name') for group in [item.data.get('groups') for l in self.peers for item in self.peers]]))
|
filter(None, [
|
||||||
|
group.get('name') for peer
|
||||||
|
in self.peers
|
||||||
|
for group in
|
||||||
|
peer.data.get('groups')
|
||||||
|
]))
|
||||||
for group in self.netbird_groups:
|
for group in self.netbird_groups:
|
||||||
self.inventory.add_group(group)
|
self.inventory.add_group(group)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
---
|
||||||
|
plugin: dominion_solutions.netbird.netbird
|
||||||
|
api_url: https://api.netbird.io/api/
|
||||||
|
api_key: nbp_this_is_a_fake_api_key
|
||||||
|
netbird_groups:
|
||||||
|
- Development
|
||||||
|
ip_style: plain
|
||||||
|
groups:
|
||||||
|
strict: No
|
||||||
|
keyed_groups:
|
||||||
|
compose:
|
||||||
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"message": "token invalid",
|
||||||
|
"code": 401
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
---
|
---
|
||||||
plugin: netbird
|
plugin: dominion_solutions.netbird.netbird
|
||||||
api_key: nbp_1234567890123456789012345678901234567
|
api_key: nbp_this_is_a_fake_api_key
|
||||||
api_url: https://netbird.example.com/api/v1
|
api_url: https://netbird.example.com/api/v1
|
||||||
ip_style: plain
|
ip_style: plain
|
||||||
netbird_connected: False
|
netbird_connected: False
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
---
|
---
|
||||||
plugin: netbird
|
plugin: netbird
|
||||||
api_key: nbp_1234567890123456789012345678901234567
|
api_key: nbp_this_is_a_fake_api_key
|
||||||
api_url: https://netbird.example.com/api/v1
|
api_url: https://netbird.example.com/api/v1
|
||||||
ip_style: plain
|
ip_style: plain
|
||||||
netbird_connected: True
|
netbird_connected: True
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,69 @@
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"accessible_peers_count": 1,
|
||||||
|
"approval_required": false,
|
||||||
|
"city_name": "",
|
||||||
|
"connected": false,
|
||||||
|
"connection_ip": "",
|
||||||
|
"country_code": "",
|
||||||
|
"dns_label": "apple.netbird.cloud",
|
||||||
|
"geoname_id": 0,
|
||||||
|
"groups": [
|
||||||
|
{
|
||||||
|
"id": "3aBcD4eF5gHiJ6kLmNoP",
|
||||||
|
"name": "All",
|
||||||
|
"peers_count": 2
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"hostname": "apple",
|
||||||
|
"id": "2j3k4l5m6n7o8p9q0r1",
|
||||||
|
"ip": "10.10.10.123",
|
||||||
|
"kernel_version": "",
|
||||||
|
"last_login": "2024-02-10T22:01:27.744131502Z",
|
||||||
|
"last_seen": "2024-02-11T03:21:42.202104672Z",
|
||||||
|
"login_expiration_enabled": true,
|
||||||
|
"login_expired": false,
|
||||||
|
"name": "apple",
|
||||||
|
"os": "Linux Mint 21.3",
|
||||||
|
"ssh_enabled": false,
|
||||||
|
"ui_version": "netbird-desktop-ui/0.25.7",
|
||||||
|
"user_id": "auth0|abc123xyz4567890defg",
|
||||||
|
"version": "0.25.7"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"accessible_peers_count": 1,
|
||||||
|
"approval_required": false,
|
||||||
|
"city_name": "New York",
|
||||||
|
"connected": true,
|
||||||
|
"connection_ip": "146.123.45.67",
|
||||||
|
"country_code": "US",
|
||||||
|
"dns_label": "banana.netbird.cloud",
|
||||||
|
"geoname_id": 1234567,
|
||||||
|
"groups": [
|
||||||
|
{
|
||||||
|
"id": "2j3k4l5m6n7o8p9q0r1",
|
||||||
|
"name": "Development",
|
||||||
|
"peers_count": 1
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "3aBcD4eF5gHiJ6kLmNoP",
|
||||||
|
"name": "All",
|
||||||
|
"peers_count": 2
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"hostname": "banana",
|
||||||
|
"id": "hkwJPXNUmGywCLo5S8Wg",
|
||||||
|
"ip": "10.10.10.124",
|
||||||
|
"kernel_version": "",
|
||||||
|
"last_login": "2024-02-02T11:20:05.934889112Z",
|
||||||
|
"last_seen": "2024-02-24T02:59:35.324496386Z",
|
||||||
|
"login_expiration_enabled": false,
|
||||||
|
"login_expired": false,
|
||||||
|
"name": "docker-manager",
|
||||||
|
"os": "Alpine Linux 3.19.1",
|
||||||
|
"ssh_enabled": false,
|
||||||
|
"ui_version": "",
|
||||||
|
"user_id": "",
|
||||||
|
"version": "0.25.5"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
@ -25,7 +25,7 @@ display = Display()
|
||||||
def inventory():
|
def inventory():
|
||||||
plugin = InventoryModule()
|
plugin = InventoryModule()
|
||||||
plugin.templar = Templar(loader=DataLoader())
|
plugin.templar = Templar(loader=DataLoader())
|
||||||
plugin._redirected_names = ["netbird", "dominion_solutions.netbird"]
|
plugin._redirected_names = ["netbird", "dominion_solutions.netbird.netbird"]
|
||||||
plugin._load_name = plugin.NAME
|
plugin._load_name = plugin.NAME
|
||||||
return plugin
|
return plugin
|
||||||
|
|
||||||
|
|
@ -44,6 +44,20 @@ def netbird_api():
|
||||||
return mock_netbird_api
|
return mock_netbird_api
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="module")
|
||||||
|
def netbird_api_multigroup():
|
||||||
|
mock_netbird_api = NetbirdApi(None, None)
|
||||||
|
response_data = []
|
||||||
|
with open('tests/unit/module_utils/inventories/fixtures/peers_multigroup.json') as peers_file:
|
||||||
|
peers_map = json.load(peers_file)
|
||||||
|
for data in peers_map:
|
||||||
|
response_data.append(Peer(data['hostname'], data['dns_label'], data['id'], data))
|
||||||
|
|
||||||
|
mock_netbird_api.ListPeers = MagicMock(return_value=response_data)
|
||||||
|
|
||||||
|
return mock_netbird_api
|
||||||
|
|
||||||
|
|
||||||
def test_missing_access_token_lookup(inventory):
|
def test_missing_access_token_lookup(inventory):
|
||||||
loader = DataLoader()
|
loader = DataLoader()
|
||||||
inventory._options = {'api_key': None, 'api_url': None}
|
inventory._options = {'api_key': None, 'api_url': None}
|
||||||
|
|
@ -84,3 +98,16 @@ def test_get_only_connected_peers(inventory, netbird_api):
|
||||||
assert inventory.inventory.hosts is not None
|
assert inventory.inventory.hosts is not None
|
||||||
assert len(inventory.inventory.hosts) == 1
|
assert len(inventory.inventory.hosts) == 1
|
||||||
assert list(inventory.inventory.hosts.values())[0].get_vars().get('connected') is True
|
assert list(inventory.inventory.hosts.values())[0].get_vars().get('connected') is True
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue