Skip to content

Commit 53d1e8e

Browse files
committed
signed upload method on azure and s3
1 parent 9c0fb20 commit 53d1e8e

2 files changed

Lines changed: 23 additions & 5 deletions

File tree

libcloud/storage/drivers/azure_blobs.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import hashlib
2121
import binascii
2222
from datetime import datetime, timedelta
23+
from typing import Literal
2324

2425
from libcloud.utils.py3 import ET, b, httplib, tostring, urlquote, urlencode
2526
from libcloud.utils.xml import fixxpath
@@ -603,7 +604,12 @@ def get_object(self, container_name, object_name):
603604

604605
raise ObjectDoesNotExistError(value=None, driver=self, object_name=object_name)
605606

606-
def get_object_cdn_url(self, obj, ex_expiry=AZURE_STORAGE_CDN_URL_EXPIRY_HOURS):
607+
def get_object_cdn_url(
608+
self,
609+
obj,
610+
ex_expiry=AZURE_STORAGE_CDN_URL_EXPIRY_HOURS,
611+
ex_method: Literal["GET", "PUT", "DELETE"] = "GET",
612+
):
607613
"""
608614
Return a SAS URL that enables reading the given object.
609615
@@ -623,10 +629,17 @@ def get_object_cdn_url(self, obj, ex_expiry=AZURE_STORAGE_CDN_URL_EXPIRY_HOURS):
623629
start = now - timedelta(minutes=AZURE_STORAGE_CDN_URL_START_MINUTES)
624630
expiry = now + timedelta(hours=ex_expiry)
625631

632+
if ex_method == "PUT":
633+
sp = "wc"
634+
elif ex_method == "DELETE":
635+
sp = "d"
636+
else:
637+
sp = "r"
638+
626639
params = {
627640
"st": start.strftime(AZURE_STORAGE_CDN_URL_DATE_FORMAT),
628641
"se": expiry.strftime(AZURE_STORAGE_CDN_URL_DATE_FORMAT),
629-
"sp": "r",
642+
"sp": sp,
630643
"spr": "https" if self.secure else "http,https",
631644
"sv": self.connectionCls.API_VERSION,
632645
"sr": "b",

libcloud/storage/drivers/s3.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import hmac
1818
import time
1919
import base64
20-
from typing import Dict, Optional
20+
from typing import Dict, Literal, Optional
2121
from hashlib import sha1
2222
from datetime import datetime
2323

@@ -1274,7 +1274,12 @@ def __init__(
12741274
def list_regions(self):
12751275
return REGION_TO_HOST_MAP.keys()
12761276

1277-
def get_object_cdn_url(self, obj, ex_expiry=S3_CDN_URL_EXPIRY_HOURS):
1277+
def get_object_cdn_url(
1278+
self,
1279+
obj,
1280+
ex_expiry=S3_CDN_URL_EXPIRY_HOURS,
1281+
ex_method: Literal["GET", "PUT", "DELETE"] = "GET",
1282+
):
12781283
"""
12791284
Return a "presigned URL" for read-only access to object
12801285
@@ -1319,7 +1324,7 @@ def get_object_cdn_url(self, obj, ex_expiry=S3_CDN_URL_EXPIRY_HOURS):
13191324
params=params_to_sign,
13201325
headers=headers_to_sign,
13211326
dt=now,
1322-
method="GET",
1327+
method=ex_method,
13231328
path=object_path,
13241329
data=UnsignedPayloadSentinel,
13251330
)

0 commit comments

Comments
 (0)