| @@ -83,6 +83,14 @@ def make_attrs(*args): | |||||
| _httpxargs = dict(timeout=20) | _httpxargs = dict(timeout=20) | ||||
| def convert_to_ws(url): | |||||
| if url.startswith('http://'): | |||||
| url = url.replace('http', 'ws', 1) | |||||
| elif url.startswith('https://'): | |||||
| url = url.replace('https', 'wss', 1) | |||||
| return url | |||||
| def output_board(brd): | def output_board(brd): | ||||
| print('Name:\t%s' % brd.name) | print('Name:\t%s' % brd.name) | ||||
| print('Class:\t%s' % brd.brdclass) | print('Class:\t%s' % brd.brdclass) | ||||
| @@ -118,6 +126,7 @@ async def fwd_data(reader, writer): | |||||
| async def run_exec(baseurl, authkey, board, args): | async def run_exec(baseurl, authkey, board, args): | ||||
| url = urllib.parse.urljoin(baseurl, 'board/%s/exec' % urllib.parse.quote(board, safe='')) | url = urllib.parse.urljoin(baseurl, 'board/%s/exec' % urllib.parse.quote(board, safe='')) | ||||
| url = convert_to_ws(url) | |||||
| stdin, stdout = await aioconsole.stream.get_standard_streams() | stdin, stdout = await aioconsole.stream.get_standard_streams() | ||||
| async with websockets.connect(url) as ws, wsfwd.WSFWDClient(ws.recv, ws.send) as client: | async with websockets.connect(url) as ws, wsfwd.WSFWDClient(ws.recv, ws.send) as client: | ||||
| @@ -338,7 +347,7 @@ class TestExecClient(unittest.IsolatedAsyncioTestCase): | |||||
| ret, stdout = await self.runAsyncMain() | ret, stdout = await self.runAsyncMain() | ||||
| webcon.assert_called_with(urllib.parse.urljoin('http://someserver/', 'board/cora-z7s/exec')) | |||||
| webcon.assert_called_with(urllib.parse.urljoin('ws://someserver/', 'board/cora-z7s/exec')) | |||||
| await server.__aexit__(None, None, None) | await server.__aexit__(None, None, None) | ||||
| @@ -417,6 +426,17 @@ class TestClient(unittest.TestCase): | |||||
| return ret, stdout.getvalue() | return ret, stdout.getvalue() | ||||
| def test_converttows(self): | |||||
| testpairs = [ | |||||
| ('http://somelkjdf/sdoijef/http/https/', | |||||
| 'ws://somelkjdf/sdoijef/http/https/'), | |||||
| ('https://oiweufjk/aoijeskfj/sadfoije/http/https/', | |||||
| 'wss://oiweufjk/aoijeskfj/sadfoije/http/https/'), | |||||
| ] | |||||
| for orig, new in testpairs: | |||||
| self.assertEqual(convert_to_ws(orig), new, 'failed to convert: %s' % repr(orig)) | |||||
| def test_sshpubkey(self): | def test_sshpubkey(self): | ||||
| fname = 'fname' | fname = 'fname' | ||||
| rdata = 'foo' | rdata = 'foo' | ||||