Revize afbdc84f
Přidáno uživatelem Michal Seják před asi 4 roky(ů)
src/controllers/certificates_controller.py | ||
---|---|---|
29 | 29 |
SUBJECT = "subject" |
30 | 30 |
VALIDITY_DAYS = "validityDays" |
31 | 31 |
CA = "CA" |
32 |
ISSUED_BY = "issuedby" |
|
32 | 33 |
STATUS = "status" |
33 | 34 |
REASON = "reason" |
34 | 35 |
REASON_UNDEFINED = "unspecified" |
... | ... | |
161 | 162 |
cert = self.certificate_service.get_certificate(v) |
162 | 163 |
|
163 | 164 |
if cert is None: |
164 |
return E_NO_CERTIFICATES_FOUND, C_NO_DATA
|
|
165 |
return E_NO_CERTIFICATES_FOUND, C_NO_DATA |
|
165 | 166 |
else: |
166 | 167 |
return {"success": True, "data": cert.pem_data}, C_SUCCESS |
167 | 168 |
|
... | ... | |
183 | 184 |
cert = self.certificate_service.get_certificate(v) |
184 | 185 |
|
185 | 186 |
if cert is None: |
186 |
return E_NO_CERTIFICATES_FOUND, C_NO_DATA
|
|
187 |
return E_NO_CERTIFICATES_FOUND, C_NO_DATA |
|
187 | 188 |
else: |
188 | 189 |
data = self.cert_to_dict_full(cert) |
189 | 190 |
if data is None: |
... | ... | |
201 | 202 |
:rtype: CertificateListResponse |
202 | 203 |
""" |
203 | 204 |
targets = {ROOT_CA_ID, INTERMEDIATE_CA_ID, CERTIFICATE_ID} # all targets |
205 |
issuer_id = -1 |
|
204 | 206 |
|
205 | 207 |
# the filtering parameter can be read as URL argument or as a request body |
206 |
if request.is_json or "filtering" in request.args.keys(): # if the request carries JSON data
|
|
208 |
if request.is_json or FILTERING in request.args.keys(): # if the request carries JSON data
|
|
207 | 209 |
if request.is_json: |
208 | 210 |
data = request.get_json() # get it |
209 | 211 |
else: |
210 | 212 |
try: |
211 |
data = {"filtering": json.loads(request.args["filtering"])}
|
|
213 |
data = {FILTERING: json.loads(request.args[FILTERING])}
|
|
212 | 214 |
except JSONDecodeError: |
213 | 215 |
return E_NOT_JSON_FORMAT, C_BAD_REQUEST |
214 | 216 |
|
... | ... | |
223 | 225 |
targets.remove(INTERMEDIATE_CA_ID) |
224 | 226 |
else: |
225 | 227 |
return E_WRONG_PARAMETERS, C_BAD_REQUEST |
228 |
if ISSUED_BY in data[FILTERING]: # containing 'issuedby' |
|
229 |
if isinstance(data[FILTERING][ISSUED_BY], int): # which is an 'int' |
|
230 |
issuer_id = data[FILTERING][ISSUED_BY] # then get its children only |
|
226 | 231 |
else: |
227 | 232 |
return E_WRONG_PARAMETERS, C_BAD_REQUEST |
233 |
if issuer_id >= 0: # if filtering by an issuer |
|
234 |
try: |
|
235 |
children = self.certificate_service.get_certificates_issued_by(issuer_id) # get his children |
|
236 |
except CertificateNotFoundException: # if id does not exist |
|
237 |
return E_NO_CERTIFICATES_FOUND, C_NOT_FOUND # throw |
|
228 | 238 |
|
229 |
if len(targets) == TREE_NODE_TYPE_COUNT: # = 3 -> root node, |
|
239 |
certs = [child for child in children if child.type_id in targets] |
|
240 |
|
|
241 |
elif len(targets) == TREE_NODE_TYPE_COUNT: # = 3 -> root node, |
|
230 | 242 |
# intermediate node, |
231 | 243 |
# or leaf node |
232 | 244 |
|
233 | 245 |
# if filtering did not change the |
234 | 246 |
# targets, |
235 |
certs = self.certificate_service.get_certificates() # fetch everything |
|
236 |
else: # otherwise fetch targets only |
|
237 |
certs = list(chain(*(self.certificate_service.get_certificates(target) for target in targets))) |
|
247 |
certs = self.certificate_service.get_certificates() # fetch everything |
|
248 |
else: # otherwise fetch targets only |
|
249 |
certs = list(chain(*(self.certificate_service.get_certificates(target) for target in targets))) |
|
250 |
else: |
|
251 |
certs = self.certificate_service.get_certificates() # if no params, fetch everything |
|
238 | 252 |
|
239 | 253 |
if certs is None: |
240 | 254 |
return E_GENERAL_ERROR, C_INTERNAL_SERVER_ERROR |
241 |
elif len(certs) == 0: |
|
242 |
return E_NO_CERTIFICATES_FOUND, C_NO_DATA |
|
243 | 255 |
else: |
244 | 256 |
ret = [] |
245 | 257 |
for c in certs: |
... | ... | |
296 | 308 |
cert = self.certificate_service.get_certificate(v) |
297 | 309 |
|
298 | 310 |
if cert is None: |
299 |
return E_NO_CERTIFICATES_FOUND, C_NO_DATA
|
|
311 |
return E_NO_CERTIFICATES_FOUND, C_NO_DATA |
|
300 | 312 |
|
301 | 313 |
if cert.parent_id is None: |
302 | 314 |
return E_NO_CERTIFICATES_FOUND, C_NO_DATA |
Také k dispozici: Unified diff
Re #8574 - Extended the `get_certificate_list` method of CertificateController to reflect the filtering query 'issuedby' update.