pyuploadcare 4.2.2__tar.gz → 4.3.0__tar.gz
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.
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/PKG-INFO +1 -1
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyproject.toml +1 -1
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/__init__.py +1 -1
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/api/api.py +6 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/client.py +16 -10
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/resources/file_group.py +5 -0
- pyuploadcare-4.3.0/pyuploadcare/secure_url.py +194 -0
- pyuploadcare-4.2.2/pyuploadcare/secure_url.py +0 -163
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/LICENSE +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/README.md +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/api/__init__.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/api/addon_entities.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/api/auth.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/api/base.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/api/client.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/api/entities.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/api/metadata.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/api/responses.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/api/utils.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/conf.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/dj/__init__.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/dj/client.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/dj/conf.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/dj/forms.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/dj/models.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/dj/static/uploadcare/uploadcare.full.min.js +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/dj/static/uploadcare/uploadcare.min.js +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/dj/subclassing.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/exceptions.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/helpers.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/resources/__init__.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/resources/base.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/resources/file.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/resources/file_list.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/resources/group_list.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/resources/utils.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/transformations/__init__.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/transformations/base.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/transformations/document.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/transformations/image.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/transformations/video.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/ucare_cli/__init__.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/ucare_cli/commands/__init__.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/ucare_cli/commands/convert_document.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/ucare_cli/commands/convert_video.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/ucare_cli/commands/create_group.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/ucare_cli/commands/create_webhook.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/ucare_cli/commands/delete_files.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/ucare_cli/commands/delete_webhook.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/ucare_cli/commands/get_file.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/ucare_cli/commands/get_project.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/ucare_cli/commands/helpers.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/ucare_cli/commands/list_files.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/ucare_cli/commands/list_groups.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/ucare_cli/commands/list_webhooks.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/ucare_cli/commands/store_files.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/ucare_cli/commands/sync.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/ucare_cli/commands/update_webhook.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/ucare_cli/commands/upload.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/ucare_cli/commands/upload_from_url.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/ucare_cli/main.py +0 -0
- {pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/ucare_cli/settings.py +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import hashlib
|
|
2
2
|
import hmac
|
|
3
3
|
import logging
|
|
4
|
+
import warnings
|
|
4
5
|
from json import JSONDecodeError
|
|
5
6
|
from time import time
|
|
6
7
|
from typing import Any, Dict, Iterable, List, Optional, Type, Union, cast
|
|
@@ -122,6 +123,11 @@ class GroupsAPI(API, ListCountMixin, RetrieveMixin, DeleteMixin):
|
|
|
122
123
|
}
|
|
123
124
|
|
|
124
125
|
def store(self, file_uuid: Union[UUID, str]) -> Dict[str, Any]:
|
|
126
|
+
warnings.warn(
|
|
127
|
+
"/groups/:uuid/storage/ endpoint has been removed from REST API v0.7"
|
|
128
|
+
"https://uploadcare.com/api-refs/rest-api/v0.7.0/#tag/Changelog",
|
|
129
|
+
DeprecationWarning,
|
|
130
|
+
)
|
|
125
131
|
url = self._build_url(file_uuid, suffix="storage")
|
|
126
132
|
return self._client.put(url).json()
|
|
127
133
|
|
|
@@ -826,25 +826,31 @@ class Uploadcare:
|
|
|
826
826
|
return expire, signature
|
|
827
827
|
|
|
828
828
|
def generate_secure_url(
|
|
829
|
-
self,
|
|
829
|
+
self, handle: Union[str, UUID], wildcard: bool = False
|
|
830
830
|
) -> str:
|
|
831
|
-
"""
|
|
832
|
-
|
|
833
|
-
|
|
831
|
+
"""
|
|
832
|
+
Generate authenticated URL.
|
|
833
|
+
:param handle: Can be one of the following: UUID, UUID with transformations, full URL.
|
|
834
|
+
"""
|
|
835
|
+
if isinstance(handle, UUID):
|
|
836
|
+
handle = str(handle)
|
|
834
837
|
|
|
835
838
|
if not self.secure_url_builder:
|
|
836
839
|
raise ValueError("secure_url_builder must be set")
|
|
837
840
|
|
|
838
|
-
return self.secure_url_builder.build(
|
|
841
|
+
return self.secure_url_builder.build(handle, wildcard=wildcard)
|
|
839
842
|
|
|
840
843
|
def generate_secure_url_token(
|
|
841
|
-
self,
|
|
844
|
+
self, handle: Union[str, UUID], wildcard: bool = False
|
|
842
845
|
) -> str:
|
|
843
|
-
"""
|
|
844
|
-
|
|
845
|
-
|
|
846
|
+
"""
|
|
847
|
+
Generate token for authenticated URL.
|
|
848
|
+
:param handle: Can be one of the following: UUID, UUID with transformations, full URL.
|
|
849
|
+
"""
|
|
850
|
+
if isinstance(handle, UUID):
|
|
851
|
+
handle = str(handle)
|
|
846
852
|
|
|
847
853
|
if not self.secure_url_builder:
|
|
848
854
|
raise ValueError("secure_url_builder must be set")
|
|
849
855
|
|
|
850
|
-
return self.secure_url_builder.get_token(
|
|
856
|
+
return self.secure_url_builder.get_token(handle, wildcard=wildcard)
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import re
|
|
2
|
+
import warnings
|
|
2
3
|
from datetime import datetime
|
|
3
4
|
from typing import TYPE_CHECKING, Any, Dict, Iterable, Iterator, Optional
|
|
4
5
|
|
|
@@ -152,6 +153,10 @@ class FileGroup(Iterable):
|
|
|
152
153
|
@property
|
|
153
154
|
def datetime_stored(self):
|
|
154
155
|
"""Returns file group's store aware *datetime* in UTC format."""
|
|
156
|
+
warnings.warn(
|
|
157
|
+
"datetime_stored has been removed from REST API v0.7",
|
|
158
|
+
DeprecationWarning,
|
|
159
|
+
)
|
|
155
160
|
datetime_ = self.info.get("datetime_stored")
|
|
156
161
|
if isinstance(datetime_, str):
|
|
157
162
|
return dateutil.parser.parse(datetime_)
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import binascii
|
|
2
|
+
import hashlib
|
|
3
|
+
import hmac
|
|
4
|
+
import re
|
|
5
|
+
import time
|
|
6
|
+
import warnings
|
|
7
|
+
from abc import ABC, abstractmethod
|
|
8
|
+
from typing import Optional
|
|
9
|
+
from urllib.parse import quote_plus, urlparse
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class BaseSecureUrlBuilder(ABC):
|
|
13
|
+
@abstractmethod
|
|
14
|
+
def build(self, handle: str, wildcard: bool = False) -> str:
|
|
15
|
+
"""
|
|
16
|
+
:param handle: Can be one of the following: UUID, UUID with transformations, full URL.
|
|
17
|
+
"""
|
|
18
|
+
raise NotImplementedError
|
|
19
|
+
|
|
20
|
+
def get_token(self, handle: str, wildcard: bool = False) -> str:
|
|
21
|
+
"""
|
|
22
|
+
:param handle: Can be one of the following: UUID, UUID with transformations, full URL.
|
|
23
|
+
"""
|
|
24
|
+
raise NotImplementedError(
|
|
25
|
+
f"{self.__class__} doesn't provide get_token()"
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class BaseAkamaiSecureUrlBuilder(BaseSecureUrlBuilder):
|
|
30
|
+
"""Akamai secure url builder.
|
|
31
|
+
|
|
32
|
+
See https://uploadcare.com/docs/security/secure_delivery/
|
|
33
|
+
for more details.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
base_template = "https://{cdn}/{path}/"
|
|
37
|
+
template = "{base}?token={token}"
|
|
38
|
+
field_delimeter = "~"
|
|
39
|
+
|
|
40
|
+
def __init__(
|
|
41
|
+
self,
|
|
42
|
+
cdn_url: str,
|
|
43
|
+
secret_key: str,
|
|
44
|
+
window: int = 300,
|
|
45
|
+
hash_algo=hashlib.sha256,
|
|
46
|
+
):
|
|
47
|
+
self.secret_key = secret_key
|
|
48
|
+
self.cdn_url = cdn_url
|
|
49
|
+
self.window = window
|
|
50
|
+
self.hash_algo = hash_algo
|
|
51
|
+
|
|
52
|
+
def build(self, handle: str, wildcard: bool = False) -> str:
|
|
53
|
+
token = self.get_token(handle, wildcard=wildcard)
|
|
54
|
+
secure_url = self._build_url(handle, token)
|
|
55
|
+
return secure_url
|
|
56
|
+
|
|
57
|
+
def get_token(self, handle: str, wildcard: bool = False) -> str:
|
|
58
|
+
path = self._get_path(handle)
|
|
59
|
+
expire = self._build_expire_time()
|
|
60
|
+
acl = self._format_acl(path, wildcard=wildcard)
|
|
61
|
+
signature = self._build_signature(handle, expire, acl)
|
|
62
|
+
token = self._build_token(expire, acl, signature)
|
|
63
|
+
return token
|
|
64
|
+
|
|
65
|
+
def _prepare_path_for_url(self, path: str) -> str:
|
|
66
|
+
path = re.sub(
|
|
67
|
+
r"(%..)",
|
|
68
|
+
lambda match: match.group(1).lower(),
|
|
69
|
+
quote_plus(path, safe=","),
|
|
70
|
+
)
|
|
71
|
+
path = self._prepare_path_for_acl(path)
|
|
72
|
+
return path
|
|
73
|
+
|
|
74
|
+
def _prepare_path_for_acl(self, path: str) -> str:
|
|
75
|
+
for escape_char in "~":
|
|
76
|
+
path = path.replace(
|
|
77
|
+
escape_char, "%" + hex(ord(escape_char)).lower()[2:]
|
|
78
|
+
)
|
|
79
|
+
return path
|
|
80
|
+
|
|
81
|
+
def _build_expire_time(self) -> int:
|
|
82
|
+
return int(time.time()) + self.window
|
|
83
|
+
|
|
84
|
+
def _build_signature(
|
|
85
|
+
self, handle: str, expire: int, acl: Optional[str]
|
|
86
|
+
) -> str:
|
|
87
|
+
path = self._get_path(handle)
|
|
88
|
+
path = self._prepare_path_for_url(path)
|
|
89
|
+
hash_source = [
|
|
90
|
+
f"exp={expire}",
|
|
91
|
+
f"acl={acl}" if acl else f"url={path}",
|
|
92
|
+
]
|
|
93
|
+
|
|
94
|
+
signature = hmac.new(
|
|
95
|
+
binascii.a2b_hex(self.secret_key.encode()),
|
|
96
|
+
self.field_delimeter.join(hash_source).encode(),
|
|
97
|
+
self.hash_algo,
|
|
98
|
+
).hexdigest()
|
|
99
|
+
|
|
100
|
+
return signature
|
|
101
|
+
|
|
102
|
+
def _build_token(self, expire: int, acl: Optional[str], signature: str):
|
|
103
|
+
token_parts = [
|
|
104
|
+
f"exp={expire}",
|
|
105
|
+
f"acl={acl}" if acl else None,
|
|
106
|
+
f"hmac={signature}",
|
|
107
|
+
]
|
|
108
|
+
|
|
109
|
+
return self.field_delimeter.join(
|
|
110
|
+
part for part in token_parts if part is not None
|
|
111
|
+
)
|
|
112
|
+
|
|
113
|
+
def _build_url(
|
|
114
|
+
self,
|
|
115
|
+
handle: str,
|
|
116
|
+
token: str,
|
|
117
|
+
) -> str:
|
|
118
|
+
base_url = self._build_base_url(handle)
|
|
119
|
+
return self.template.format(
|
|
120
|
+
base=base_url,
|
|
121
|
+
token=token,
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
def _get_path(self, handle: str) -> str:
|
|
125
|
+
"""
|
|
126
|
+
>>> builder._get_path("fake-uuid")
|
|
127
|
+
/fake-uuid/
|
|
128
|
+
>>> builder._get_path("https://sectest.ucarecdn.com/fake-uuid/-/resize/20x20/")
|
|
129
|
+
/fake-uuid/-/resize/20x20/
|
|
130
|
+
"""
|
|
131
|
+
path = handle
|
|
132
|
+
parsed = urlparse(path)
|
|
133
|
+
if parsed.netloc:
|
|
134
|
+
# extract uuid with transformations from url
|
|
135
|
+
path = parsed.path
|
|
136
|
+
if not path.startswith("/"):
|
|
137
|
+
path = f"/{path}"
|
|
138
|
+
return path
|
|
139
|
+
|
|
140
|
+
def _build_base_url(self, handle: str):
|
|
141
|
+
"""
|
|
142
|
+
>>> builder._build_base_url("fake-uuid")
|
|
143
|
+
https://sectest.ucarecdn.com/fake-uuid/
|
|
144
|
+
>>> builder._get_path("https://sectest.ucarecdn.com/fake-uuid/-/resize/20x20/")
|
|
145
|
+
https://sectest.ucarecdn.com/fake-uuid/-/resize/20x20/
|
|
146
|
+
"""
|
|
147
|
+
path = self._get_path(handle)
|
|
148
|
+
path = path.lstrip("/").rstrip("/")
|
|
149
|
+
base_url = self.base_template.format(cdn=self.cdn_url, path=path)
|
|
150
|
+
return base_url
|
|
151
|
+
|
|
152
|
+
@abstractmethod
|
|
153
|
+
def _format_acl(self, handle: str, wildcard: bool) -> Optional[str]:
|
|
154
|
+
raise NotImplementedError
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
class AkamaiSecureUrlBuilderWithAclToken(BaseAkamaiSecureUrlBuilder):
|
|
158
|
+
def _format_acl(self, handle: str, wildcard: bool) -> str:
|
|
159
|
+
path = self._get_path(handle)
|
|
160
|
+
path = path.lstrip("/").rstrip("/")
|
|
161
|
+
path = self._prepare_path_for_acl(path)
|
|
162
|
+
if wildcard:
|
|
163
|
+
return f"/{path}/*"
|
|
164
|
+
return f"/{path}/"
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
class AkamaiSecureUrlBuilderWithUrlToken(BaseAkamaiSecureUrlBuilder):
|
|
168
|
+
def _format_acl(self, handle: str, wildcard: bool) -> None:
|
|
169
|
+
if wildcard:
|
|
170
|
+
raise ValueError(
|
|
171
|
+
"Wildcards are not supported in AkamaiSecureUrlBuilderWithUrlToken."
|
|
172
|
+
)
|
|
173
|
+
return None
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
class AkamaiSecureUrlBuilder(AkamaiSecureUrlBuilderWithAclToken):
|
|
177
|
+
def __init__(
|
|
178
|
+
self,
|
|
179
|
+
cdn_url: str,
|
|
180
|
+
secret_key: str,
|
|
181
|
+
window: int = 300,
|
|
182
|
+
hash_algo=hashlib.sha256,
|
|
183
|
+
):
|
|
184
|
+
warnings.warn(
|
|
185
|
+
"AkamaiSecureUrlBuilder class was renamed to AkamaiSecureUrlBuilderWithAclToken",
|
|
186
|
+
DeprecationWarning,
|
|
187
|
+
stacklevel=2,
|
|
188
|
+
)
|
|
189
|
+
super().__init__(
|
|
190
|
+
cdn_url=cdn_url,
|
|
191
|
+
secret_key=secret_key,
|
|
192
|
+
window=window,
|
|
193
|
+
hash_algo=hash_algo,
|
|
194
|
+
)
|
|
@@ -1,163 +0,0 @@
|
|
|
1
|
-
import binascii
|
|
2
|
-
import hashlib
|
|
3
|
-
import hmac
|
|
4
|
-
import time
|
|
5
|
-
import warnings
|
|
6
|
-
from abc import ABC, abstractmethod
|
|
7
|
-
from typing import Optional
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class BaseSecureUrlBuilder(ABC):
|
|
11
|
-
@abstractmethod
|
|
12
|
-
def build(self, uuid: str, wildcard: bool = False) -> str:
|
|
13
|
-
raise NotImplementedError
|
|
14
|
-
|
|
15
|
-
def get_token(self, uuid: str, wildcard: bool = False) -> str:
|
|
16
|
-
raise NotImplementedError(
|
|
17
|
-
f"{self.__class__} doesn't provide get_token()"
|
|
18
|
-
)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
class BaseAkamaiSecureUrlBuilder(BaseSecureUrlBuilder):
|
|
22
|
-
"""Akamai secure url builder.
|
|
23
|
-
|
|
24
|
-
See https://uploadcare.com/docs/security/secure_delivery/
|
|
25
|
-
for more details.
|
|
26
|
-
"""
|
|
27
|
-
|
|
28
|
-
template = "{base}?token={token}"
|
|
29
|
-
field_delimeter = "~"
|
|
30
|
-
|
|
31
|
-
def __init__(
|
|
32
|
-
self,
|
|
33
|
-
cdn_url: str,
|
|
34
|
-
secret_key: str,
|
|
35
|
-
window: int = 300,
|
|
36
|
-
hash_algo=hashlib.sha256,
|
|
37
|
-
):
|
|
38
|
-
self.secret_key = secret_key
|
|
39
|
-
self.cdn_url = cdn_url
|
|
40
|
-
self.window = window
|
|
41
|
-
self.hash_algo = hash_algo
|
|
42
|
-
|
|
43
|
-
def build(self, uuid: str, wildcard: bool = False) -> str:
|
|
44
|
-
uuid_or_url = self._format_uuid_or_url(uuid)
|
|
45
|
-
token = self.get_token(uuid_or_url, wildcard=wildcard)
|
|
46
|
-
secure_url = self._build_url(uuid_or_url, token)
|
|
47
|
-
return secure_url
|
|
48
|
-
|
|
49
|
-
def get_token(self, uuid: str, wildcard: bool = False) -> str:
|
|
50
|
-
uuid_or_url = self._format_uuid_or_url(uuid)
|
|
51
|
-
expire = self._build_expire_time()
|
|
52
|
-
acl = self._format_acl(uuid_or_url, wildcard=wildcard)
|
|
53
|
-
signature = self._build_signature(uuid_or_url, expire, acl)
|
|
54
|
-
token = self._build_token(expire, acl, signature)
|
|
55
|
-
return token
|
|
56
|
-
|
|
57
|
-
def _build_expire_time(self) -> int:
|
|
58
|
-
return int(time.time()) + self.window
|
|
59
|
-
|
|
60
|
-
def _build_signature(
|
|
61
|
-
self, uuid_or_url: str, expire: int, acl: Optional[str]
|
|
62
|
-
) -> str:
|
|
63
|
-
|
|
64
|
-
hash_source = [
|
|
65
|
-
f"exp={expire}",
|
|
66
|
-
f"acl={acl}" if acl else f"url={uuid_or_url}",
|
|
67
|
-
]
|
|
68
|
-
|
|
69
|
-
signature = hmac.new(
|
|
70
|
-
binascii.a2b_hex(self.secret_key.encode()),
|
|
71
|
-
self.field_delimeter.join(hash_source).encode(),
|
|
72
|
-
self.hash_algo,
|
|
73
|
-
).hexdigest()
|
|
74
|
-
|
|
75
|
-
return signature
|
|
76
|
-
|
|
77
|
-
def _build_token(self, expire: int, acl: Optional[str], signature: str):
|
|
78
|
-
|
|
79
|
-
token_parts = [
|
|
80
|
-
f"exp={expire}",
|
|
81
|
-
f"acl={acl}" if acl else None,
|
|
82
|
-
f"hmac={signature}",
|
|
83
|
-
]
|
|
84
|
-
|
|
85
|
-
return self.field_delimeter.join(
|
|
86
|
-
part for part in token_parts if part is not None
|
|
87
|
-
)
|
|
88
|
-
|
|
89
|
-
@abstractmethod
|
|
90
|
-
def _build_base_url(self, uuid_or_url: str):
|
|
91
|
-
raise NotImplementedError
|
|
92
|
-
|
|
93
|
-
def _build_url(
|
|
94
|
-
self,
|
|
95
|
-
uuid_or_url: str,
|
|
96
|
-
token: str,
|
|
97
|
-
) -> str:
|
|
98
|
-
base_url = self._build_base_url(uuid_or_url)
|
|
99
|
-
return self.template.format(
|
|
100
|
-
base=base_url,
|
|
101
|
-
token=token,
|
|
102
|
-
)
|
|
103
|
-
|
|
104
|
-
@abstractmethod
|
|
105
|
-
def _format_acl(self, uuid_or_url: str, wildcard: bool) -> Optional[str]:
|
|
106
|
-
raise NotImplementedError
|
|
107
|
-
|
|
108
|
-
@abstractmethod
|
|
109
|
-
def _format_uuid_or_url(self, uuid_or_url: str) -> str:
|
|
110
|
-
raise NotImplementedError
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
class AkamaiSecureUrlBuilderWithAclToken(BaseAkamaiSecureUrlBuilder):
|
|
114
|
-
base_template = "https://{cdn}/{uuid}/"
|
|
115
|
-
|
|
116
|
-
def _build_base_url(self, uuid_or_url: str):
|
|
117
|
-
return self.base_template.format(cdn=self.cdn_url, uuid=uuid_or_url)
|
|
118
|
-
|
|
119
|
-
def _format_acl(self, uuid_or_url: str, wildcard: bool) -> str:
|
|
120
|
-
if wildcard:
|
|
121
|
-
return f"/{uuid_or_url}/*"
|
|
122
|
-
return f"/{uuid_or_url}/"
|
|
123
|
-
|
|
124
|
-
def _format_uuid_or_url(self, uuid_or_url: str) -> str:
|
|
125
|
-
return uuid_or_url.lstrip("/").rstrip("/")
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
class AkamaiSecureUrlBuilderWithUrlToken(BaseAkamaiSecureUrlBuilder):
|
|
129
|
-
def _build_base_url(self, uuid_or_url: str):
|
|
130
|
-
return uuid_or_url
|
|
131
|
-
|
|
132
|
-
def _format_acl(self, uuid_or_url: str, wildcard: bool) -> None:
|
|
133
|
-
if wildcard:
|
|
134
|
-
raise ValueError(
|
|
135
|
-
"Wildcards are not supported in AkamaiSecureUrlBuilderWithUrlToken."
|
|
136
|
-
)
|
|
137
|
-
return None
|
|
138
|
-
|
|
139
|
-
def _format_uuid_or_url(self, uuid_or_url: str) -> str:
|
|
140
|
-
if "://" not in uuid_or_url:
|
|
141
|
-
raise ValueError(f"{uuid_or_url} doesn't look like a URL")
|
|
142
|
-
return uuid_or_url
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
class AkamaiSecureUrlBuilder(AkamaiSecureUrlBuilderWithAclToken):
|
|
146
|
-
def __init__(
|
|
147
|
-
self,
|
|
148
|
-
cdn_url: str,
|
|
149
|
-
secret_key: str,
|
|
150
|
-
window: int = 300,
|
|
151
|
-
hash_algo=hashlib.sha256,
|
|
152
|
-
):
|
|
153
|
-
warnings.warn(
|
|
154
|
-
"AkamaiSecureUrlBuilder class was renamed to AkamaiSecureUrlBuilderWithAclToken",
|
|
155
|
-
DeprecationWarning,
|
|
156
|
-
stacklevel=2,
|
|
157
|
-
)
|
|
158
|
-
super().__init__(
|
|
159
|
-
cdn_url=cdn_url,
|
|
160
|
-
secret_key=secret_key,
|
|
161
|
-
window=window,
|
|
162
|
-
hash_algo=hash_algo,
|
|
163
|
-
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/dj/static/uploadcare/uploadcare.full.min.js
RENAMED
|
File without changes
|
{pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/dj/static/uploadcare/uploadcare.min.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/ucare_cli/commands/convert_document.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pyuploadcare-4.2.2 → pyuploadcare-4.3.0}/pyuploadcare/ucare_cli/commands/upload_from_url.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|