Revize ef65f488
Přidáno uživatelem Stanislav Král před asi 4 roky(ů)
src/services/certificate_service.py | ||
---|---|---|
1 |
from typing import List |
|
2 |
|
|
1 | 3 |
from src.constants import ROOT_CA_ID, INTERMEDIATE_CA_ID, CA_ID, CERTIFICATE_ID |
2 | 4 |
from src.dao.certificate_repository import CertificateRepository |
3 | 5 |
from src.model.certificate import Certificate |
... | ... | |
123 | 125 |
def get_certificate(self, unique_id: int) -> Certificate: |
124 | 126 |
return self.certificate_repository.read(unique_id) |
125 | 127 |
|
126 |
def get_certificates(self, cert_type=None) -> Certificate:
|
|
128 |
def get_certificates(self, cert_type=None) -> List[Certificate]:
|
|
127 | 129 |
return self.certificate_repository.read_all(cert_type) |
130 |
|
|
131 |
def get_chain_of_trust(self, from_id: int, to_id: int = -1, exclude_root=True) -> List[Certificate]: |
|
132 |
start_cert = self.certificate_repository.read(from_id) |
|
133 |
|
|
134 |
if start_cert is None or (start_cert.type_id == ROOT_CA_ID and exclude_root): |
|
135 |
return [] |
|
136 |
|
|
137 |
current_cert = start_cert |
|
138 |
chain_of_trust = [current_cert] |
|
139 |
|
|
140 |
# TODO could possibly be simplified |
|
141 |
if start_cert.type_id == ROOT_CA_ID: |
|
142 |
return chain_of_trust |
|
143 |
|
|
144 |
while True: |
|
145 |
parent_cert = self.certificate_repository.read(current_cert.parent_id) |
|
146 |
|
|
147 |
# check whether parent certificate |
|
148 |
if parent_cert is None or parent_cert.type_id == ROOT_CA_ID: |
|
149 |
if not exclude_root: |
|
150 |
chain_of_trust.append(parent_cert) |
|
151 |
break |
|
152 |
|
|
153 |
chain_of_trust.append(parent_cert) |
|
154 |
|
|
155 |
if parent_cert.certificate_id == to_id: |
|
156 |
break |
|
157 |
|
|
158 |
current_cert = parent_cert |
|
159 |
|
|
160 |
return chain_of_trust |
Také k dispozici: Unified diff
Re #8472 - Implemented get_chain_of_trust method and added an integration test validating it
Added return type specification to read_all method in CertificateRepository