Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 47e0e828

Přidáno uživatelem David Friesecký před asi 4 roky(ů)

Re #8471 - Added FK of parent certificate

Zobrazit rozdíly:

SQLite_database.sql
1 1
/* ---------------------------------------------------- */
2 2
/*  Generated by Enterprise Architect Version 13.5 		*/
3
/*  Created On : 31-b?e-2021 10:24:41 				*/
3
/*  Created On : 31-b?e-2021 13:28:01 				*/
4 4
/*  DBMS       : SQLite 								*/
5 5
/* ---------------------------------------------------- */
6 6

  
......
54 54
	'pem_data' TEXT NOT NULL,
55 55
	'private_key_id' INTEGER NOT NULL,
56 56
	'certificate_type_id' INTEGER NOT NULL,
57
	'parent_certificate_id' INTEGER NOT NULL,
58
	CONSTRAINT 'FK_Certificates' FOREIGN KEY ('parent_certificate_id') REFERENCES 'Certificates' ('id') ON DELETE No Action ON UPDATE No Action,
57 59
	CONSTRAINT 'FK_CertificateTypes' FOREIGN KEY ('certificate_type_id') REFERENCES 'CertificateTypes' ('id') ON DELETE No Action ON UPDATE No Action,
58 60
	CONSTRAINT 'FK_PrivateKeys' FOREIGN KEY ('private_key_id') REFERENCES 'PrivateKeys' ('id') ON DELETE No Action ON UPDATE No Action
59 61
)
src/constants.py
26 26
COL_PEM_DATA = "pem_data"
27 27
COL_PRIVATE_KEY_ID = "private_key_id"
28 28
COL_TYPE_ID = "certificate_type_id"
29
COL_PARENT_ID = "parent_certificate_id"
29 30

  
30 31
# DB column names of PrivateKeys table
31 32
COL_PRIVATE_KEY = "private_key"
src/db_objects/certificate.py
11 11
                 pem_data: str,
12 12
                 private_key_id: int,
13 13
                 type_id: int,
14
                 parent_id: int,
14 15
                 usages: Dict[int, bool]):
15 16
        self.certificate_id: int = certificate_id
16 17
        self.common_name: str = common_name
......
19 20
        self.pem_data: str = pem_data
20 21
        self.private_key_id: int = private_key_id
21 22
        self.type_id: int = type_id
23
        self.parent_id: int = parent_id
22 24
        self.usages: Dict[int, bool] = DICT_USAGES.copy()
23 25

  
24 26
        for usage_id, usage_value in usages.items():
src/impl/certificate_repository_impl.py
9 9
class CertificateRepositoryImpl(IRepository):
10 10

  
11 11
    def create(self, common_name: str, valid_from: str, valid_to: str, pem_data: str,
12
               private_key_id: int, type_id: int, usages: Dict[int, bool]) -> bool:
12
               private_key_id: int, type_id: int, parent_id: int, usages: Dict[int, bool]) -> bool:
13 13
        sql = (f"INSERT INTO {TAB_CERTIFICATES} ({COL_COMMON_NAME},{COL_VALID_FROM},{COL_VALID_TO},{COL_PEM_DATA},"
14
               f"{COL_PRIVATE_KEY_ID},{COL_TYPE_ID})"
14
               f"{COL_PRIVATE_KEY_ID},{COL_TYPE_ID},{COL_PARENT_ID})"
15 15
               f"VALUES(?,?,?,?,?,?,?)")
16
        result = DBManager.create(sql, [common_name, valid_from, valid_to, pem_data, private_key_id, type_id], usages)
16
        result = DBManager.create(sql, [common_name, valid_from, valid_to, pem_data,
17
                                        private_key_id, type_id, parent_id], usages)
17 18
        return result
18 19

  
19 20
    def read(self, certificate_id: int = None):
......
42 43
                                            certificate_row[4],
43 44
                                            certificate_row[5],
44 45
                                            certificate_row[6],
46
                                            certificate_row[7],
45 47
                                            usage_dict))
46 48

  
47 49
        if certificate_id is not None:
......
50 52
        return certificates
51 53

  
52 54
    def update(self, certificate_id: int, common_name: str = None, valid_from: str = None, valid_to: str = None,
53
               pem_data: str = None, private_key_id: int = None, type_id: int = None,
55
               pem_data: str = None, private_key_id: int = None, type_id: int = None, parent_id: int = None,
54 56
               usages: Dict[int, bool] = None) -> bool:
55 57
        updated_list = []
56 58
        values = []
......
72 74
        if type_id is not None:
73 75
            updated_list.append(f"{COL_TYPE_ID} = ?")
74 76
            values.append(type_id)
77
        if parent_id is not None:
78
            updated_list.append(f"{COL_PARENT_ID} = ?")
79
            values.append(parent_id)
75 80

  
76 81
        updated_str = ", ".join(updated_list)
77 82
        sql = f"UPDATE {TAB_CERTIFICATES} SET {updated_str} WHERE {COL_ID} = ?"

Také k dispozici: Unified diff