Add ReceptorAddress to root urls

- Add database contraints to make sure addresses
are unique
If port is defined:
address, port, protocol, websocket_path are unique together

if port is not defined:
address, protocol, websocket_path are unique together

- Allow deleting address via API
- Add ReceptorAddressAccess to determine permissions
- awx-manage add_receptor_address returns changed: True
if successful
This commit is contained in:
Seth Foster
2023-10-04 02:56:25 -04:00
committed by Seth Foster
parent 387e877485
commit 5199cc5246
10 changed files with 115 additions and 11 deletions

View File

@@ -1,8 +1,6 @@
# Copyright (c) 2015 Ansible, Inc.
# All Rights Reserved
import os
from django.core.management.base import BaseCommand
from django.db import transaction
@@ -28,11 +26,20 @@ class Command(BaseCommand):
)
def _add_address(self, **kwargs):
i = Instance.objects.get(hostname=kwargs.pop('hostname'))
kwargs['instance'] = i
ReceptorAddress.objects.create(**kwargs)
try:
instance = Instance.objects.get(hostname=kwargs.pop('hostname'))
kwargs['instance'] = instance
addr = ReceptorAddress.objects.create(**kwargs)
print(f"Successfully added receptor address {addr.get_full_address()}")
self.changed = True
except Exception as e:
self.changed = False
print(f"Error adding receptor address: {e}")
@transaction.atomic
def handle(self, **options):
self.changed = False
address_options = {k: options[k] for k in ('hostname', 'address', 'port', 'protocol', 'websocket_path', 'is_internal')}
self._add_address(**address_options)
if self.changed:
print("(changed: True)")