Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/DIRAC/DataManagementSystem/Service/S3GatewayHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ def export_createPresignedUrl(self, storageName, s3_method, urls, expiration):
failed[url] = "Permission denied"
continue

res = returnSingleResult(
s3Plugin.createPresignedUrl({url: urls.get("Fields")}, s3_method, expiration=expiration)
)
# For put_object, urls maps each url to the fields (metadata) of the file
fields = urls[url] if s3_method == "put_object" else None
res = returnSingleResult(s3Plugin.createPresignedUrl({url: fields}, s3_method, expiration=expiration))

log.debug(f"Presigned URL for {url}: {res}")
if res["OK"]:
Expand Down
7 changes: 5 additions & 2 deletions src/DIRAC/Resources/Storage/S3Storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ def _presigned_exists(self, urls):
# and perform it with requests
for url, presignedURL in presignedURLs.items():
try:
response = requests.get(presignedURL, timeout=30)
# The URL is signed for head_object so it must be used with HEAD
response = requests.head(presignedURL, timeout=30)
if response.status_code == 200:
successful[url] = True
elif response.status_code == 404: # not found
Expand Down Expand Up @@ -768,8 +769,10 @@ def createPresignedUrl(self, urls, s3_method, expiration=3600):
fields = keys.get(key)
if not isinstance(fields, dict):
fields = None
# boto does not add the fields to the policy, without which S3 rejects them
conditions = [{k: v} for k, v in fields.items()] if fields else None
response = self.s3_client.generate_presigned_post(
self.bucketName, key, Fields=fields, ExpiresIn=expiration
self.bucketName, key, Fields=fields, Conditions=conditions, ExpiresIn=expiration
)

successful[key] = response
Expand Down
Loading