appmesh 1.6.7__py3-none-any.whl → 1.6.9__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
@@ -7,7 +7,10 @@ import locale
|
|
7
7
|
import logging
|
8
8
|
import os
|
9
9
|
import sys
|
10
|
+
import threading
|
10
11
|
import time
|
12
|
+
import requests
|
13
|
+
import http.cookiejar as cookiejar
|
11
14
|
from datetime import datetime
|
12
15
|
from enum import Enum, unique
|
13
16
|
from http import HTTPStatus
|
@@ -16,8 +19,6 @@ from typing import Optional, Tuple, Union
|
|
16
19
|
from urllib import parse
|
17
20
|
import aniso8601
|
18
21
|
import jwt
|
19
|
-
import requests
|
20
|
-
from requests.auth import _basic_auth_str
|
21
22
|
from .app import App
|
22
23
|
from .app_run import AppRun
|
23
24
|
from .app_output import AppOutput
|
@@ -75,7 +76,7 @@ class AppMeshClient(metaclass=abc.ABCMeta):
|
|
75
76
|
- wait_for_async_run()
|
76
77
|
- run_app_sync()
|
77
78
|
- run_task()
|
78
|
-
-
|
79
|
+
- cancel_task()
|
79
80
|
|
80
81
|
# System Management
|
81
82
|
- forward_to
|
@@ -192,7 +193,8 @@ class AppMeshClient(metaclass=abc.ABCMeta):
|
|
192
193
|
rest_ssl_verify=DEFAULT_SSL_CA_CERT_PATH if os.path.exists(DEFAULT_SSL_CA_CERT_PATH) else False,
|
193
194
|
rest_ssl_client_cert=(DEFAULT_SSL_CLIENT_CERT_PATH, DEFAULT_SSL_CLIENT_KEY_PATH) if os.path.exists(DEFAULT_SSL_CLIENT_CERT_PATH) else None,
|
194
195
|
rest_timeout=(60, 300),
|
195
|
-
jwt_token=None,
|
196
|
+
jwt_token: Optional[str] = None,
|
197
|
+
rest_cookie_file: Optional[str] = None,
|
196
198
|
auto_refresh_token=False,
|
197
199
|
):
|
198
200
|
"""Initialize an App Mesh HTTP client for interacting with the App Mesh server via secure HTTPS.
|
@@ -214,13 +216,14 @@ class AppMeshClient(metaclass=abc.ABCMeta):
|
|
214
216
|
rest_timeout (tuple, optional): HTTP connection timeouts for API requests, as `(connect_timeout, read_timeout)`.
|
215
217
|
The default is `(60, 300)`, where `60` seconds is the maximum time to establish a connection and `300` seconds for the maximum read duration.
|
216
218
|
|
219
|
+
rest_cookie_file (str, optional): Path to a file for storing session cookies. If provided, cookies will be saved to and loaded from this file to maintain session state across client instances.
|
220
|
+
|
217
221
|
jwt_token (str, optional): JWT token for API authentication, used in headers to authorize requests where required.
|
218
222
|
auto_refresh_token (bool, optional): Enable automatic token refresh before expiration.
|
219
223
|
When enabled, a background timer will monitor token expiration and attempt to refresh
|
220
224
|
the token before it expires. This works with both native App Mesh tokens and Keycloak tokens.
|
221
225
|
"""
|
222
226
|
self._ensure_logging_configured()
|
223
|
-
self.session = requests.Session()
|
224
227
|
self.auth_server_url = rest_url
|
225
228
|
self._jwt_token = jwt_token
|
226
229
|
self.ssl_verify = rest_ssl_verify
|
@@ -228,6 +231,20 @@ class AppMeshClient(metaclass=abc.ABCMeta):
|
|
228
231
|
self.rest_timeout = rest_timeout
|
229
232
|
self._forward_to = None
|
230
233
|
|
234
|
+
# Session and cookie management
|
235
|
+
self._lock = threading.Lock()
|
236
|
+
self.session = requests.Session()
|
237
|
+
self.cookie_file = rest_cookie_file
|
238
|
+
if self.cookie_file:
|
239
|
+
self.session.cookies = cookiejar.MozillaCookieJar(self.cookie_file)
|
240
|
+
if os.path.exists(self.cookie_file):
|
241
|
+
self.session.cookies.load(ignore_discard=True, ignore_expires=True)
|
242
|
+
else:
|
243
|
+
os.makedirs(os.path.dirname(self.cookie_file), exist_ok=True)
|
244
|
+
self.session.cookies.save(ignore_discard=True, ignore_expires=True)
|
245
|
+
if os.name == "posix":
|
246
|
+
os.chmod(self.cookie_file, 0o600) # User read/write only
|
247
|
+
|
231
248
|
# Token auto-refresh
|
232
249
|
self._token_refresh_timer = None
|
233
250
|
self._auto_refresh_token = auto_refresh_token
|
@@ -399,6 +416,11 @@ class AppMeshClient(metaclass=abc.ABCMeta):
|
|
399
416
|
self._token_refresh_timer.cancel()
|
400
417
|
self._token_refresh_timer = None
|
401
418
|
|
419
|
+
# handle session
|
420
|
+
with self._lock:
|
421
|
+
if self.cookie_file:
|
422
|
+
self.session.cookies.save(ignore_discard=True, ignore_expires=True)
|
423
|
+
|
402
424
|
@property
|
403
425
|
def forward_to(self) -> str:
|
404
426
|
"""Get the target host address for request forwarding in a cluster setup.
|
@@ -474,7 +496,7 @@ class AppMeshClient(metaclass=abc.ABCMeta):
|
|
474
496
|
AppMeshClient.Method.POST,
|
475
497
|
path="/appmesh/login",
|
476
498
|
header={
|
477
|
-
self.HTTP_HEADER_KEY_AUTH:
|
499
|
+
self.HTTP_HEADER_KEY_AUTH: "Basic " + base64.b64encode(f"{user_name}:{user_pwd}".encode()).decode(),
|
478
500
|
"X-Expire-Seconds": str(self._parse_duration(timeout_seconds)),
|
479
501
|
**({"X-Audience": audience} if audience else {}),
|
480
502
|
# **({"X-Totp-Code": totp_code} if totp_code else {}),
|
@@ -610,15 +632,17 @@ class AppMeshClient(metaclass=abc.ABCMeta):
|
|
610
632
|
raise Exception(f"Token renewal failed: {str(e)}") from e
|
611
633
|
|
612
634
|
def get_totp_secret(self) -> str:
|
613
|
-
"""
|
635
|
+
"""
|
636
|
+
Generate TOTP secret for the current user and return a secret.
|
614
637
|
|
615
638
|
Returns:
|
616
|
-
str: TOTP secret
|
639
|
+
str: TOTP secret string
|
617
640
|
"""
|
618
641
|
resp = self._request_http(method=AppMeshClient.Method.POST, path="/appmesh/totp/secret")
|
619
642
|
if resp.status_code == HTTPStatus.OK:
|
620
643
|
totp_uri = base64.b64decode(resp.json()["mfa_uri"]).decode()
|
621
644
|
return self._parse_totp_uri(totp_uri).get("secret")
|
645
|
+
|
622
646
|
raise Exception(resp.text)
|
623
647
|
|
624
648
|
def setup_totp(self, totp_code: str) -> str:
|
@@ -1238,7 +1262,7 @@ class AppMeshClient(metaclass=abc.ABCMeta):
|
|
1238
1262
|
|
1239
1263
|
return resp.text
|
1240
1264
|
|
1241
|
-
def
|
1265
|
+
def cancel_task(self, app_name: str) -> bool:
|
1242
1266
|
"""Client cancle a running task to a App Mesh application.
|
1243
1267
|
|
1244
1268
|
Args:
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: appmesh
|
3
|
-
Version: 1.6.
|
3
|
+
Version: 1.6.9
|
4
4
|
Summary: Client SDK for App Mesh
|
5
5
|
Home-page: https://github.com/laoshanxi/app-mesh
|
6
6
|
Author: laoshanxi
|
@@ -145,7 +145,6 @@ Refer to the [Installation doc](https://app-mesh.readthedocs.io/en/latest/Instal
|
|
145
145
|
- [log4cpp](http://log4cpp.sourceforge.net)
|
146
146
|
- [Crypto++](https://www.cryptopp.com)
|
147
147
|
- [ldap-cpp](https://github.com/AndreyBarmaley/ldap-cpp)
|
148
|
-
- [OATH Toolkit](http://www.nongnu.org/oath-toolkit/liboath-api)
|
149
148
|
|
150
149
|
[language.url]: https://isocpp.org/
|
151
150
|
[language.badge]: https://img.shields.io/badge/language-C++-blue.svg
|
@@ -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=
|
6
|
+
appmesh/client_http.py,sha256=OiYM4CXn21S4e_jx71X5_31krLes6UuHHueEYk6UIu4,58690
|
7
7
|
appmesh/client_http_oauth.py,sha256=1d51o0JX_xtB8d2bEuM7_XJHcwMnhcjkbIq7GE1Zxm8,6120
|
8
8
|
appmesh/client_tcp.py,sha256=aq6UUzytZA4ibE9WQMMWdo1uW8sHETEhJjsbM6IYSno,11457
|
9
9
|
appmesh/server_http.py,sha256=rBIYO9rbR-r3x1Jcry440Sp--IM-OWKRaOhNpGdkxh8,4299
|
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.
|
14
|
-
appmesh-1.6.
|
15
|
-
appmesh-1.6.
|
16
|
-
appmesh-1.6.
|
13
|
+
appmesh-1.6.9.dist-info/METADATA,sha256=aT2BPT5BM_5FkkFKhR-h_NBWMQMeVBP3-Wo2QwA-j6Y,11763
|
14
|
+
appmesh-1.6.9.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
15
|
+
appmesh-1.6.9.dist-info/top_level.txt,sha256=-y0MNQOGJxUzLdHZ6E_Rfv5_LNCkV-GTmOBME_b6pg8,8
|
16
|
+
appmesh-1.6.9.dist-info/RECORD,,
|
File without changes
|
File without changes
|