appmesh 0.6.0__py3-none-any.whl → 0.6.2__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 +25 -7
- {appmesh-0.6.0.dist-info → appmesh-0.6.2.dist-info}/METADATA +1 -1
- appmesh-0.6.2.dist-info/RECORD +6 -0
- appmesh-0.6.0.dist-info/RECORD +0 -6
- {appmesh-0.6.0.dist-info → appmesh-0.6.2.dist-info}/WHEEL +0 -0
- {appmesh-0.6.0.dist-info → appmesh-0.6.2.dist-info}/top_level.txt +0 -0
appmesh/appmesh_client.py
CHANGED
@@ -24,6 +24,8 @@ REST_TEXT_MESSAGE_JSON_KEY = "message"
|
|
24
24
|
MESSAGE_ENCODING_UTF8 = "utf-8"
|
25
25
|
TCP_MESSAGE_HEADER_LENGTH = 4
|
26
26
|
_SSL_CA_PEM_FILE = "/opt/appmesh/ssl/ca.pem"
|
27
|
+
_SSL_CLIENT_PEM_FILE = "/opt/appmesh/ssl/client.pem"
|
28
|
+
_SSL_CLIENT_PEM_KEY_FILE = "/opt/appmesh/ssl/client-key.pem"
|
27
29
|
HTTP_USER_AGENT_HEADER_NAME = "User-Agent"
|
28
30
|
HTTP_USER_AGENT = "appmeshsdk/py"
|
29
31
|
|
@@ -278,6 +280,7 @@ class AppMeshClient(metaclass=abc.ABCMeta):
|
|
278
280
|
self,
|
279
281
|
rest_url: str = "https://127.0.0.1:6060",
|
280
282
|
rest_ssl_verify=_SSL_CA_PEM_FILE,
|
283
|
+
rest_ssl_client_cert=(_SSL_CLIENT_PEM_FILE, _SSL_CLIENT_PEM_KEY_FILE),
|
281
284
|
rest_timeout=(60, 300),
|
282
285
|
jwt_token=None,
|
283
286
|
):
|
@@ -286,12 +289,14 @@ class AppMeshClient(metaclass=abc.ABCMeta):
|
|
286
289
|
Args:
|
287
290
|
rest_url (str, optional): server URI string.
|
288
291
|
rest_ssl_verify (str, optional): SSL CA certification path for verification, True for use system's default certificate store, False to disable SSL verification.
|
292
|
+
rest_ssl_client_cert (tuple, optional): SSL client certificate and key pair, None to disable client verification
|
289
293
|
rest_timeout (tuple, optional): HTTP timeout, Defaults to 60 seconds for connect timeout and 300 seconds for read timeout
|
290
294
|
jwt_token (str, optional): JWT token, provide correct token is same with login() & authenticate().
|
291
295
|
"""
|
292
296
|
self.server_url = rest_url
|
293
297
|
self.__jwt_token = jwt_token
|
294
298
|
self.ssl_verify = rest_ssl_verify
|
299
|
+
self.ssl_client_cert = rest_ssl_client_cert
|
295
300
|
self.rest_timeout = rest_timeout
|
296
301
|
|
297
302
|
@property
|
@@ -1107,22 +1112,23 @@ class AppMeshClient(metaclass=abc.ABCMeta):
|
|
1107
1112
|
header[HTTP_USER_AGENT_HEADER_NAME] = HTTP_USER_AGENT
|
1108
1113
|
|
1109
1114
|
if method is AppMeshClient.Method.GET:
|
1110
|
-
return requests.get(url=rest_url, params=query, headers=header, verify=self.ssl_verify, timeout=self.rest_timeout)
|
1115
|
+
return requests.get(url=rest_url, params=query, headers=header, cert=self.ssl_client_cert, verify=self.ssl_verify, timeout=self.rest_timeout)
|
1111
1116
|
elif method is AppMeshClient.Method.POST:
|
1112
|
-
return requests.post(url=rest_url, params=query, headers=header, data=
|
1117
|
+
return requests.post(url=rest_url, params=query, headers=header, data=body if (isinstance(body, str) or isinstance(body, json)) else json.dumps(body), cert=self.ssl_client_cert, verify=self.ssl_verify, timeout=self.rest_timeout)
|
1113
1118
|
elif method is AppMeshClient.Method.POST_STREAM:
|
1114
1119
|
return requests.post(
|
1115
1120
|
url=rest_url,
|
1116
1121
|
params=query,
|
1117
1122
|
headers=header,
|
1118
1123
|
data=body,
|
1119
|
-
|
1124
|
+
cert=self.ssl_client_cert,
|
1125
|
+
verify=self.ssl_verify,
|
1120
1126
|
stream=True,
|
1121
1127
|
)
|
1122
1128
|
elif method is AppMeshClient.Method.DELETE:
|
1123
|
-
return requests.delete(url=rest_url, headers=header, verify=self.ssl_verify, timeout=self.rest_timeout)
|
1129
|
+
return requests.delete(url=rest_url, headers=header, cert=self.ssl_client_cert, verify=self.ssl_verify, timeout=self.rest_timeout)
|
1124
1130
|
elif method is AppMeshClient.Method.PUT:
|
1125
|
-
return requests.put(url=rest_url, params=query, headers=header, json=body, verify=self.ssl_verify, timeout=self.rest_timeout)
|
1131
|
+
return requests.put(url=rest_url, params=query, headers=header, json=body, cert=self.ssl_client_cert, verify=self.ssl_verify, timeout=self.rest_timeout)
|
1126
1132
|
else:
|
1127
1133
|
raise Exception("Invalid http method", method)
|
1128
1134
|
|
@@ -1136,14 +1142,21 @@ class AppMeshClientTCP(AppMeshClient):
|
|
1136
1142
|
|
1137
1143
|
def __init__(
|
1138
1144
|
self,
|
1145
|
+
rest_ssl_verify=_SSL_CA_PEM_FILE,
|
1146
|
+
rest_ssl_client_cert=(_SSL_CLIENT_PEM_FILE, _SSL_CLIENT_PEM_KEY_FILE),
|
1147
|
+
jwt_token=None,
|
1139
1148
|
tcp_address=("localhost", 6059),
|
1140
1149
|
):
|
1141
1150
|
"""Construct an App Mesh client TCP object
|
1142
1151
|
|
1143
1152
|
Args:
|
1153
|
+
rest_ssl_verify (str, optional): SSL CA certification path for verification, True for use system's default certificate store, False to disable SSL verification.
|
1154
|
+
rest_ssl_client_cert (tuple, optional): SSL client certificate and key pair, None to disable client verification
|
1155
|
+
jwt_token (str, optional): JWT token, provide correct token is same with login() & authenticate().
|
1156
|
+
|
1144
1157
|
tcp_address (tuple, optional): TCP connect address.
|
1145
1158
|
"""
|
1146
|
-
super().__init__()
|
1159
|
+
super().__init__("", rest_ssl_verify, rest_ssl_client_cert, None, jwt_token)
|
1147
1160
|
self.tcp_address = tcp_address
|
1148
1161
|
self.__socket_client = None
|
1149
1162
|
|
@@ -1157,7 +1170,12 @@ class AppMeshClientTCP(AppMeshClient):
|
|
1157
1170
|
sock.setblocking(True)
|
1158
1171
|
|
1159
1172
|
context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
|
1160
|
-
context.
|
1173
|
+
context.verify_mode = ssl.CERT_NONE if self.ssl_verify == False else ssl.CERT_REQUIRED
|
1174
|
+
if isinstance(self.ssl_verify, str):
|
1175
|
+
context.check_hostname = True
|
1176
|
+
context.load_verify_locations(self.ssl_verify)
|
1177
|
+
if self.ssl_client_cert is not None:
|
1178
|
+
context.load_cert_chain(certfile=self.ssl_client_cert[0], keyfile=self.ssl_client_cert[1])
|
1161
1179
|
self.__socket_client = context.wrap_socket(sock, server_hostname=self.tcp_address[0])
|
1162
1180
|
|
1163
1181
|
def __close_socket(self) -> None:
|
@@ -0,0 +1,6 @@
|
|
1
|
+
appmesh/__init__.py,sha256=xRdXeFHEieRauuJZElbEBASgXG0ZzU1a5_0isAhM7Gw,11
|
2
|
+
appmesh/appmesh_client.py,sha256=ODBZkjX6wXI2eHNxZT_Tx4T82D6MCbnM3PYWjIuS0rs,54041
|
3
|
+
appmesh-0.6.2.dist-info/METADATA,sha256=mO9JQyb5qEBLxXsJ8t5YmMgo2rYWWbQX3GGb2dF6hDk,10746
|
4
|
+
appmesh-0.6.2.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
5
|
+
appmesh-0.6.2.dist-info/top_level.txt,sha256=-y0MNQOGJxUzLdHZ6E_Rfv5_LNCkV-GTmOBME_b6pg8,8
|
6
|
+
appmesh-0.6.2.dist-info/RECORD,,
|
appmesh-0.6.0.dist-info/RECORD
DELETED
@@ -1,6 +0,0 @@
|
|
1
|
-
appmesh/__init__.py,sha256=xRdXeFHEieRauuJZElbEBASgXG0ZzU1a5_0isAhM7Gw,11
|
2
|
-
appmesh/appmesh_client.py,sha256=pj3uv-ieW4V2vM_yU2Vs5tx41oT7M44cOhOAXYmQAa8,52537
|
3
|
-
appmesh-0.6.0.dist-info/METADATA,sha256=6x48ZMeWLlL3bpTOIoDVclCH_85p0GhxeQ8tKVGb3yw,10746
|
4
|
-
appmesh-0.6.0.dist-info/WHEEL,sha256=oiQVh_5PnQM0E3gPdiz09WCNmwiHDMaGer_elqB3coM,92
|
5
|
-
appmesh-0.6.0.dist-info/top_level.txt,sha256=-y0MNQOGJxUzLdHZ6E_Rfv5_LNCkV-GTmOBME_b6pg8,8
|
6
|
-
appmesh-0.6.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|