Files
awx/awx/main/models/receptor_address.py
2024-02-02 10:37:41 -05:00

30 lines
841 B
Python

from django.db import models
class ReceptorAddress(models.Model):
address = models.CharField(max_length=255)
port = models.IntegerField(null=True)
protocol = models.CharField(max_length=10)
websocket_path = models.CharField(max_length=255, default="", blank=True)
is_internal = models.BooleanField(default=False)
instance = models.ForeignKey(
'Instance',
related_name='receptor_addresses',
on_delete=models.CASCADE,
)
def get_full_address(self):
scheme = ""
path = ""
port = ""
if self.protocol == "ws":
scheme = "wss://"
if self.protocol == "ws" and self.websocket_path:
path = f"/{self.websocket_path}"
if self.port:
port = f":{self.port}"
return f"{scheme}{self.address}{port}{path}"