12
12
13
13
import json
14
14
import logging
15
- from typing import List , Optional
15
+ from typing import List , Optional , Union
16
16
17
17
import requests
18
18
@@ -45,11 +45,38 @@ def _handle_response(url: str, res: json):
45
45
46
46
47
47
def _post_request (
48
- url : str , api_key : str , params : {}, timeout : int = 20 , ** kwargs
48
+ url : str ,
49
+ api_key : str ,
50
+ params : {},
51
+ timeout : int = 20 ,
52
+ verify : Optional [Union [bool , str ]] = True ,
53
+ cert : Optional [Union [str , tuple ]] = None ,
54
+ ** kwargs ,
49
55
) -> requests .Response :
56
+ """Send a POST request with 1-way / 2-way optional certificate validation
57
+
58
+ Args:
59
+ url (str): The endpoint URL
60
+ api_key (str): API key for authentication
61
+ params (dict): JSON parameters for the request
62
+ timeout (int): Timeout for the request
63
+ verify (bool, str, optional): Either a boolean, to verify the server's TLS certificate
64
+ or a string, which must be server's certificate path. Defaults to `True`.
65
+ cert (str, tuple, optional): if String, path to ssl client cert file.
66
+ if Tuple, ('cert', 'key') pair.
67
+
68
+ Returns:
69
+ requests.Response: Response object.
70
+ """
50
71
try :
51
72
resp = requests .post (
52
- url = url , headers = _http_headers (api_key ), json = params , timeout = timeout , ** kwargs
73
+ url = url ,
74
+ headers = _http_headers (api_key ),
75
+ json = params ,
76
+ timeout = timeout ,
77
+ verify = verify ,
78
+ cert = cert ,
79
+ ** kwargs ,
53
80
)
54
81
if resp .status_code != 200 :
55
82
_throw (f"Failed to post url: { url } , status code: { resp .status_code } " )
@@ -85,6 +112,8 @@ def bulk_import(
85
112
api_key : str = "" ,
86
113
access_key : str = "" ,
87
114
secret_key : str = "" ,
115
+ verify : Optional [Union [bool , str ]] = True ,
116
+ cert : Optional [Union [str , tuple ]] = None ,
88
117
** kwargs ,
89
118
) -> requests .Response :
90
119
"""call bulkinsert restful interface to import files
@@ -103,6 +132,10 @@ def bulk_import(
103
132
api_key (str): API key to authenticate your requests.
104
133
access_key (str): access key to access the object storage
105
134
secret_key (str): secret key to access the object storage
135
+ verify (bool, str, optional): Either a boolean, to verify the server's TLS certificate
136
+ or a string, which must be server's certificate path. Defaults to `True`.
137
+ cert (str, tuple, optional): if String, path to ssl client cert file.
138
+ if Tuple, ('cert', 'key') pair.
106
139
107
140
Returns:
108
141
response of the restful interface
@@ -125,13 +158,21 @@ def bulk_import(
125
158
if isinstance (options , dict ):
126
159
params ["options" ] = options
127
160
128
- resp = _post_request (url = request_url , api_key = api_key , params = params , ** kwargs )
161
+ resp = _post_request (
162
+ url = request_url , api_key = api_key , params = params , verify = verify , cert = cert , ** kwargs
163
+ )
129
164
_handle_response (request_url , resp .json ())
130
165
return resp
131
166
132
167
133
168
def get_import_progress (
134
- url : str , job_id : str , cluster_id : str = "" , api_key : str = "" , ** kwargs
169
+ url : str ,
170
+ job_id : str ,
171
+ cluster_id : str = "" ,
172
+ api_key : str = "" ,
173
+ verify : Optional [Union [bool , str ]] = True ,
174
+ cert : Optional [Union [str , tuple ]] = None ,
175
+ ** kwargs ,
135
176
) -> requests .Response :
136
177
"""get job progress
137
178
@@ -140,6 +181,10 @@ def get_import_progress(
140
181
job_id (str): a job id
141
182
cluster_id (str): id of a milvus instance(for cloud)
142
183
api_key (str): API key to authenticate your requests.
184
+ verify (bool, str, optional): Either a boolean, to verify the server's TLS certificate
185
+ or a string, which must be server's certificate path. Defaults to `True`.
186
+ cert (str, tuple, optional): if String, path to ssl client cert file.
187
+ if Tuple, ('cert', 'key') pair.
143
188
144
189
Returns:
145
190
response of the restful interface
@@ -151,7 +196,9 @@ def get_import_progress(
151
196
"clusterId" : cluster_id ,
152
197
}
153
198
154
- resp = _post_request (url = request_url , api_key = api_key , params = params , ** kwargs )
199
+ resp = _post_request (
200
+ url = request_url , api_key = api_key , params = params , verify = verify , cert = cert , ** kwargs
201
+ )
155
202
_handle_response (request_url , resp .json ())
156
203
return resp
157
204
@@ -163,6 +210,8 @@ def list_import_jobs(
163
210
api_key : str = "" ,
164
211
page_size : int = 10 ,
165
212
current_page : int = 1 ,
213
+ verify : Optional [Union [bool , str ]] = True ,
214
+ cert : Optional [Union [str , tuple ]] = None ,
166
215
** kwargs ,
167
216
) -> requests .Response :
168
217
"""list jobs in a cluster
@@ -174,6 +223,10 @@ def list_import_jobs(
174
223
api_key (str): API key to authenticate your requests.
175
224
page_size (int): pagination size
176
225
current_page (int): pagination
226
+ verify (bool, str, optional): Either a boolean, to verify the server's TLS certificate
227
+ or a string, which must be server's certificate path. Defaults to `True`.
228
+ cert (str, tuple, optional): if String, path to ssl client cert file.
229
+ if Tuple, ('cert', 'key') pair.
177
230
178
231
Returns:
179
232
response of the restful interface
@@ -187,6 +240,8 @@ def list_import_jobs(
187
240
"currentPage" : current_page ,
188
241
}
189
242
190
- resp = _post_request (url = request_url , api_key = api_key , params = params , ** kwargs )
243
+ resp = _post_request (
244
+ url = request_url , api_key = api_key , params = params , verify = verify , cert = cert , ** kwargs
245
+ )
191
246
_handle_response (request_url , resp .json ())
192
247
return resp
0 commit comments