Skip to content

Commit

Permalink
fix wsrelay connection in ipv6 environments
Browse files Browse the repository at this point in the history
  • Loading branch information
kdelee committed Nov 6, 2023
1 parent b831dbd commit 946ca0b
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion awx/main/wsrelay.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import asyncio
from typing import Dict

import ipaddress

import aiohttp
from aiohttp import client_exceptions
import aioredis
Expand Down Expand Up @@ -71,7 +73,16 @@ async def connect(self):
if not self.channel_layer:
self.channel_layer = get_channel_layer()

uri = f"{self.protocol}://{self.remote_host}:{self.remote_port}/websocket/relay/"
# figure out if what we have is an ipaddress, IPv6 Addresses must have brackets added for uri
uri_hostname = self.remote_host
try:
# Throws ValueError if self.remote_host is a hostname like example.com, not an IPv4 or IPv6 ip address
if isinstance(ipaddress.ip_address(uri_hostname), ipaddress.IPv6Address):
uri_hostname = f"[{uri_hostname}]"
except ValueError:
pass

uri = f"{self.protocol}://{uri_hostname}:{self.remote_port}/websocket/relay/"
timeout = aiohttp.ClientTimeout(total=10)

secret_val = WebsocketSecretAuthHelper.construct_secret()
Expand Down

0 comments on commit 946ca0b

Please sign in to comment.