mirror of
https://github.com/ansible/awx.git
synced 2026-03-19 09:57:33 -02:30
Ability to user awxkit with websocket custom urls
This commit is contained in:
committed by
Dave
parent
81d88df757
commit
f78ba282a6
@@ -51,7 +51,16 @@ class WSClient(object):
|
|||||||
# Subscription group types
|
# Subscription group types
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self, token=None, hostname='', port=443, secure=True, session_id=None, csrftoken=None, add_received_time=False, session_cookie_name='awx_sessionid'
|
self,
|
||||||
|
token=None,
|
||||||
|
hostname='',
|
||||||
|
port=443,
|
||||||
|
secure=True,
|
||||||
|
ws_suffix='websocket/',
|
||||||
|
session_id=None,
|
||||||
|
csrftoken=None,
|
||||||
|
add_received_time=False,
|
||||||
|
session_cookie_name='awx_sessionid',
|
||||||
):
|
):
|
||||||
# delay this import, because this is an optional dependency
|
# delay this import, because this is an optional dependency
|
||||||
import websocket
|
import websocket
|
||||||
@@ -68,6 +77,7 @@ class WSClient(object):
|
|||||||
hostname = result.hostname
|
hostname = result.hostname
|
||||||
|
|
||||||
self.port = port
|
self.port = port
|
||||||
|
self.suffix = ws_suffix
|
||||||
self._use_ssl = secure
|
self._use_ssl = secure
|
||||||
self.hostname = hostname
|
self.hostname = hostname
|
||||||
self.token = token
|
self.token = token
|
||||||
@@ -85,7 +95,7 @@ class WSClient(object):
|
|||||||
else:
|
else:
|
||||||
auth_cookie = ''
|
auth_cookie = ''
|
||||||
pref = 'wss://' if self._use_ssl else 'ws://'
|
pref = 'wss://' if self._use_ssl else 'ws://'
|
||||||
url = '{0}{1.hostname}:{1.port}/websocket/'.format(pref, self)
|
url = '{0}{1.hostname}:{1.port}/{1.suffix}'.format(pref, self)
|
||||||
self.ws = websocket.WebSocketApp(
|
self.ws = websocket.WebSocketApp(
|
||||||
url, on_open=self._on_open, on_message=self._on_message, on_error=self._on_error, on_close=self._on_close, cookie=auth_cookie
|
url, on_open=self._on_open, on_message=self._on_message, on_error=self._on_error, on_close=self._on_close, cookie=auth_cookie
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -17,6 +17,11 @@ def test_explicit_hostname():
|
|||||||
assert client.token == "token"
|
assert client.token == "token"
|
||||||
|
|
||||||
|
|
||||||
|
def test_websocket_suffix():
|
||||||
|
client = WSClient("token", "hostname", 566, ws_suffix='my-websocket/')
|
||||||
|
assert client.suffix == 'my-websocket/'
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
'url, result',
|
'url, result',
|
||||||
[
|
[
|
||||||
|
|||||||
Reference in New Issue
Block a user