Models
models.base
models.base
models.document
models.document
Document
Bases: SQLModelWithID, DocumentCommon
A document is a file that can be accessed by the users of the system. Each document has a unique ID, filepath, content, and owner. The owner is the user who originally uploaded the document.
The document is stored in the file system, and the filepath is used to identify the document. The content of the document is encrypted using the Data Encryption Key (DEK) before it is stored in the file system.
Each document has a list of users who have access to the document. The access is granted using the User ID of the users. The users with access to the document can download the document.
Attributes:
| Name | Type | Description |
|---|---|---|
id |
str
|
Unique identifier for the document. |
filepath |
str
|
The filepath of the document in the file system. |
content |
bytes
|
The content of the document in bytes. |
owner_id |
str
|
The User ID of the owner of the document. |
shared_keys |
list[SharedKeyRegistry]
|
A list of SharedKeyRegistry objects that store the shared encryption keys for the document. |
uploaded_on |
datetime
|
The timestamp when the document was uploaded. |
Source code in models/document.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
get_dek(user_id, user_private_key)
Get the DEK for the given user_id, using the private key provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_id
|
str
|
The ID of the user. |
required |
user_private_key
|
bytes
|
The user's private key. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
The DEK for the document. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the document is not shared with the user or if the private key is invalid. |
Source code in models/document.py
update_shared_keys_registry(user_ids, dek)
Updates the shared keys registry for the given users.
This function updates the SharedKeyRegistry table with the given user IDs and the Data Encryption Key (DEK) for the document. The DEK is encrypted using the public key of each user and stored in the SharedKeyRegistry table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
user_ids
|
list[str]
|
A list of User IDs to update the shared keys registry for. |
required |
dek
|
bytes
|
The Data Encryption Key (DEK) to store in the SharedKeyRegistry table. The DEK is encrypted using the public key of each user before it is stored. |
required |
Source code in models/document.py
DocumentBase
Bases: DocumentDownloadResponse
Base model for creating new documents.
This model is used to create new documents in the system. It contains the essential information required to create a document, such as the filepath and content of the document.
Source code in models/document.py
DocumentCommon
Bases: SQLModel
Common fields for Document and DocumentBase models.
This class serves as a base for storing common attributes related to documents. It provides a standardized way to define the essential properties required for handling documents within the system. The attributes defined here are shared among different document models to ensure consistency.
Attributes:
| Name | Type | Description |
|---|---|---|
filepath |
str
|
The filepath of the document. This is used to locate the document in the storage system. The path is indexed to improve the performance of queries that filter or sort based on the document's path. |
owner_id |
str
|
The User ID of the owner of the document. This field establishes an ownership link between the document and a user in the system. It uses a foreign key reference to ensure that the owner_id corresponds to a valid user in the database. |
Source code in models/document.py
DocumentDownloadResponse
Bases: DocumentCommon
Document download response model.
This model is used to represent a document that is being downloaded from the server. It contains the filepath and content of the document.
Source code in models/document.py
DocumentShareResponse
Bases: DocumentCommon
Document share response model.
This model is used to represent a document that is being shared with another user.
Source code in models/document.py
SharedKeyRegistry
Bases: SQLModel
Stores the shared encryption keys for a given document and user pair.
The shared key is encrypted using the user's public key, and can be decrypted by the user using their private key. This allows the user to access the document without having to be re-shared the document.
The shared key is stored in the database as a binary blob, and is encrypted using the user's public key. This means that only the user who the document is shared with can decrypt the shared key.
Attributes:
| Name | Type | Description |
|---|---|---|
user_id |
str
|
The User ID of the user the document is shared with. |
document_id |
str
|
The Document ID of the document that is shared. |
shared_key |
bytes
|
The encrypted shared key. |
created_at |
datetime
|
The timestamp when the shared key was created. |
document |
Document
|
The document that is shared. |
user |
User
|
The user that the document is shared with. |
Source code in models/document.py
models.enums
models.enums
models.user
models.user
User
Bases: UserBase
Source code in models/user.py
verify_private_key(password)
Verifies that the given private key matches the public key of the user. Returns True if the key is valid, False otherwise.