Skip to content

Commit

Permalink
Auto-register new hosts
Browse files Browse the repository at this point in the history
This patch adds a flag to auto-register newly added hosts with the
firewall. This can be enabled in general via the configuration and
disabled via a command line flag if necessary, or just enabled via
command line flag.
  • Loading branch information
lkiesow committed Sep 6, 2023
1 parent 17f0b77 commit 25cb883
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ To configure the client, create a file `~/.deterrers.yml` with the following con
```yaml
url: https://deterrers.example.com
token: <api-token>

# If you want to automatically register newly added hosts
# Default: false
auto-register: false
```
## Usane
Expand Down
8 changes: 7 additions & 1 deletion deterrerscli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from deterrerscli.types import IPV4_TYPE

deterrers = None
auto_register = False

profiles = click.Choice(
('', 'HTTP', 'SSH', 'HTTP+SSH', 'Multipurpose'),
Expand All @@ -26,9 +27,11 @@ def print_format(data, format: str):
@click.group()
def cli():
global deterrers
global auto_register
with open(pathlib.Path().home() / '.deterrers.yml', 'r') as f:
config = yaml.safe_load(f)
deterrers = deterrersapi.Deterrers(config['url'], config['token'])
auto_register = config.get('auto-register', False)


@cli.command()
Expand Down Expand Up @@ -62,11 +65,14 @@ def delete(ipv4):
@click.option('--admin', '-a', multiple=True, required=True)
@click.option('--profile', '-p', default='', type=profiles)
@click.option('--firewall', '-f', default='', type=host_firewalls)
@click.option('--register/--no-register', default=False)
@click.argument('ipv4', type=IPV4_TYPE)
def add(ipv4, admin, profile, firewall):
def add(ipv4, admin, profile, firewall, register):
'''Add IP address to DETERRERS.
'''
deterrers.add(ipv4, admin, profile, firewall)
if auto_register or register:
deterrers.action(ipv4, 'register')


@cli.command()
Expand Down

0 comments on commit 25cb883

Please sign in to comment.