Revize a0602bad
Přidáno uživatelem David Friesecký před asi 4 roky(ů)
src/impl/certificate_repository_impl.py | ||
---|---|---|
10 | 10 |
|
11 | 11 |
def create(self, common_name: str, valid_from: str, valid_to: str, pem_data: str, |
12 | 12 |
private_key_id: int, type_id: int, parent_id: int, usages: Dict[int, bool]) -> bool: |
13 |
""" |
|
14 |
Creates a certificate |
|
15 |
|
|
16 |
:param common_name: private key of the certificate |
|
17 |
:param valid_from: string of date (time) of validation after (from) |
|
18 |
:param valid_to: string of date (time) of validation before (to) |
|
19 |
:param pem_data: data of certificate in a PEM format |
|
20 |
:param private_key_id: ID from PrivateKeys table for specific private key |
|
21 |
:param type_id: ID from CertificateTypes table (ROOT_CA_ID=1, INTERMEDIATE_CA_ID=2, CERTIFICATE_ID=3) |
|
22 |
:param parent_id: ID from Certificates table for specific parent certificate |
|
23 |
for root CA use e.g. -1 (ID will be changed after created certificate) |
|
24 |
:param usages: dictionary of usages IDs which certificate use |
|
25 |
Dictionary[Integer, Boolean] |
|
26 |
- Key = ID (CA_ID=1, SSL_ID=2, SIGNATURE_ID=3, AUTHENTICATION_ID=4) |
|
27 |
- Value = used=True/unused=False |
|
28 |
|
|
29 |
:return: the result of whether the creation was successful |
|
30 |
""" |
|
31 |
|
|
13 | 32 |
sql = (f"INSERT INTO {TAB_CERTIFICATES} ({COL_COMMON_NAME},{COL_VALID_FROM},{COL_VALID_TO},{COL_PEM_DATA}," |
14 | 33 |
f"{COL_PRIVATE_KEY_ID},{COL_TYPE_ID},{COL_PARENT_ID})" |
15 | 34 |
f"VALUES(?,?,?,?,?,?,?)") |
... | ... | |
18 | 37 |
return result |
19 | 38 |
|
20 | 39 |
def read(self, certificate_id: int = None): |
40 |
""" |
|
41 |
Reads (selects) a certificate or certificates |
|
42 |
|
|
43 |
:param certificate_id: ID of specific certificate |
|
44 |
|
|
45 |
:return: instance of Certificate class if ID was used otherwise list of this instances |
|
46 |
""" |
|
47 |
|
|
21 | 48 |
sql_extend = "" |
22 | 49 |
|
23 | 50 |
if certificate_id is not None: |
... | ... | |
54 | 81 |
def update(self, certificate_id: int, common_name: str = None, valid_from: str = None, valid_to: str = None, |
55 | 82 |
pem_data: str = None, private_key_id: int = None, type_id: int = None, parent_id: int = None, |
56 | 83 |
usages: Dict[int, bool] = None) -> bool: |
84 |
""" |
|
85 |
Updates a certificate |
|
86 |
|
|
87 |
:param certificate_id: ID of specific certificate |
|
88 |
:param common_name: private key of the certificate |
|
89 |
:param valid_from: string of date (time) of validation after (from) |
|
90 |
:param valid_to: string of date (time) of validation before (to) |
|
91 |
:param pem_data: data of certificate in a PEM format |
|
92 |
:param private_key_id: ID from PrivateKeys table for specific private key |
|
93 |
:param type_id: ID from CertificateTypes table (ROOT_CA_ID=1, INTERMEDIATE_CA_ID=2, CERTIFICATE_ID=3) |
|
94 |
:param parent_id: ID from Certificates table for specific parent certificate |
|
95 |
for root CA use e.g. -1 (ID will be changed after created certificate) |
|
96 |
:param usages: dictionary of usages IDs which certificate use |
|
97 |
Dictionary[Integer, Boolean] |
|
98 |
- Key = ID (CA_ID=1, SSL_ID=2, SIGNATURE_ID=3, AUTHENTICATION_ID=4) |
|
99 |
- Value = used=True/unused=False |
|
100 |
|
|
101 |
:return: the result of whether the updation was successful |
|
102 |
""" |
|
103 |
|
|
57 | 104 |
updated_list = [] |
58 | 105 |
values = [] |
59 | 106 |
if common_name is not None: |
... | ... | |
84 | 131 |
return result |
85 | 132 |
|
86 | 133 |
def delete(self, certificate_id: int) -> bool: |
134 |
""" |
|
135 |
Deletes a certificate |
|
136 |
|
|
137 |
:param certificate_id: ID of specific certificate |
|
138 |
|
|
139 |
:return: the result of whether the deletion was successful |
|
140 |
""" |
|
141 |
|
|
87 | 142 |
sql = f"DELETE FROM {TAB_CERTIFICATES} WHERE {COL_ID} = ?" |
88 | 143 |
result = DBManager.delete(sql, certificate_id, True) |
89 | 144 |
return result |
Také k dispozici: Unified diff
Re #8471 - Added comments for CRUD functions