appmesh 1.6.4__py3-none-any.whl → 1.6.6__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/client_http.py CHANGED
@@ -1,5 +1,5 @@
1
1
  # client_http.py
2
- # pylint: disable=broad-exception-raised,line-too-long,broad-exception-caught,too-many-lines, import-outside-toplevel, protected-access
2
+ # pylint: disable=broad-exception-raised,line-too-long,broad-exception-caught,too-many-lines,import-outside-toplevel
3
3
  import abc
4
4
  import base64
5
5
  import json
@@ -17,6 +17,7 @@ from urllib import parse
17
17
  import aniso8601
18
18
  import jwt
19
19
  import requests
20
+ from requests.auth import _basic_auth_str
20
21
  from .app import App
21
22
  from .app_run import AppRun
22
23
  from .app_output import AppOutput
@@ -123,6 +124,7 @@ class AppMeshClient(metaclass=abc.ABCMeta):
123
124
 
124
125
  JSON_KEY_MESSAGE = "message"
125
126
  HTTP_USER_AGENT = "appmesh/python"
127
+ HTTP_HEADER_KEY_AUTH = "Authorization"
126
128
  HTTP_HEADER_KEY_USER_AGENT = "User-Agent"
127
129
  HTTP_HEADER_KEY_X_TARGET_HOST = "X-Target-Host"
128
130
  HTTP_HEADER_KEY_X_FILE_PATH = "X-File-Path"
@@ -229,7 +231,7 @@ class AppMeshClient(metaclass=abc.ABCMeta):
229
231
  # Token auto-refresh
230
232
  self._token_refresh_timer = None
231
233
  self._auto_refresh_token = auto_refresh_token
232
- self.jwt_token = jwt_token # Set property last after all dependencies are initialized
234
+ self.jwt_token = jwt_token # Set property last after all dependencies are initialized to setup refresh timer
233
235
 
234
236
  @staticmethod
235
237
  def _ensure_logging_configured():
@@ -306,7 +308,7 @@ class AppMeshClient(metaclass=abc.ABCMeta):
306
308
  check_interval = 1 # Almost immediate refresh
307
309
  else:
308
310
  # Check at earlier of 5 minutes before expiry or regular interval
309
- check_interval = min(time_to_expiry - self.TOKEN_REFRESH_OFFSET, self.TOKEN_REFRESH_INTERVAL)
311
+ check_interval = max(1, min(time_to_expiry - self.TOKEN_REFRESH_OFFSET, self.TOKEN_REFRESH_INTERVAL))
310
312
 
311
313
  # Create timer to execute refresh check
312
314
  self._token_refresh_timer = threading.Timer(check_interval, self._check_and_refresh_token)
@@ -472,7 +474,7 @@ class AppMeshClient(metaclass=abc.ABCMeta):
472
474
  AppMeshClient.Method.POST,
473
475
  path="/appmesh/login",
474
476
  header={
475
- "Authorization": "Basic " + base64.b64encode((user_name + ":" + user_pwd).encode()).decode(),
477
+ self.HTTP_HEADER_KEY_AUTH: _basic_auth_str(user_name, user_pwd),
476
478
  "X-Expire-Seconds": str(self._parse_duration(timeout_seconds)),
477
479
  **({"X-Audience": audience} if audience else {}),
478
480
  # **({"X-Totp-Code": totp_code} if totp_code else {}),
@@ -1396,9 +1398,9 @@ class AppMeshClient(metaclass=abc.ABCMeta):
1396
1398
 
1397
1399
  # Prepare headers
1398
1400
  header = {} if header is None else header
1399
- if self.jwt_token:
1400
- token = self._get_access_token()
1401
- header["Authorization"] = "Bearer " + token
1401
+ token = self._get_access_token()
1402
+ if token:
1403
+ header[self.HTTP_HEADER_KEY_AUTH] = f"Bearer {token}"
1402
1404
  if self.forward_to and len(self.forward_to) > 0:
1403
1405
  if ":" in self.forward_to:
1404
1406
  header[self.HTTP_HEADER_KEY_X_TARGET_HOST] = self.forward_to
@@ -1436,4 +1438,4 @@ class AppMeshClient(metaclass=abc.ABCMeta):
1436
1438
  # Wrap the response for encoding handling
1437
1439
  return AppMeshClient.EncodingResponse(resp)
1438
1440
  except requests.exceptions.RequestException as e:
1439
- raise Exception(f"HTTP request failed: {str(e)}")
1441
+ raise Exception(f"HTTP request failed: {str(e)}") from e
appmesh/client_tcp.py CHANGED
@@ -116,8 +116,9 @@ class AppMeshClientTCP(AppMeshClient):
116
116
  self.tcp_transport.connect()
117
117
 
118
118
  appmesh_request = RequestMessage()
119
- if super().jwt_token:
120
- appmesh_request.headers["Authorization"] = "Bearer " + super().jwt_token
119
+ token = self._get_access_token()
120
+ if token:
121
+ appmesh_request.headers[self.HTTP_HEADER_KEY_AUTH] = token
121
122
  if super().forward_to and len(super().forward_to) > 0:
122
123
  raise Exception("Not support forward request in TCP mode")
123
124
  appmesh_request.headers[self.HTTP_HEADER_KEY_USER_AGENT] = self.HTTP_USER_AGENT_TCP
appmesh/server_http.py CHANGED
@@ -17,7 +17,7 @@ class AppMeshServer(metaclass=abc.ABCMeta):
17
17
  Server SDK for App Mesh application interacting with the local App Mesh REST service over HTTPS.
18
18
 
19
19
  Build-in runtime environment variables required:
20
- - APP_MESH_PROCESS_ID
20
+ - APP_MESH_PROCESS_KEY
21
21
  - APP_MESH_APPLICATION_NAME
22
22
 
23
23
  Methods:
@@ -58,10 +58,10 @@ class AppMeshServer(metaclass=abc.ABCMeta):
58
58
  @staticmethod
59
59
  def _get_runtime_env() -> Tuple[str, str]:
60
60
  """Read and validate required runtime environment variables."""
61
- process_id = os.getenv("APP_MESH_PROCESS_ID")
61
+ process_id = os.getenv("APP_MESH_PROCESS_KEY")
62
62
  app_name = os.getenv("APP_MESH_APPLICATION_NAME")
63
63
  if not process_id:
64
- raise Exception("Missing environment variable: APP_MESH_PROCESS_ID. This must be set by App Mesh service.")
64
+ raise Exception("Missing environment variable: APP_MESH_PROCESS_KEY. This must be set by App Mesh service.")
65
65
  if not app_name:
66
66
  raise Exception("Missing environment variable: APP_MESH_APPLICATION_NAME. This must be set by App Mesh service.")
67
67
  return process_id, app_name
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: appmesh
3
- Version: 1.6.4
3
+ Version: 1.6.6
4
4
  Summary: Client SDK for App Mesh
5
5
  Home-page: https://github.com/laoshanxi/app-mesh
6
6
  Author: laoshanxi
@@ -3,14 +3,14 @@ appmesh/app.py,sha256=crD4DRFZJuHtZMfSsz7C-EwvjPmGZbFXYXvA_wCdvdI,10734
3
3
  appmesh/app_output.py,sha256=vfn322AyixblI8DbXds08h6L_ybObiaRSifsA1-Xcoo,1035
4
4
  appmesh/app_run.py,sha256=aYq852a29OThIi32Xtx5s0sTXZ97T0lHD5WXH8yfPoc,2018
5
5
  appmesh/appmesh_client.py,sha256=ywB2222PtJUffdfdxZcBfdhZs1KYyc7JvzMxwuK2qyI,378
6
- appmesh/client_http.py,sha256=hKv8t5ufqfnNkt4Bi4NCfDcn5LZisFP5qtNxzGsehVo,57457
6
+ appmesh/client_http.py,sha256=dzNZvMztm0POLHNS8iNHo1iuJprjvQP0kii1UWOH-XA,57529
7
7
  appmesh/client_http_oauth.py,sha256=1d51o0JX_xtB8d2bEuM7_XJHcwMnhcjkbIq7GE1Zxm8,6120
8
- appmesh/client_tcp.py,sha256=ewKKltGHqjs7XM-9Hc1Jp9bciwvlNQR1k0Nzu3xviks,11442
9
- appmesh/server_http.py,sha256=vf_Kh7ZIyEuBijZp8I2Rv-Fy9gxFdPFn5Pp2rUNCT1U,4319
8
+ appmesh/client_tcp.py,sha256=aq6UUzytZA4ibE9WQMMWdo1uW8sHETEhJjsbM6IYSno,11457
9
+ appmesh/server_http.py,sha256=H6DfMhU2NxlBqxjmRG2C8NXMaGDxy_5QVyBmaVrelfI,4322
10
10
  appmesh/server_tcp.py,sha256=-CU5tw97WJmDcUNsNPWqpdZ0wxRzRD6kUP3XyNZUTHc,1444
11
11
  appmesh/tcp_messages.py,sha256=H9S_iCy0IuufY2v50_SUgRvcyQmJsySG65tBe_xb3Ko,1878
12
12
  appmesh/tcp_transport.py,sha256=0hRSp5fpL9wKB05JIyIRIuyBC8w1IdokryhMDHqtN4M,8946
13
- appmesh-1.6.4.dist-info/METADATA,sha256=9LUrGW7tdTI5__wP2srofLy7_mj6WK0_O3z1nUVgWvc,11828
14
- appmesh-1.6.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
15
- appmesh-1.6.4.dist-info/top_level.txt,sha256=-y0MNQOGJxUzLdHZ6E_Rfv5_LNCkV-GTmOBME_b6pg8,8
16
- appmesh-1.6.4.dist-info/RECORD,,
13
+ appmesh-1.6.6.dist-info/METADATA,sha256=2zvQG43uxfAhmT0v4e-_jyfQJT5veka--K-3Zeokqyw,11828
14
+ appmesh-1.6.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
15
+ appmesh-1.6.6.dist-info/top_level.txt,sha256=-y0MNQOGJxUzLdHZ6E_Rfv5_LNCkV-GTmOBME_b6pg8,8
16
+ appmesh-1.6.6.dist-info/RECORD,,