Skip to content
This repository was archived by the owner on May 5, 2025. It is now read-only.

Commit 741151b

Browse files
committed
make repository non-required for ArchiveService, add bulk delete to ArchiveService, remove default value from paths
1 parent 96d0b0c commit 741151b

File tree

6 files changed

+27
-13
lines changed

6 files changed

+27
-13
lines changed

shared/api_archive/archive.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ def __init__(self, repository, ttl=None):
6464
self.ttl = ttl or int(get_config("services", "minio", "ttl", default=self.ttl))
6565

6666
self.storage = StorageService()
67-
self.storage_hash = self.get_archive_hash(repository)
67+
if repository:
68+
self.storage_hash = self.get_archive_hash(repository)
69+
else:
70+
self.storage_hash = None
6871

6972
@classmethod
7073
def get_archive_hash(cls, repository) -> str:
@@ -98,6 +101,8 @@ def write_json_data_to_storage(
98101
*,
99102
encoder=ReportEncoder,
100103
):
104+
if not self.storage_hash:
105+
raise ValueError("No hash key provided")
101106
if commit_id is None:
102107
# Some classes don't have a commit associated with them
103108
# For example Pull belongs to multiple commits.
@@ -147,20 +152,29 @@ def read_file(self, path: str) -> str:
147152
return contents.decode()
148153

149154
@sentry_sdk.trace
150-
def delete_file(self, path):
155+
def delete_file(self, path: str) -> None:
151156
"""
152157
Generic method to delete a file from the archive.
153158
"""
154159
self.storage.delete_file(self.root, path)
155160

161+
@sentry_sdk.trace
162+
def delete_files(self, paths: list[str]) -> None:
163+
"""
164+
Generic method to delete files from the archive.
165+
"""
166+
self.storage.delete_files(bucket_name=self.root, paths=paths)
167+
156168
def read_chunks(self, commit_sha: str) -> str:
157169
"""
158170
Convenience method to read a chunks file from the archive.
159171
"""
172+
if not self.storage_hash:
173+
raise ValueError("No hash key provided")
160174
path = MinioEndpoints.chunks.get_path(
161175
version="v4", repo_hash=self.storage_hash, commitid=commit_sha
162176
)
163177
return self.read_file(path)
164178

165-
def create_presigned_put(self, path):
179+
def create_presigned_put(self, path: str) -> str:
166180
return self.storage.create_presigned_put(self.root, path, self.ttl)

shared/django_apps/utils/model_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def __get__(self, obj, objtype=None):
115115
if cached_value:
116116
return cached_value
117117
db_field = getattr(obj, self.db_field_name)
118-
if db_field is not None:
118+
if not db_field:
119119
value = self.rehydrate_fn(obj, db_field)
120120
else:
121121
value = self._get_value_from_archive(obj)

shared/storage/aws.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def delete_file(self, bucket_name, path):
147147
except ClientError:
148148
raise
149149

150-
def delete_files(self, bucket_name, paths=[]):
150+
def delete_files(self, bucket_name: str, paths: list[str]) -> list[bool]:
151151
"""Batch deletes a list of files from a given bucket
152152
153153
Note:

shared/storage/fallback.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def delete_file(self, bucket_name, path):
8989
second_deletion = self.fallback_service.delete_file(bucket_name, path)
9090
return first_deletion and second_deletion
9191

92-
def delete_files(self, bucket_name, paths=[]):
92+
def delete_files(self, bucket_name: str, paths: list[str]) -> list[bool]:
9393
"""Batch deletes a list of files from a given bucket
9494
(what happens to the files that don't exist?)
9595

shared/storage/memory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def delete_file(self, bucket_name, path):
123123
raise FileNotInStorageError()
124124
return True
125125

126-
def delete_files(self, bucket_name, paths=[]):
126+
def delete_files(self, bucket_name: str, paths: list[str]) -> list[bool]:
127127
"""Batch deletes a list of files from a given bucket
128128
(what happens to the files that don't exist?)
129129

shared/storage/minio.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,21 +233,21 @@ def read_file(
233233
deletion, returns a ResponseError otherwise.
234234
"""
235235

236-
def delete_file(self, bucket_name, url):
236+
def delete_file(self, bucket_name: str, path: str) -> bool:
237237
try:
238-
# delete a file given a bucket name and a url
239-
self.minio_client.remove_object(bucket_name, url)
238+
# delete a file given a bucket name and a path
239+
self.minio_client.remove_object(bucket_name, path)
240240
return True
241241
except MinioException:
242242
raise
243243

244-
def delete_files(self, bucket_name, urls=[]):
244+
def delete_files(self, bucket_name: str, paths: list[str]) -> list[bool]:
245245
try:
246246
for del_err in self.minio_client.remove_objects(
247-
bucket_name, [DeleteObject(url) for url in urls]
247+
bucket_name, [DeleteObject(path) for path in paths]
248248
):
249249
print("Deletion error: {}".format(del_err))
250-
return [True] * len(urls)
250+
return [True] * len(paths)
251251
except MinioException:
252252
raise
253253

0 commit comments

Comments
 (0)