Skip to content

Commit

Permalink
Allow adding all host information immediately
Browse files Browse the repository at this point in the history
To add a new IP address with all necessray information to be able to
register it with the perimeter firewall, you need two separate requests
right now since add does not accept all necessary parameters:

```
❯ deterrers-cli add --admin virtUOS 192.0.0.1
❯ deterrers-cli update --profile ssh 192.0.0.1
```

This patch allows setting the firewall profile and the host firewall
directly when adding a new IP address to DETERRERS.
  • Loading branch information
lkiesow committed Apr 17, 2023
1 parent 27eee85 commit a2e337a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion deterrersapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,29 @@ def get(self, ipv4: str):
'''
return self.__get('host/', ipv4_addr=ipv4)

def add(self, ipv4: str, admins: list[str]) -> None:
def add(self, ipv4: str,
admins: list[str],
profile: None | str = None,
firewall: None | str = None) -> None:
'''Add a new IP address to DETERRERS.
:param ipv4: IPv4 address
:type ipv4: str
:param admins: List of admins for address
:type admins: list[str]
:param profile: Firewall profile to use. Must be None, a valid profile
or an empty string string (default: None)
:type profile: None | str
:param firewall: Host firewall. Must be None, one of the UI options
or an empty string (default: None)
:type firewall: None | str
'''
data = {'ipv4_addr': ipv4,
'admin_ids': admins}
if profile is not None:
data['service_profile'] = profile
if firewall is not None:
data['fw'] = firewall
return self.__post('host/', data)

def delete(self, ipv4: str) -> None:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def read(filename):

setup(
name='deterrers-api',
version='0.2',
version='0.3',
description='Python API client for DETERRERS',
url='https://github.com/virtUOS/deterrers-api',
author='Lars Kiesow',
Expand Down

0 comments on commit a2e337a

Please sign in to comment.