-
Notifications
You must be signed in to change notification settings - Fork 4
/
test-ws-client.py
executable file
·46 lines (37 loc) · 1.25 KB
/
test-ws-client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python3
# This executable can be used to test the websocket connection of a
# aca-py message processor instance.
import json
import asyncio
import os
import aiohttp
import argparse
parser = argparse.ArgumentParser(
prog='test-ws-client',
description="collects and cache's aca-py webhook calls until requested by controller."
)
parser.add_argument('--api-key', '-k', action='store', help='the API key to use')
parser.add_argument('--host', '-H', action='store', default='0.0.0.0')
parser.add_argument('--port', '-p', action='store', default=8080)
args = parser.parse_args()
URL = f'ws://{args.host}:{args.port}/ws'
print(f'Connecting to: {URL}')
async def main():
headers = {}
if args.api_key:
headers['Authorization'] = args.api_key
session = aiohttp.ClientSession(headers=headers)
async with session.ws_connect(URL) as ws:
await ws.send_str(json.dumps({
'auth': args.api_key,
'fastForward': True
}))
async for msg in ws:
print('Message received from server:')
print(msg)
print()
print('done')
if __name__ == '__main__':
print('Type "exit" to quit')
loop = asyncio.get_event_loop()
loop.run_until_complete(main())