appmesh 1.2.3__py3-none-any.whl → 1.2.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- appmesh/appmesh_client.py +48 -6
- {appmesh-1.2.3.dist-info → appmesh-1.2.5.dist-info}/METADATA +2 -2
- appmesh-1.2.5.dist-info/RECORD +6 -0
- {appmesh-1.2.3.dist-info → appmesh-1.2.5.dist-info}/WHEEL +1 -1
- appmesh-1.2.3.dist-info/RECORD +0 -6
- {appmesh-1.2.3.dist-info → appmesh-1.2.5.dist-info}/top_level.txt +0 -0
appmesh/appmesh_client.py
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
"""App Mesh Python SDK"""
|
3
3
|
import abc
|
4
4
|
import base64
|
5
|
+
from contextlib import contextmanager
|
5
6
|
import copy
|
6
7
|
import json
|
7
8
|
import os
|
@@ -305,21 +306,33 @@ class Run(object):
|
|
305
306
|
"""application name"""
|
306
307
|
self.proc_uid = process_id
|
307
308
|
"""process_uuid from run_async()"""
|
308
|
-
self.
|
309
|
+
self._client = client
|
309
310
|
"""AppMeshClient object"""
|
311
|
+
self._delegate_host = client.delegate_host
|
312
|
+
"""delegate host indicates the target server for this app run"""
|
313
|
+
|
314
|
+
@contextmanager
|
315
|
+
def delegate_host(self):
|
316
|
+
"""context manager for delegate host override to self._client"""
|
317
|
+
original_value = self._client.delegate_host
|
318
|
+
self._client.delegate_host = self._delegate_host
|
319
|
+
try:
|
320
|
+
yield
|
321
|
+
finally:
|
322
|
+
self._client.delegate_host = original_value
|
310
323
|
|
311
324
|
def wait(self, stdout_print: bool = True, timeout: int = 0) -> int:
|
312
325
|
"""Wait for an async run to be finished
|
313
326
|
|
314
327
|
Args:
|
315
|
-
run (Run): asyncrized run result from run_async().
|
316
328
|
stdout_print (bool, optional): print remote stdout to local or not.
|
317
329
|
timeout (int, optional): wait max timeout seconds and return if not finished, 0 means wait until finished
|
318
330
|
|
319
331
|
Returns:
|
320
332
|
int: return exit code if process finished, return None for timeout or exception.
|
321
333
|
"""
|
322
|
-
|
334
|
+
with self.delegate_host():
|
335
|
+
return self._client.run_async_wait(self, stdout_print, timeout)
|
323
336
|
|
324
337
|
|
325
338
|
class AppMeshClient(metaclass=abc.ABCMeta):
|
@@ -359,10 +372,11 @@ class AppMeshClient(metaclass=abc.ABCMeta):
|
|
359
372
|
"""
|
360
373
|
|
361
374
|
self.server_url = rest_url
|
362
|
-
self.
|
375
|
+
self._jwt_token = jwt_token
|
363
376
|
self.ssl_verify = rest_ssl_verify
|
364
377
|
self.ssl_client_cert = rest_ssl_client_cert
|
365
378
|
self.rest_timeout = rest_timeout
|
379
|
+
self._delegate_host = None
|
366
380
|
|
367
381
|
@property
|
368
382
|
def jwt_token(self) -> str:
|
@@ -371,7 +385,7 @@ class AppMeshClient(metaclass=abc.ABCMeta):
|
|
371
385
|
Returns:
|
372
386
|
str: _description_
|
373
387
|
"""
|
374
|
-
return self.
|
388
|
+
return self._jwt_token
|
375
389
|
|
376
390
|
@jwt_token.setter
|
377
391
|
def jwt_token(self, token: str) -> None:
|
@@ -380,7 +394,25 @@ class AppMeshClient(metaclass=abc.ABCMeta):
|
|
380
394
|
Args:
|
381
395
|
token (str): _description_
|
382
396
|
"""
|
383
|
-
self.
|
397
|
+
self._jwt_token = token
|
398
|
+
|
399
|
+
@property
|
400
|
+
def delegate_host(self) -> str:
|
401
|
+
"""property for delegate_host
|
402
|
+
|
403
|
+
Returns:
|
404
|
+
str: delegate request to target host (host:port)
|
405
|
+
"""
|
406
|
+
return self._delegate_host
|
407
|
+
|
408
|
+
@delegate_host.setter
|
409
|
+
def delegate_host(self, host: str) -> None:
|
410
|
+
"""setter for delegate_host
|
411
|
+
|
412
|
+
Args:
|
413
|
+
host (str): delegate request to target host (host:port)
|
414
|
+
"""
|
415
|
+
self._delegate_host = host
|
384
416
|
|
385
417
|
########################################
|
386
418
|
# Security
|
@@ -1298,6 +1330,11 @@ class AppMeshClient(metaclass=abc.ABCMeta):
|
|
1298
1330
|
header = {} if header is None else header
|
1299
1331
|
if self.jwt_token:
|
1300
1332
|
header["Authorization"] = "Bearer " + self.jwt_token
|
1333
|
+
if self.delegate_host and len(self.delegate_host) > 0:
|
1334
|
+
if ":" in self.delegate_host:
|
1335
|
+
header["X-Target-Host"] = self.delegate_host
|
1336
|
+
else:
|
1337
|
+
header["X-Target-Host"] = self.delegate_host + ":" + str(parse.urlsplit(self.server_url).port)
|
1301
1338
|
header[HTTP_USER_AGENT_HEADER_NAME] = HTTP_USER_AGENT
|
1302
1339
|
|
1303
1340
|
if method is AppMeshClient.Method.GET:
|
@@ -1461,6 +1498,11 @@ class AppMeshClientTCP(AppMeshClient):
|
|
1461
1498
|
appmesh_requst = RequestMsg()
|
1462
1499
|
if super().jwt_token:
|
1463
1500
|
appmesh_requst.headers["Authorization"] = "Bearer " + super().jwt_token
|
1501
|
+
if super().delegate_host and len(super().delegate_host) > 0:
|
1502
|
+
if ":" in super().delegate_host:
|
1503
|
+
appmesh_requst.headers["X-Target-Host"] = super().delegate_host
|
1504
|
+
else:
|
1505
|
+
appmesh_requst.headers["X-Target-Host"] = super().delegate_host + ":" + str(parse.urlsplit(self.server_url).port)
|
1464
1506
|
appmesh_requst.headers[HTTP_USER_AGENT_HEADER_NAME] = HTTP_USER_AGENT
|
1465
1507
|
appmesh_requst.uuid = str(uuid.uuid1())
|
1466
1508
|
appmesh_requst.http_method = method.value
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: appmesh
|
3
|
-
Version: 1.2.
|
3
|
+
Version: 1.2.5
|
4
4
|
Summary: Client SDK for App Mesh
|
5
5
|
Home-page: https://github.com/laoshanxi/app-mesh
|
6
6
|
Author: laoshanxi
|
@@ -43,7 +43,7 @@ Cloud native | Schedule cloud-level applications to run on multiple hosts with r
|
|
43
43
|
Micro service application | ⚡️ [Consul micro-service cluster management](https://app-mesh.readthedocs.io/en/latest/CONSUL.html)
|
44
44
|
Extra Features | Collect host/app resource usage <br> Remote shell command execution <br> File upload/download interface <br> Hot-update support `systemctl reload appmesh` <br> Bash completion <br> Reverse proxy <br> [Web GUI](https://github.com/laoshanxi/app-mesh-ui)
|
45
45
|
Platform support | X86_64 <br> ARM32 <br> ARM64
|
46
|
-
SDK | [Python](https://app-mesh.readthedocs.io/en/latest/api/appmesh_client.html) <br> [Golang](https://github.com/laoshanxi/app-mesh/blob/main/src/sdk/go/appmesh_client.go) <br> Swagger
|
46
|
+
SDK | [Python](https://app-mesh.readthedocs.io/en/latest/api/appmesh_client.html) <br> [Golang](https://github.com/laoshanxi/app-mesh/blob/main/src/sdk/go/appmesh_client.go) <br> [Swagger OpenAPI Specification](https://petstore.swagger.io/?url=https://raw.githubusercontent.com/laoshanxi/app-mesh/main/src/daemon/rest/openapi.yaml)
|
47
47
|
|
48
48
|
## Getting started
|
49
49
|
|
@@ -0,0 +1,6 @@
|
|
1
|
+
appmesh/__init__.py,sha256=xRdXeFHEieRauuJZElbEBASgXG0ZzU1a5_0isAhM7Gw,11
|
2
|
+
appmesh/appmesh_client.py,sha256=vPC9L3hkvGuYRPHyzx6N6zbISKoSLah5PtbiE1Ktpv4,62419
|
3
|
+
appmesh-1.2.5.dist-info/METADATA,sha256=5EqsWLxfTX4CVSKJ1RhroBlR53G-5fxQlMeZ5-3suI8,10927
|
4
|
+
appmesh-1.2.5.dist-info/WHEEL,sha256=Wyh-_nZ0DJYolHNn1_hMa4lM7uDedD_RGVwbmTjyItk,91
|
5
|
+
appmesh-1.2.5.dist-info/top_level.txt,sha256=-y0MNQOGJxUzLdHZ6E_Rfv5_LNCkV-GTmOBME_b6pg8,8
|
6
|
+
appmesh-1.2.5.dist-info/RECORD,,
|
appmesh-1.2.3.dist-info/RECORD
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
appmesh/__init__.py,sha256=xRdXeFHEieRauuJZElbEBASgXG0ZzU1a5_0isAhM7Gw,11
|
2
|
-
appmesh/appmesh_client.py,sha256=T4UxSIrQDc9sLC4wqNXveYhBl_g1-pC9FHNdAzqFvgo,60822
|
3
|
-
appmesh-1.2.3.dist-info/METADATA,sha256=ChudplkmAbMyqjZ6mzGaEytKBfkvcxHpUVyJTaI50vM,10928
|
4
|
-
appmesh-1.2.3.dist-info/WHEEL,sha256=Z4pYXqR_rTB7OWNDYFOm1qRk0RX6GFP2o8LgvP453Hk,91
|
5
|
-
appmesh-1.2.3.dist-info/top_level.txt,sha256=-y0MNQOGJxUzLdHZ6E_Rfv5_LNCkV-GTmOBME_b6pg8,8
|
6
|
-
appmesh-1.2.3.dist-info/RECORD,,
|
File without changes
|