Skip to content

Commit

Permalink
fix: arg checking, no empty filenames
Browse files Browse the repository at this point in the history
  • Loading branch information
juancarlospaco committed Sep 19, 2024
1 parent dc6f323 commit bd174d7
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions storage3/_sync/resumable.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ def __init__(self, session: SyncClient) -> None:
self.expiration_time_format = "%a, %d %b %Y %X %Z"
self._filestore = FileStore()

def _is_valid_arg(self, target):
return isinstance(target, str) and len(target.strip()) > 0

def _encode(self, metadata: UploadMetadata) -> str:
"""Generate base64 encoding for Upload-Metadata header
Parameters
Expand Down Expand Up @@ -60,15 +63,17 @@ def create_unique_link(
filename
Local file
"""
if bucketname is None:
if not self._is_valid_arg(bucketname):
raise StorageException("bucketname cannot be empty")

if objectname is None and filename is None:
if not (self._is_valid_arg(objectname) or self._is_valid_arg(filename)):
raise StorageException("Must specify objectname or filename")

file = filename if filename else objectname
upload_mode = None
if not self._is_valid_arg(file):
raise StorageException("Must specify objectname or filename")

upload_mode = None
info = FileInfo(
name=file, link="", length="", headers={"Tus-Resumable": "1.0.0"}
)
Expand Down Expand Up @@ -152,11 +157,14 @@ def upload(
Amount of megabytes to be sent in each iteration
"""
if upload_defer:
if link is None or objectname is None:
if not (self._is_valid_arg(link) and self._is_valid_arg(objectname)):
raise StorageException(
"Upload-Defer mode requires a link and objectname"
)

if not self._is_valid_arg(filename):
raise StorageException("Must specify a filename")

target_file = objectname if upload_defer else filename
chunk_size = 1048576 * int(abs(mb_size)) # 1024 * 1024 * mb_size
size = None
Expand Down

0 comments on commit bd174d7

Please sign in to comment.