divbase-lib 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- divbase_lib/__init__.py +1 -0
- divbase_lib/api_schemas/__init__.py +0 -0
- divbase_lib/api_schemas/announcements.py +18 -0
- divbase_lib/api_schemas/auth.py +37 -0
- divbase_lib/api_schemas/personal_access_tokens.py +42 -0
- divbase_lib/api_schemas/project_versions.py +90 -0
- divbase_lib/api_schemas/queries.py +210 -0
- divbase_lib/api_schemas/s3.py +359 -0
- divbase_lib/api_schemas/task_history.py +51 -0
- divbase_lib/api_schemas/vcf_dimensions.py +67 -0
- divbase_lib/divbase_constants.py +66 -0
- divbase_lib/exceptions.py +154 -0
- divbase_lib/metadata_validator.py +827 -0
- divbase_lib/s3_checksums.py +120 -0
- divbase_lib/utils.py +133 -0
- divbase_lib-0.1.0.dist-info/METADATA +38 -0
- divbase_lib-0.1.0.dist-info/RECORD +18 -0
- divbase_lib-0.1.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Schemas for DivBase's S3 API routes.
|
|
3
|
+
|
|
4
|
+
Pre-signed download URLs do not need to account for single vs multipart as this can be controlled by the client
|
|
5
|
+
using the HTTP range header when downloading (so you only need 1 pre-signed URL per object for download).
|
|
6
|
+
|
|
7
|
+
Pre-signed upload URLs need to account for single vs multipart uploads hence all the extra schemas below.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from datetime import datetime
|
|
11
|
+
|
|
12
|
+
from pydantic import BaseModel, Field, field_validator
|
|
13
|
+
|
|
14
|
+
from divbase_lib.divbase_constants import (
|
|
15
|
+
MAX_S3_API_BATCH_SIZE,
|
|
16
|
+
S3_MULTIPART_CHUNK_SIZE,
|
|
17
|
+
SUPPORTED_DIVBASE_FILE_TYPES,
|
|
18
|
+
SUPPORTED_DIVBASE_FILE_TYPES_DISPLAY,
|
|
19
|
+
UNSUPPORTED_CHARACTERS_DISPLAY,
|
|
20
|
+
UNSUPPORTED_CHARACTERS_IN_FILENAMES,
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
MB = 1024 * 1024
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def validate_s3_object_name(name: str) -> str:
|
|
27
|
+
"""Validate that the S3 object name does not contain unsupported characters."""
|
|
28
|
+
if name.startswith("/") or name.endswith("/"):
|
|
29
|
+
raise ValueError("Object name must not start or end with a '/'.")
|
|
30
|
+
if not any(name.endswith(ext) for ext in SUPPORTED_DIVBASE_FILE_TYPES):
|
|
31
|
+
raise ValueError(f"Object name must be one of the supported file types: {SUPPORTED_DIVBASE_FILE_TYPES_DISPLAY}")
|
|
32
|
+
if any(part in (".", "..") for part in name.split("/")):
|
|
33
|
+
raise ValueError("Object name cannot contain '.' or '..' as a folder path or file name.")
|
|
34
|
+
for char in UNSUPPORTED_CHARACTERS_IN_FILENAMES:
|
|
35
|
+
if char in name:
|
|
36
|
+
raise ValueError(
|
|
37
|
+
f"Object name contains unsupported characters. Unsupported: {UNSUPPORTED_CHARACTERS_DISPLAY}"
|
|
38
|
+
)
|
|
39
|
+
return name
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def validate_s3_directory_name(name: str) -> str:
|
|
43
|
+
"""Validate + clean a S3 directory name."""
|
|
44
|
+
if name.startswith("/"):
|
|
45
|
+
name = name[1:]
|
|
46
|
+
if not name.endswith("/"):
|
|
47
|
+
name = f"{name}/"
|
|
48
|
+
|
|
49
|
+
stripped = name.strip("/")
|
|
50
|
+
if not stripped:
|
|
51
|
+
raise ValueError("Directory name cannot be empty or '/'.")
|
|
52
|
+
|
|
53
|
+
if any(part in (".", "..") for part in name.split("/")):
|
|
54
|
+
raise ValueError(f"Directory '{name}' cannot contain '.' or '..' as a folder path.")
|
|
55
|
+
|
|
56
|
+
for char in UNSUPPORTED_CHARACTERS_IN_FILENAMES:
|
|
57
|
+
if char in name:
|
|
58
|
+
raise ValueError(
|
|
59
|
+
f"Directory name contains unsupported characters. Unsupported: {UNSUPPORTED_CHARACTERS_DISPLAY}"
|
|
60
|
+
)
|
|
61
|
+
return name
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def validate_s3_object_prefix(prefix: str | None) -> str | None:
|
|
65
|
+
"""Validate that the S3 object prefix does not contain unsupported characters."""
|
|
66
|
+
if not prefix:
|
|
67
|
+
return None
|
|
68
|
+
if any(part in (".", "..") for part in prefix.split("/")):
|
|
69
|
+
raise ValueError(f"Prefix '{prefix}' cannot contain '.' or '..' as a path segment.")
|
|
70
|
+
for char in UNSUPPORTED_CHARACTERS_IN_FILENAMES:
|
|
71
|
+
if char in prefix:
|
|
72
|
+
raise ValueError(f"Prefix contains unsupported characters. Unsupported: {UNSUPPORTED_CHARACTERS_DISPLAY}")
|
|
73
|
+
return prefix
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
## list objects models ##
|
|
77
|
+
class ObjectDetails(BaseModel):
|
|
78
|
+
"""Details about a single object in an S3 bucket."""
|
|
79
|
+
|
|
80
|
+
name: str = Field(..., description="The name of the object in the bucket.")
|
|
81
|
+
size: int = Field(..., description="The size of the object in bytes.")
|
|
82
|
+
last_modified: datetime = Field(..., description="The date and time the object was last modified.")
|
|
83
|
+
etag: str = Field(..., description="The ETag of the object, which is the MD5 checksum.")
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
class ListObjectsRequest(BaseModel):
|
|
87
|
+
"""Request model for listing objects in an S3 bucket."""
|
|
88
|
+
|
|
89
|
+
prefix: str | None = Field(None, description="Optional prefix to filter objects by name.")
|
|
90
|
+
delimiter: str | None = Field(
|
|
91
|
+
None,
|
|
92
|
+
description="Delimiter for simulating a file-system view. Use '/' to do this. Leave as none to recursively list all files.",
|
|
93
|
+
)
|
|
94
|
+
next_token: str | None = Field(
|
|
95
|
+
None, description="Token to continue listing files from the end of a previous request."
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
@field_validator("prefix")
|
|
99
|
+
@classmethod
|
|
100
|
+
def validate_prefix(cls, prefix: str | None) -> str | None:
|
|
101
|
+
return validate_s3_object_prefix(prefix)
|
|
102
|
+
|
|
103
|
+
@field_validator("delimiter")
|
|
104
|
+
@classmethod
|
|
105
|
+
def validate_delimiter(cls, delimiter: str | None) -> str | None:
|
|
106
|
+
if delimiter is not None and delimiter != "/":
|
|
107
|
+
raise ValueError("Delimiter must be either None or '/'.")
|
|
108
|
+
return delimiter
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
class ListObjectsResponse(BaseModel):
|
|
112
|
+
"""
|
|
113
|
+
Response model for listing objects in an S3 bucket.
|
|
114
|
+
|
|
115
|
+
When delimiter is omitted: files contains all matching objects, folders is always empty.
|
|
116
|
+
When delimiter='/' is used: files contains objects at the current level only, folders contains
|
|
117
|
+
common prefixes (simulated directories).
|
|
118
|
+
"""
|
|
119
|
+
|
|
120
|
+
files: list[ObjectDetails] = Field(
|
|
121
|
+
...,
|
|
122
|
+
description="Files at this level (or all files when no delimiter is used).",
|
|
123
|
+
min_length=0,
|
|
124
|
+
max_length=1000,
|
|
125
|
+
)
|
|
126
|
+
folders: list[str] = Field(
|
|
127
|
+
...,
|
|
128
|
+
description="Simulated folder prefixes. Only populated when a delimiter is used.",
|
|
129
|
+
min_length=0,
|
|
130
|
+
max_length=1000,
|
|
131
|
+
)
|
|
132
|
+
next_token: str | None = Field(
|
|
133
|
+
None, description="Token for fetching the next page of results. If None, no more results."
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
## list soft-deleted objects models ##
|
|
138
|
+
class ListDeletedObjectsRequest(BaseModel):
|
|
139
|
+
"""Request model for listing soft-deleted objects in an S3 bucket."""
|
|
140
|
+
|
|
141
|
+
prefix: str | None = Field(None, description="Optional prefix to filter objects by name.")
|
|
142
|
+
|
|
143
|
+
@field_validator("prefix")
|
|
144
|
+
@classmethod
|
|
145
|
+
def validate_prefix(cls, prefix: str | None) -> str | None:
|
|
146
|
+
return validate_s3_object_prefix(prefix)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
class SoftDeletedObjectDetails(BaseModel):
|
|
150
|
+
"""Details about a single soft-deleted object in an S3 bucket."""
|
|
151
|
+
|
|
152
|
+
name: str = Field(..., description="The name of the object in the bucket.")
|
|
153
|
+
last_modified: datetime = Field(..., description="The date and time the object was deleted.")
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
## file info models ##
|
|
157
|
+
class ObjectVersionInfo(BaseModel):
|
|
158
|
+
"""Detailed information about a single version of an S3 object."""
|
|
159
|
+
|
|
160
|
+
version_id: str = Field(..., description="The version ID of the object.")
|
|
161
|
+
last_modified: datetime = Field(..., description="The date and time the object version was last modified.")
|
|
162
|
+
size: int = Field(..., description="The size of the object in bytes.")
|
|
163
|
+
etag: str = Field(..., description="The ETag of the object, which is the MD5 checksum.")
|
|
164
|
+
is_latest: bool = Field(..., description="Indicates if this is the latest version of the object.")
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
class ObjectInfoResponse(BaseModel):
|
|
168
|
+
"""Response model for detailed information about all versions of a single object stored in S3."""
|
|
169
|
+
|
|
170
|
+
object_name: str = Field(..., description="The name of the object.")
|
|
171
|
+
is_currently_deleted: bool = Field(..., description="True if the latest version of the object is a delete marker.")
|
|
172
|
+
versions: list[ObjectVersionInfo] = Field(..., description="A list of all versions of the object.")
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
## download models ##
|
|
176
|
+
class DownloadObjectRequest(BaseModel):
|
|
177
|
+
"""Request model to download a single object using a pre-signed URL."""
|
|
178
|
+
|
|
179
|
+
name: str = Field(..., description="Name of the object to be downloaded")
|
|
180
|
+
version_id: str | None = Field(None, description="Version ID of the object, None if latest version")
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
class PreSignedDownloadResponse(BaseModel):
|
|
184
|
+
"""Response model to download a single object using the pre-signed URL and (optionally) version ID."""
|
|
185
|
+
|
|
186
|
+
name: str = Field(..., description="Name of the object to be downloaded")
|
|
187
|
+
pre_signed_url: str = Field(..., description="Pre-signed URL for downloading the object")
|
|
188
|
+
version_id: str | None = Field(None, description="Version ID of the object, None if latest version")
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
### Single-part upload models ###
|
|
192
|
+
class UploadSinglePartObjectRequest(BaseModel):
|
|
193
|
+
"""Request model to upload a single object as a single part using a pre-signed URL."""
|
|
194
|
+
|
|
195
|
+
name: str = Field(..., min_length=3, max_length=255, description="Name of the object to be uploaded")
|
|
196
|
+
content_length: int = Field(..., ge=0, description="Size of the file in bytes")
|
|
197
|
+
md5_hash: str | None = Field(None, description="Optional MD5 hash of the object for integrity check")
|
|
198
|
+
|
|
199
|
+
@field_validator("name")
|
|
200
|
+
@classmethod
|
|
201
|
+
def validate_s3_name(cls, name: str) -> str:
|
|
202
|
+
return validate_s3_object_name(name)
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
class PreSignedSinglePartUploadResponse(BaseModel):
|
|
206
|
+
"""Response model to upload a single object as a single part using the pre-signed URL using PUT."""
|
|
207
|
+
|
|
208
|
+
name: str = Field(..., description="Name of the object to be uploaded")
|
|
209
|
+
pre_signed_url: str = Field(..., description="Pre-signed URL to which the file should be uploaded")
|
|
210
|
+
put_headers: dict[str, str] = Field(..., description="Headers to be included in the PUT request")
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
### Multipart upload models ###
|
|
214
|
+
class CreateMultipartUploadRequest(BaseModel):
|
|
215
|
+
"""Request model to create a multipart upload using pre-signed URLs."""
|
|
216
|
+
|
|
217
|
+
name: str = Field(..., min_length=3, max_length=255, description="Name of the object to be uploaded")
|
|
218
|
+
content_length: int = Field(..., ge=0, description="Size of the file in bytes")
|
|
219
|
+
|
|
220
|
+
@field_validator("name")
|
|
221
|
+
@classmethod
|
|
222
|
+
def validate_s3_name(cls, name: str) -> str:
|
|
223
|
+
return validate_s3_object_name(name)
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
class CreateMultipartUploadResponse(BaseModel):
|
|
227
|
+
"""Response model to create a multipart upload using pre-signed URLs."""
|
|
228
|
+
|
|
229
|
+
name: str = Field(..., description="Name of the object to be uploaded")
|
|
230
|
+
upload_id: str = Field(..., description="Upload ID for the multipart upload")
|
|
231
|
+
number_of_parts: int = Field(..., description="Total number of parts required for the upload", ge=1, le=10000)
|
|
232
|
+
part_size: int = Field(
|
|
233
|
+
S3_MULTIPART_CHUNK_SIZE, description="Size of each part in bytes (the last part may be smaller)."
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
|
|
237
|
+
class GetPresignedPartUrlsRequest(BaseModel):
|
|
238
|
+
"""
|
|
239
|
+
Request model to get pre-signed URLs for multiple parts of a presigned multipart upload.
|
|
240
|
+
|
|
241
|
+
You can request up to 100 parts at a time.
|
|
242
|
+
Part number indexing is 1-based (with max allowed range: 1 to 10000).
|
|
243
|
+
"""
|
|
244
|
+
|
|
245
|
+
name: str = Field(..., description="Name of the object to be uploaded")
|
|
246
|
+
upload_id: str = Field(..., description="Upload ID for the multipart upload")
|
|
247
|
+
parts_range_start: int = Field(..., description="Starting part number", ge=1, le=10000)
|
|
248
|
+
parts_range_end: int = Field(..., description="Ending part number", ge=1, le=10000)
|
|
249
|
+
md5_checksums: list[str] | None = Field(
|
|
250
|
+
None, description="Optional list of MD5 checksums for each part to be uploaded"
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
class PresignedUploadPartUrlResponse(BaseModel):
|
|
255
|
+
"""Response model for a pre-signed URL for a single part of a multipart upload."""
|
|
256
|
+
|
|
257
|
+
part_number: int = Field(..., description="Part number", ge=1, le=10000)
|
|
258
|
+
pre_signed_url: str = Field(..., description="Pre-signed URL for uploading this part")
|
|
259
|
+
headers: dict[str, str] = Field(..., description="Headers to be included in the PUT request for this part")
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
class UploadedPart(BaseModel):
|
|
263
|
+
"""Model representing a part of an object that has been uploaded via multi-part upload."""
|
|
264
|
+
|
|
265
|
+
part_number: int = Field(..., description="Part number", ge=1, le=10000)
|
|
266
|
+
etag: str = Field(description="ETag returned by S3 after uploading the part")
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
class CompleteMultipartUploadRequest(BaseModel):
|
|
270
|
+
"""Request model to complete a multipart upload using pre-signed URLs."""
|
|
271
|
+
|
|
272
|
+
name: str = Field(..., description="Name of the object to be uploaded")
|
|
273
|
+
upload_id: str = Field(..., description="Upload ID for the multipart upload")
|
|
274
|
+
parts: list[UploadedPart] = Field(..., description="List of parts that have been uploaded")
|
|
275
|
+
|
|
276
|
+
|
|
277
|
+
class CompleteMultipartUploadResponse(BaseModel):
|
|
278
|
+
"""Response model to complete a multipart upload using pre-signed URLs."""
|
|
279
|
+
|
|
280
|
+
name: str = Field(..., description="Name of the object that was uploaded")
|
|
281
|
+
version_id: str = Field(..., description="Version ID of the uploaded object")
|
|
282
|
+
md5_hash: str = Field(..., description="MD5 hash of the uploaded object")
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
class AbortMultipartUploadRequest(BaseModel):
|
|
286
|
+
"""Request model to abort a multipart upload and clean up parts."""
|
|
287
|
+
|
|
288
|
+
name: str = Field(..., description="Name of the object being uploaded")
|
|
289
|
+
upload_id: str = Field(..., description="Upload ID for the multipart upload to be aborted")
|
|
290
|
+
|
|
291
|
+
|
|
292
|
+
class AbortMultipartUploadResponse(BaseModel):
|
|
293
|
+
"""Response model to abort a multipart upload."""
|
|
294
|
+
|
|
295
|
+
name: str = Field(..., description="Name of the object being uploaded")
|
|
296
|
+
upload_id: str = Field(..., description="Upload ID for the multipart upload that was aborted")
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
### make directories models (remove directories done by standard soft delete) ###
|
|
300
|
+
class MakeDirectoriesRequest(BaseModel):
|
|
301
|
+
"""Request model for making directories in the bucket."""
|
|
302
|
+
|
|
303
|
+
directories: list[str] = Field(
|
|
304
|
+
...,
|
|
305
|
+
description=("List of directories to be created."),
|
|
306
|
+
min_length=1,
|
|
307
|
+
max_length=MAX_S3_API_BATCH_SIZE,
|
|
308
|
+
)
|
|
309
|
+
|
|
310
|
+
@field_validator("directories")
|
|
311
|
+
@classmethod
|
|
312
|
+
def validate_directories(cls, directories: list[str]) -> list[str]:
|
|
313
|
+
cleaned = []
|
|
314
|
+
for name in directories:
|
|
315
|
+
cleaned.append(validate_s3_directory_name(name))
|
|
316
|
+
return cleaned
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
class MakeDirectoriesResponse(BaseModel):
|
|
320
|
+
"""Response model for making directories in the bucket."""
|
|
321
|
+
|
|
322
|
+
created: list[str] = Field(
|
|
323
|
+
...,
|
|
324
|
+
description=(
|
|
325
|
+
"List of directories that were successfully created. This will include directories that already existed."
|
|
326
|
+
),
|
|
327
|
+
)
|
|
328
|
+
failed: list[str] = Field(
|
|
329
|
+
...,
|
|
330
|
+
description=("List of directories that could not be created."),
|
|
331
|
+
)
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
### restore objects models ###
|
|
335
|
+
class RestoreObjectsResponse(BaseModel):
|
|
336
|
+
"""Response model for restoring soft-deleted objects in a bucket."""
|
|
337
|
+
|
|
338
|
+
restored: list[str] = Field(
|
|
339
|
+
...,
|
|
340
|
+
description="List of object names that were successfully restored, this includes objects that were already live",
|
|
341
|
+
)
|
|
342
|
+
not_restored: list[str] = Field(
|
|
343
|
+
...,
|
|
344
|
+
description=(
|
|
345
|
+
"List of object names that could not be processed.\n"
|
|
346
|
+
"This could be due to several reasons:\n"
|
|
347
|
+
"1. The object does not exist in the bucket (e.g., a typo in the name).\n"
|
|
348
|
+
"2. The object was hard-deleted and is unrecoverable.\n"
|
|
349
|
+
"3. An unexpected server error occurred during the restore attempt."
|
|
350
|
+
),
|
|
351
|
+
)
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
## checksum models ##
|
|
355
|
+
class FileChecksumResponse(BaseModel):
|
|
356
|
+
"""Response model for reporting a file's checksum in the bucket."""
|
|
357
|
+
|
|
358
|
+
object_name: str = Field(..., description="Name of the object in the bucket")
|
|
359
|
+
md5_checksum: str = Field(..., description="MD5 checksum of the object in the bucket")
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Schemas for task history routes.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from datetime import datetime
|
|
6
|
+
from typing import Any, Optional, Union
|
|
7
|
+
|
|
8
|
+
from pydantic import BaseModel
|
|
9
|
+
|
|
10
|
+
from divbase_lib.api_schemas.queries import (
|
|
11
|
+
BcftoolsQueryKwargs,
|
|
12
|
+
BcftoolsQueryTaskResult,
|
|
13
|
+
SampleMetadataQueryKwargs,
|
|
14
|
+
SampleMetadataQueryTaskResult,
|
|
15
|
+
)
|
|
16
|
+
from divbase_lib.api_schemas.vcf_dimensions import DimensionUpdateKwargs, DimensionUpdateTaskResult
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class TaskHistoryResult(BaseModel):
|
|
20
|
+
"""
|
|
21
|
+
Task details as returned by queries to the SQAlchemy+pg results backend.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
id: int # This is TaskHistoryDB.id
|
|
25
|
+
created_at: datetime # NOTE: This comes from TaskHistoryDB, so cannot be None unlike the other datetimes here.
|
|
26
|
+
submitter_email: str
|
|
27
|
+
name: str
|
|
28
|
+
status: Optional[str] = None
|
|
29
|
+
result: Optional[
|
|
30
|
+
Union[
|
|
31
|
+
dict[
|
|
32
|
+
str, Any
|
|
33
|
+
], # Note! This dict must come first here so that error results are preserved and not incorrectly inserted into the result models
|
|
34
|
+
SampleMetadataQueryTaskResult,
|
|
35
|
+
BcftoolsQueryTaskResult,
|
|
36
|
+
DimensionUpdateTaskResult,
|
|
37
|
+
]
|
|
38
|
+
] = None
|
|
39
|
+
date_done: Optional[datetime] = None
|
|
40
|
+
args: Optional[str] = None
|
|
41
|
+
kwargs: Optional[
|
|
42
|
+
Union[
|
|
43
|
+
SampleMetadataQueryKwargs,
|
|
44
|
+
BcftoolsQueryKwargs,
|
|
45
|
+
DimensionUpdateKwargs,
|
|
46
|
+
]
|
|
47
|
+
] = None
|
|
48
|
+
worker: Optional[str] = None
|
|
49
|
+
started_at: Optional[datetime] = None
|
|
50
|
+
completed_at: Optional[datetime] = None
|
|
51
|
+
runtime: Optional[float] = None
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Schemas for VCF dimensions routes.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from typing import Optional
|
|
6
|
+
|
|
7
|
+
from pydantic import BaseModel, Field
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class DimensionUpdateKwargs(BaseModel):
|
|
11
|
+
"""Keyword arguments for dimension update task. Used to pass info to Celery task, and also for recording task history."""
|
|
12
|
+
|
|
13
|
+
bucket_name: str
|
|
14
|
+
project_id: int
|
|
15
|
+
project_name: str
|
|
16
|
+
user_id: int
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class DimensionUpdateTaskResult(BaseModel):
|
|
20
|
+
"""Dimension update task result details. Based on the return of tasks.update_vcf_dimensions_task."""
|
|
21
|
+
|
|
22
|
+
status: Optional[str] = None
|
|
23
|
+
VCF_files_added: Optional[list[str]] = Field(
|
|
24
|
+
None, description="VCF files that were added to dimensions cache by this job"
|
|
25
|
+
)
|
|
26
|
+
VCF_files_skipped: Optional[list[str]] = Field(
|
|
27
|
+
None, description="VCF files skipped by this job (previous DivBase-generated result VCFs)"
|
|
28
|
+
)
|
|
29
|
+
VCF_files_deleted: Optional[list[str]] = Field(
|
|
30
|
+
None, description="VCF files that have been deleted from the project and thus have been dropped from the index"
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class DimensionsShowResult(BaseModel):
|
|
35
|
+
"""Result model for showing VCF dimensions for a project."""
|
|
36
|
+
|
|
37
|
+
project_id: int
|
|
38
|
+
project_name: str
|
|
39
|
+
vcf_file_count: int
|
|
40
|
+
vcf_files: list[dict]
|
|
41
|
+
skipped_file_count: int
|
|
42
|
+
skipped_files: list[dict]
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class DimensionsSamplesResult(BaseModel):
|
|
46
|
+
"""Result model for showing unique samples across project VCFs."""
|
|
47
|
+
|
|
48
|
+
unique_samples: list[str] # Already sorted, by the CRUD function get_unique_samples_by_project_async()
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class DimensionsScaffoldsResult(BaseModel):
|
|
52
|
+
"""Result model for showing unique scaffolds across project VCFs."""
|
|
53
|
+
|
|
54
|
+
unique_scaffolds: list[str] # Already sorted, by the CRUD function get_unique_scaffolds_by_project_async()
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class DimensionsVCFFileEntry(BaseModel):
|
|
58
|
+
"""A single VCF file entry in the unique VCF files response."""
|
|
59
|
+
|
|
60
|
+
vcf_file_s3_key: str
|
|
61
|
+
s3_version_id: str
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class DimensionsVCFFilesResult(BaseModel):
|
|
65
|
+
"""Result model for showing unique VCF file/version entries across project VCFs."""
|
|
66
|
+
|
|
67
|
+
unique_vcf_files: list[DimensionsVCFFileEntry]
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Constants that both divbase-api and divbase-cli need to agree on.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
ONE_MiB = 1024 * 1024
|
|
6
|
+
|
|
7
|
+
# When you download a file that has been uploaded in parts, you have
|
|
8
|
+
# to know the part/chunk size used in order to correctly calculate the composite checksum
|
|
9
|
+
S3_MULTIPART_CHUNK_SIZE = 32 * ONE_MiB
|
|
10
|
+
|
|
11
|
+
# At what point you swap from single part to multipart upload to S3.
|
|
12
|
+
# If server and client used the same threshold then makes life easier
|
|
13
|
+
# when validating the checksums of files in s3 as single part and multipart uploads use different ETag formats.
|
|
14
|
+
# (No benefit in constraining the download threshold, so not done here)
|
|
15
|
+
S3_MULTIPART_UPLOAD_THRESHOLD = 96 * ONE_MiB
|
|
16
|
+
|
|
17
|
+
# Max number of items that can be processed in a single API call to divbase-api's S3 routes
|
|
18
|
+
# covers e.g pre-signed urls for upload/download, soft delete and checksum comparisons
|
|
19
|
+
# client has to batch requests if exceeding this limit
|
|
20
|
+
MAX_S3_API_BATCH_SIZE = 100
|
|
21
|
+
|
|
22
|
+
# How long the pre-signed URLs divbase-api creates are valid for
|
|
23
|
+
SINGLE_PART_UPLOAD_URL_EXPIRATION_SECONDS = 3600 # 1 hour
|
|
24
|
+
MULTI_PART_UPLOAD_URL_EXPIRATION_SECONDS = 36000 # 10 hours
|
|
25
|
+
DOWNLOAD_URL_EXPIRATION_SECONDS = 36000 # 10 hours
|
|
26
|
+
|
|
27
|
+
# (Not used anywhere, just making it explicit)
|
|
28
|
+
# This is limited by our fixing of the chunk size and S3's limit to the number of chunks allowed (10,000)
|
|
29
|
+
# 320 GiB if using 32 MiB chunks
|
|
30
|
+
LARGEST_FILE_UPLOADABLE_TO_DIVBASE_BYTES = 10_000 * S3_MULTIPART_CHUNK_SIZE
|
|
31
|
+
|
|
32
|
+
# File types that DivBase supports
|
|
33
|
+
# Whilst we can't realistically limit what file types a user actually uploads,
|
|
34
|
+
# this is here to say what we know should work in DivBase.
|
|
35
|
+
SUPPORTED_DIVBASE_FILE_TYPES = (".tsv", ".vcf.gz", ".csi", ".tbi", ".txt", ".md")
|
|
36
|
+
SUPPORTED_DIVBASE_FILE_TYPES_DISPLAY = ", ".join(f"'{ext}'" for ext in SUPPORTED_DIVBASE_FILE_TYPES)
|
|
37
|
+
# Characters that are not allowed in file names uploaded to DivBase
|
|
38
|
+
# This is to prevent issues when users try to filter/query files on DivBase using these characters
|
|
39
|
+
# or when downloading files (e.g. ":" is used to specify file versions when downloading files
|
|
40
|
+
UNSUPPORTED_CHARACTERS_IN_FILENAMES = (":", "*", "?", "<", ">", "|", "\\", "//", "@", "~")
|
|
41
|
+
UNSUPPORTED_CHARACTERS_DISPLAY = ", ".join(f"'{c}'" for c in UNSUPPORTED_CHARACTERS_IN_FILENAMES)
|
|
42
|
+
|
|
43
|
+
# This prefix is used for all *.vcf.gz results files from a query job/task.
|
|
44
|
+
# After the prefix comes the job id which is a rolling integer.
|
|
45
|
+
# E.g. format: result_of_job_<job-id>.vcf.gz , where <job-id> = 1 and is auto-incremented for every new job.
|
|
46
|
+
# NOTE: If you update this, you should also update the S3 lifecycle policies associated with this.
|
|
47
|
+
QUERY_RESULTS_FILE_PREFIX = "result_of_job_"
|
|
48
|
+
|
|
49
|
+
# CLI includes this in every request to the server,
|
|
50
|
+
# and server uses it to determine if it should:
|
|
51
|
+
# 1. Reject the request as the version is too outdated
|
|
52
|
+
# 2. Add an announcement about a new CLI version being available when the user logs in.
|
|
53
|
+
# 3. Do Nothing as the user's CLI version is up to date.
|
|
54
|
+
CLI_VERSION_HEADER_KEY = "X-CLI-Version"
|
|
55
|
+
|
|
56
|
+
# Personal Access Tokens (PATs) are used for passwordless auth with DivBase API
|
|
57
|
+
PAT_TOKEN_PREFIX = "divbase_pat_"
|
|
58
|
+
|
|
59
|
+
# Both divbase-api and divbase-worker(s) configs want to know if we are in a deployed environment or not
|
|
60
|
+
LOCAL_DEV_ENVIRONMENTS = ["local_dev", "test"]
|
|
61
|
+
|
|
62
|
+
# The default timezone and formats used for display (e.g. in the frontend, admin panel and in emails).
|
|
63
|
+
DIVBASE_SERVER_TIMEZONE = "Europe/Stockholm"
|
|
64
|
+
DEFAULT_DISPLAY_DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S %Z"
|
|
65
|
+
# divbase-cli uses user's local timezone for display
|
|
66
|
+
DEFAULT_CLI_DISPLAY_DATETIME_FORMAT = "%Y-%m-%d %H:%M %Z"
|