NGPIris 5.7.0.dev3__tar.gz → 5.7.0.dev4__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.
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/NGPIris/cli/__init__.py +1 -1
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/NGPIris/hci/hci_api_requests.py +2 -2
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/NGPIris/hcp/exceptions.py +12 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/NGPIris/hcp/hcp.py +108 -97
- ngpiris-5.7.0.dev4/NGPIris/hcp/helpers.py +372 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/NGPIris/hcp/statistics.py +3 -7
- ngpiris-5.7.0.dev4/NGPIris/hcp/types.py +191 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4/NGPIris.egg-info}/PKG-INFO +13 -8
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/NGPIris.egg-info/requires.txt +2 -1
- {ngpiris-5.7.0.dev3/NGPIris.egg-info → ngpiris-5.7.0.dev4}/PKG-INFO +13 -8
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/README.md +10 -6
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/docs/NGPIris_tutorial.md +18 -21
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/pyproject.toml +7 -3
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/tests/data/80MB_test_file +1 -1
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/tests/data/A/A_80MB_file_0 +1 -1
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/tests/data/A/A_80MB_file_1 +1 -1
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/tests/data/A/B/B_80MB_file_0 +1 -1
- ngpiris-5.7.0.dev3/NGPIris/hcp/helpers.py +0 -171
- ngpiris-5.7.0.dev3/NGPIris/hcp/types.py +0 -45
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/LICENSE +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/MANIFEST.in +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/NGPIris/__init__.py +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/NGPIris/cli/helpers.py +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/NGPIris/cli/sections.py +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/NGPIris/hci/__init__.py +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/NGPIris/hci/exceptions.py +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/NGPIris/hci/hci.py +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/NGPIris/hci/helpers.py +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/NGPIris/hci/query_string.py +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/NGPIris/hci/types.py +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/NGPIris/hcp/__init__.py +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/NGPIris/parse_credentials/__init__.py +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/NGPIris/parse_credentials/parse_credentials.py +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/NGPIris/utils/__init__.py +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/NGPIris/utils/deprecation.py +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/NGPIris/utils/utils.py +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/NGPIris.egg-info/SOURCES.txt +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/NGPIris.egg-info/dependency_links.txt +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/NGPIris.egg-info/entry_points.txt +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/NGPIris.egg-info/top_level.txt +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/docs/Makefile +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/docs/NGPIris.cli.rst +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/docs/NGPIris.hci.rst +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/docs/NGPIris.hcp.rst +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/docs/NGPIris.parse_credentials.rst +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/docs/NGPIris.utils.rst +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/docs/NGPIris_base.rst +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/docs/_static/Iris_HCP_HCI.png +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/docs/_static/gms.png +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/docs/conf.py +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/docs/glossary.rst +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/docs/index.rst +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/docs/make.bat +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/setup.cfg +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/tests/data/complete_creds_0.json +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/tests/data/complete_creds_1.json +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/tests/data/complete_creds_2.json +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/tests/data/incomplete_creds_0.json +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/tests/data/incomplete_creds_1.json +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/tests/data/incomplete_creds_2.json +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/tests/data/incomplete_creds_3.json +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/tests/data/incomplete_creds_4.json +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/tests/test_hci.py +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/tests/test_hcp.py +0 -0
- {ngpiris-5.7.0.dev3 → ngpiris-5.7.0.dev4}/tests/test_parse_credentials.py +0 -0
|
@@ -63,8 +63,8 @@ def get_response(
|
|
|
63
63
|
msg = "Request type is set to POST, but no data was supplied"
|
|
64
64
|
raise DataNotSuppliedToPOSTError(msg)
|
|
65
65
|
|
|
66
|
-
if request_type == "GET" and data:
|
|
67
|
-
msg = "Request type is set to
|
|
66
|
+
if (request_type == "GET") and data:
|
|
67
|
+
msg = "Request type is set to GET, but data was also supplied"
|
|
68
68
|
raise DataSuppliedToGETError(msg)
|
|
69
69
|
|
|
70
70
|
match hci_handler.realm:
|
|
@@ -26,6 +26,12 @@ class NotFoundError(Exception):
|
|
|
26
26
|
"""
|
|
27
27
|
|
|
28
28
|
|
|
29
|
+
class IncorrectPostDataError(Exception):
|
|
30
|
+
"""
|
|
31
|
+
The given request POST data is not correct.
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
|
|
29
35
|
# -------------- Operation response exceptions --------------
|
|
30
36
|
class MetadataCouldNotBeFoundError(Exception):
|
|
31
37
|
"""
|
|
@@ -70,6 +76,12 @@ class BucketForbiddenError(Exception):
|
|
|
70
76
|
"""
|
|
71
77
|
|
|
72
78
|
|
|
79
|
+
class UnknownBucketError(Exception):
|
|
80
|
+
"""
|
|
81
|
+
An unknown error when connecting to the bucket occurred.
|
|
82
|
+
"""
|
|
83
|
+
|
|
84
|
+
|
|
73
85
|
# -------------- Bucket object exceptions --------------
|
|
74
86
|
|
|
75
87
|
|
|
@@ -16,8 +16,12 @@ from boto3.s3.transfer import TransferConfig
|
|
|
16
16
|
from botocore.config import Config
|
|
17
17
|
from botocore.exceptions import ClientError, EndpointConnectionError
|
|
18
18
|
from parse import Result, parse
|
|
19
|
-
from requests import
|
|
20
|
-
from
|
|
19
|
+
from requests import post
|
|
20
|
+
from types_boto3_s3.type_defs import (
|
|
21
|
+
DeleteTypeDef,
|
|
22
|
+
GetBucketAclOutputTypeDef,
|
|
23
|
+
GetObjectAclOutputTypeDef,
|
|
24
|
+
)
|
|
21
25
|
from typing_extensions import Generator # noqa: UP035
|
|
22
26
|
from urllib3 import disable_warnings
|
|
23
27
|
|
|
@@ -29,21 +33,26 @@ from NGPIris.hcp.exceptions import (
|
|
|
29
33
|
IsFolderObjectError,
|
|
30
34
|
NoBucketMountedError,
|
|
31
35
|
NotAValidTenantError,
|
|
32
|
-
NotFoundError,
|
|
33
|
-
NotSufficientPermissionsError,
|
|
34
36
|
ObjectAlreadyExistError,
|
|
35
37
|
ObjectDoesNotExistError,
|
|
36
38
|
SubfolderError,
|
|
37
39
|
UnableToParseEndpointError,
|
|
38
40
|
UnallowedCharacterError,
|
|
41
|
+
UnknownBucketError,
|
|
39
42
|
)
|
|
40
43
|
from NGPIris.hcp.helpers import (
|
|
41
|
-
|
|
44
|
+
add_content_md5_to_headers,
|
|
45
|
+
client_error_response_code_handler,
|
|
42
46
|
create_access_control_policy,
|
|
43
|
-
|
|
47
|
+
delete_object_response_code_handler,
|
|
48
|
+
make_MAPI_request,
|
|
44
49
|
progress_bar_handler,
|
|
45
50
|
raise_path_error,
|
|
46
51
|
)
|
|
52
|
+
from NGPIris.hcp.types import (
|
|
53
|
+
ModifyBucketOptions,
|
|
54
|
+
POSTRequestDataWrapper,
|
|
55
|
+
)
|
|
47
56
|
from NGPIris.parse_credentials import CredentialsHandler
|
|
48
57
|
from NGPIris.utils.deprecation import _add_deprecation_in_doc_string
|
|
49
58
|
|
|
@@ -199,6 +208,12 @@ class HCPHandler:
|
|
|
199
208
|
config=s3_config,
|
|
200
209
|
)
|
|
201
210
|
|
|
211
|
+
self.s3_client.meta.events.register(
|
|
212
|
+
"before-call.s3.DeleteObjects",
|
|
213
|
+
add_content_md5_to_headers,
|
|
214
|
+
unique_id="delete-objects-content-md5",
|
|
215
|
+
)
|
|
216
|
+
|
|
202
217
|
if custom_config_path: # pragma: no cover
|
|
203
218
|
ini_config = ConfigParser()
|
|
204
219
|
ini_config.read(custom_config_path)
|
|
@@ -232,34 +247,39 @@ class HCPHandler:
|
|
|
232
247
|
|
|
233
248
|
:return: The response as a dictionary
|
|
234
249
|
"""
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
"
|
|
240
|
-
}
|
|
241
|
-
response = get(
|
|
242
|
-
url,
|
|
243
|
-
headers=headers,
|
|
244
|
-
verify=self.use_ssl,
|
|
245
|
-
timeout=60,
|
|
250
|
+
return make_MAPI_request(
|
|
251
|
+
self.base_request_url + path_extension,
|
|
252
|
+
self.token,
|
|
253
|
+
self.use_ssl,
|
|
254
|
+
"GET",
|
|
246
255
|
)
|
|
247
256
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
257
|
+
def post_MAPI_request(
|
|
258
|
+
self,
|
|
259
|
+
path_extension: str = "",
|
|
260
|
+
post_data_wrapper: POSTRequestDataWrapper | None = None,
|
|
261
|
+
) -> None:
|
|
262
|
+
"""
|
|
263
|
+
Make a POST request to the HCP in order to use the builtin MAPI.
|
|
264
|
+
|
|
265
|
+
:param path_extension:
|
|
266
|
+
Extension for the base request URL
|
|
267
|
+
|
|
268
|
+
"""
|
|
269
|
+
make_MAPI_request(
|
|
270
|
+
self.base_request_url + path_extension,
|
|
271
|
+
self.token,
|
|
272
|
+
self.use_ssl,
|
|
273
|
+
"POST",
|
|
274
|
+
additional_headers={"Content-Type": "application/json"},
|
|
275
|
+
post_data_wrapper=post_data_wrapper,
|
|
276
|
+
)
|
|
261
277
|
|
|
262
|
-
|
|
278
|
+
def _get_mounted_bucket(self) -> str:
|
|
279
|
+
if not self.bucket_name:
|
|
280
|
+
msg = "No bucket is mounted"
|
|
281
|
+
raise NoBucketMountedError(msg)
|
|
282
|
+
return self.bucket_name
|
|
263
283
|
|
|
264
284
|
# ---------------------------- User methods ----------------------------
|
|
265
285
|
|
|
@@ -283,7 +303,7 @@ class HCPHandler:
|
|
|
283
303
|
self.get_MAPI_request("/userAccounts/" + username)
|
|
284
304
|
.get("roles", {})
|
|
285
305
|
.get("role")
|
|
286
|
-
)
|
|
306
|
+
)
|
|
287
307
|
|
|
288
308
|
def is_user_admin(self, username: str) -> bool:
|
|
289
309
|
"""
|
|
@@ -329,10 +349,15 @@ class HCPHandler:
|
|
|
329
349
|
except EndpointConnectionError: # pragma: no cover
|
|
330
350
|
raise
|
|
331
351
|
except ClientError as e:
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
352
|
+
response_metadata = e.response.get("ResponseMetadata")
|
|
353
|
+
if response_metadata:
|
|
354
|
+
status_code = response_metadata.get(
|
|
355
|
+
"HTTPStatusCode",
|
|
356
|
+
-1,
|
|
357
|
+
)
|
|
358
|
+
else:
|
|
359
|
+
msg = "An unknown error when connecting to the bucket occurred"
|
|
360
|
+
raise UnknownBucketError(msg) from e
|
|
336
361
|
match status_code:
|
|
337
362
|
case 404:
|
|
338
363
|
raise BucketNotFoundError(
|
|
@@ -386,6 +411,20 @@ class HCPHandler:
|
|
|
386
411
|
Bucket=bucket,
|
|
387
412
|
)
|
|
388
413
|
|
|
414
|
+
def modify_bucket(self, bucket: str, options: ModifyBucketOptions) -> None:
|
|
415
|
+
"""
|
|
416
|
+
Modify a specified bucket.
|
|
417
|
+
|
|
418
|
+
:param bucket: The bucket to be modified
|
|
419
|
+
|
|
420
|
+
:param options:
|
|
421
|
+
The settings to modify and the value to make the replacement with
|
|
422
|
+
"""
|
|
423
|
+
self.post_MAPI_request(
|
|
424
|
+
"/namespaces/" + bucket + "/",
|
|
425
|
+
POSTRequestDataWrapper(options, ModifyBucketOptions),
|
|
426
|
+
)
|
|
427
|
+
|
|
389
428
|
class ListBucketsOutputMode(Enum):
|
|
390
429
|
FULL = "full"
|
|
391
430
|
EXTENDED = "extended"
|
|
@@ -508,7 +547,6 @@ class HCPHandler:
|
|
|
508
547
|
|
|
509
548
|
# ---------------------------- Object primitive methods --------------------
|
|
510
549
|
|
|
511
|
-
@check_mounted
|
|
512
550
|
def get_object(self, key: str) -> dict:
|
|
513
551
|
"""
|
|
514
552
|
Get object data and metadata.
|
|
@@ -520,23 +558,22 @@ class HCPHandler:
|
|
|
520
558
|
try:
|
|
521
559
|
response = dict(
|
|
522
560
|
self.s3_client.get_object(
|
|
523
|
-
Bucket=self.
|
|
561
|
+
Bucket=self._get_mounted_bucket(),
|
|
524
562
|
Key=key,
|
|
525
563
|
),
|
|
526
564
|
)
|
|
527
565
|
except ClientError as e:
|
|
528
|
-
|
|
566
|
+
error = e.response.get("Error")
|
|
567
|
+
error_code = error.get("Code", "Unknown") if error else "Unknown"
|
|
568
|
+
if error_code == "NoSuchKey":
|
|
529
569
|
msg = "The object " + key + " does not exist"
|
|
530
570
|
raise ObjectDoesNotExistError(msg) from e
|
|
531
571
|
raise
|
|
532
572
|
else:
|
|
533
573
|
return response
|
|
534
574
|
|
|
535
|
-
@check_mounted
|
|
536
575
|
def get_object_metadata(self, key: str) -> dict:
|
|
537
576
|
"""
|
|
538
|
-
[PRIMITIVE OBJECT METHOD].
|
|
539
|
-
|
|
540
577
|
Retrieve object metadata.
|
|
541
578
|
|
|
542
579
|
:param key: The object name
|
|
@@ -545,15 +582,17 @@ class HCPHandler:
|
|
|
545
582
|
"""
|
|
546
583
|
try:
|
|
547
584
|
metadata_response = dict(
|
|
548
|
-
self.s3_client.head_object(
|
|
585
|
+
self.s3_client.head_object(
|
|
586
|
+
Bucket=self._get_mounted_bucket(), Key=key
|
|
587
|
+
)
|
|
549
588
|
)
|
|
550
589
|
except ClientError as e:
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
rm, "Get object metadata", key, self.bucket_name
|
|
590
|
+
client_error_response_code_handler(
|
|
591
|
+
e, "Get object metadata", key, self.bucket_name
|
|
554
592
|
)
|
|
555
593
|
# This `raise` is most likely useless, but acts as fallback
|
|
556
|
-
# if `
|
|
594
|
+
# if `client_error_response_code_handler` does not raise any
|
|
595
|
+
# exception
|
|
557
596
|
raise
|
|
558
597
|
else:
|
|
559
598
|
return metadata_response
|
|
@@ -567,8 +606,6 @@ class HCPHandler:
|
|
|
567
606
|
|
|
568
607
|
def raise_error_if_object_is_file(self, object_path: str) -> None:
|
|
569
608
|
"""
|
|
570
|
-
[PRIMITIVE OBJECT METHOD].
|
|
571
|
-
|
|
572
609
|
Raises an error if ``object_path`` is a file.
|
|
573
610
|
|
|
574
611
|
:param object_path: The path to the object
|
|
@@ -581,8 +618,6 @@ class HCPHandler:
|
|
|
581
618
|
|
|
582
619
|
def raise_error_if_object_is_folder(self, object_path: str) -> None:
|
|
583
620
|
"""
|
|
584
|
-
[PRIMITIVE OBJECT METHOD].
|
|
585
|
-
|
|
586
621
|
Raises an error if ``object_path`` is a folder.
|
|
587
622
|
|
|
588
623
|
:param object_path: The path to the object
|
|
@@ -593,11 +628,8 @@ class HCPHandler:
|
|
|
593
628
|
msg = "The object " + object_path + " is a folder"
|
|
594
629
|
raise IsFolderObjectError(msg)
|
|
595
630
|
|
|
596
|
-
@check_mounted
|
|
597
631
|
def object_exists(self, key: str) -> bool:
|
|
598
632
|
"""
|
|
599
|
-
[PRIMITIVE OBJECT METHOD].
|
|
600
|
-
|
|
601
633
|
Check if a given object is in the mounted bucket.
|
|
602
634
|
|
|
603
635
|
:param key: The object name
|
|
@@ -620,7 +652,6 @@ class HCPHandler:
|
|
|
620
652
|
|
|
621
653
|
# ---------------------------- Object methods ----------------------------
|
|
622
654
|
|
|
623
|
-
@check_mounted
|
|
624
655
|
def list_objects( # noqa: C901
|
|
625
656
|
self,
|
|
626
657
|
path_key: str = "",
|
|
@@ -674,7 +705,7 @@ class HCPHandler:
|
|
|
674
705
|
|
|
675
706
|
paginator: Paginator = self.s3_client.get_paginator("list_objects_v2")
|
|
676
707
|
pages: PageIterator = paginator.paginate(
|
|
677
|
-
Bucket=self.
|
|
708
|
+
Bucket=self._get_mounted_bucket(),
|
|
678
709
|
Prefix=path_key,
|
|
679
710
|
Delimiter="/",
|
|
680
711
|
)
|
|
@@ -708,7 +739,6 @@ class HCPHandler:
|
|
|
708
739
|
key, file_object_metadata, True, output_mode
|
|
709
740
|
)
|
|
710
741
|
|
|
711
|
-
@check_mounted
|
|
712
742
|
def download_file(
|
|
713
743
|
self,
|
|
714
744
|
key: str,
|
|
@@ -743,12 +773,11 @@ class HCPHandler:
|
|
|
743
773
|
{
|
|
744
774
|
"Key": key,
|
|
745
775
|
"Filename": filename,
|
|
746
|
-
"Bucket": self.
|
|
776
|
+
"Bucket": self._get_mounted_bucket(),
|
|
747
777
|
"Config": self.transfer_config,
|
|
748
778
|
},
|
|
749
779
|
)
|
|
750
780
|
|
|
751
|
-
@check_mounted
|
|
752
781
|
def download_folder(
|
|
753
782
|
self,
|
|
754
783
|
folder_key: str,
|
|
@@ -834,7 +863,6 @@ class HCPHandler:
|
|
|
834
863
|
SIMPLE = "simple"
|
|
835
864
|
EQUAL_PARTS = "equal_parts"
|
|
836
865
|
|
|
837
|
-
@check_mounted
|
|
838
866
|
def upload_file(
|
|
839
867
|
self,
|
|
840
868
|
local_file_path: str,
|
|
@@ -896,12 +924,11 @@ class HCPHandler:
|
|
|
896
924
|
{
|
|
897
925
|
"Filename": local_file_path,
|
|
898
926
|
"Key": key,
|
|
899
|
-
"Bucket": self.
|
|
927
|
+
"Bucket": self._get_mounted_bucket(),
|
|
900
928
|
"Config": config,
|
|
901
929
|
},
|
|
902
930
|
)
|
|
903
931
|
|
|
904
|
-
@check_mounted
|
|
905
932
|
def upload_folder(
|
|
906
933
|
self,
|
|
907
934
|
local_folder_path: str,
|
|
@@ -959,7 +986,6 @@ class HCPHandler:
|
|
|
959
986
|
equal_parts=equal_parts,
|
|
960
987
|
)
|
|
961
988
|
|
|
962
|
-
@check_mounted
|
|
963
989
|
def delete_objects(self, keys: list[str]) -> str:
|
|
964
990
|
"""
|
|
965
991
|
Delete a list of objects on the mounted bucket.
|
|
@@ -981,15 +1007,15 @@ class HCPHandler:
|
|
|
981
1007
|
|
|
982
1008
|
result = ""
|
|
983
1009
|
if object_list:
|
|
984
|
-
deletion_dict = {"Objects": object_list}
|
|
985
|
-
response
|
|
986
|
-
Bucket=self.
|
|
1010
|
+
deletion_dict = DeleteTypeDef({"Objects": object_list})
|
|
1011
|
+
response = self.s3_client.delete_objects(
|
|
1012
|
+
Bucket=self._get_mounted_bucket(),
|
|
987
1013
|
Delete=deletion_dict,
|
|
988
1014
|
)
|
|
989
1015
|
|
|
990
|
-
|
|
1016
|
+
delete_object_response_code_handler(response)
|
|
991
1017
|
|
|
992
|
-
deleted_files: list = [d
|
|
1018
|
+
deleted_files: list = [d.get("Key") for d in response["Deleted"]]
|
|
993
1019
|
result += "The following was successfully deleted: \n" + "\n".join(
|
|
994
1020
|
deleted_files,
|
|
995
1021
|
)
|
|
@@ -1002,7 +1028,6 @@ class HCPHandler:
|
|
|
1002
1028
|
|
|
1003
1029
|
return result
|
|
1004
1030
|
|
|
1005
|
-
@check_mounted
|
|
1006
1031
|
def delete_object(self, key: str) -> str:
|
|
1007
1032
|
"""
|
|
1008
1033
|
Delete a single object in the mounted bucket.
|
|
@@ -1015,7 +1040,6 @@ class HCPHandler:
|
|
|
1015
1040
|
"""
|
|
1016
1041
|
return self.delete_objects([key])
|
|
1017
1042
|
|
|
1018
|
-
@check_mounted
|
|
1019
1043
|
def delete_folder(self, key: str) -> str:
|
|
1020
1044
|
"""
|
|
1021
1045
|
Delete a folder of objects in the mounted bucket.
|
|
@@ -1057,13 +1081,12 @@ class HCPHandler:
|
|
|
1057
1081
|
|
|
1058
1082
|
# Delete the folder object itself separately
|
|
1059
1083
|
self.s3_client.delete_object(
|
|
1060
|
-
Bucket=self.
|
|
1084
|
+
Bucket=self._get_mounted_bucket(),
|
|
1061
1085
|
Key=key,
|
|
1062
1086
|
)
|
|
1063
1087
|
|
|
1064
1088
|
return result
|
|
1065
1089
|
|
|
1066
|
-
@check_mounted
|
|
1067
1090
|
def copy_file(
|
|
1068
1091
|
self,
|
|
1069
1092
|
source_key: str,
|
|
@@ -1089,11 +1112,9 @@ class HCPHandler:
|
|
|
1089
1112
|
self.s3_client.copy,
|
|
1090
1113
|
{
|
|
1091
1114
|
"Key": destination_key,
|
|
1092
|
-
"Bucket": destination_bucket
|
|
1093
|
-
if destination_bucket
|
|
1094
|
-
else self.bucket_name,
|
|
1115
|
+
"Bucket": destination_bucket or self._get_mounted_bucket(),
|
|
1095
1116
|
"CopySource": {
|
|
1096
|
-
"Bucket": self.
|
|
1117
|
+
"Bucket": self._get_mounted_bucket(),
|
|
1097
1118
|
"Key": source_key,
|
|
1098
1119
|
},
|
|
1099
1120
|
},
|
|
@@ -1101,7 +1122,6 @@ class HCPHandler:
|
|
|
1101
1122
|
|
|
1102
1123
|
@_add_deprecation_in_doc_string(_MOVE_FILE_DEP_MSG, "v5.7.0")
|
|
1103
1124
|
@deprecated(_MOVE_FILE_DEP_MSG)
|
|
1104
|
-
@check_mounted
|
|
1105
1125
|
def move_file(
|
|
1106
1126
|
self,
|
|
1107
1127
|
source_key: str, # noqa: ARG002
|
|
@@ -1165,7 +1185,7 @@ class HCPHandler:
|
|
|
1165
1185
|
"+objectPath:(/*"
|
|
1166
1186
|
+ escaped_search
|
|
1167
1187
|
+ "*) +namespace:"
|
|
1168
|
-
+ str(self.
|
|
1188
|
+
+ str(self._get_mounted_bucket())
|
|
1169
1189
|
+ "."
|
|
1170
1190
|
+ str(self.tenant)
|
|
1171
1191
|
)
|
|
@@ -1182,7 +1202,6 @@ class HCPHandler:
|
|
|
1182
1202
|
xml_declaration=False,
|
|
1183
1203
|
)
|
|
1184
1204
|
|
|
1185
|
-
@check_mounted
|
|
1186
1205
|
def mqe_search_in_bucket(
|
|
1187
1206
|
self,
|
|
1188
1207
|
search_string: str,
|
|
@@ -1263,8 +1282,7 @@ class HCPHandler:
|
|
|
1263
1282
|
|
|
1264
1283
|
# ---------------------------- ACL methods ----------------------------
|
|
1265
1284
|
|
|
1266
|
-
|
|
1267
|
-
def get_object_acl(self, key: str) -> dict:
|
|
1285
|
+
def get_object_acl(self, key: str) -> GetObjectAclOutputTypeDef:
|
|
1268
1286
|
"""
|
|
1269
1287
|
Get the object Access Control List (ACL).
|
|
1270
1288
|
|
|
@@ -1272,25 +1290,21 @@ class HCPHandler:
|
|
|
1272
1290
|
|
|
1273
1291
|
:return: Return the ACL in the shape of a dictionary
|
|
1274
1292
|
"""
|
|
1275
|
-
|
|
1276
|
-
Bucket=self.
|
|
1293
|
+
return self.s3_client.get_object_acl(
|
|
1294
|
+
Bucket=self._get_mounted_bucket(),
|
|
1277
1295
|
Key=key,
|
|
1278
1296
|
)
|
|
1279
|
-
return response
|
|
1280
1297
|
|
|
1281
|
-
|
|
1282
|
-
def get_bucket_acl(self) -> dict:
|
|
1298
|
+
def get_bucket_acl(self) -> GetBucketAclOutputTypeDef:
|
|
1283
1299
|
"""
|
|
1284
1300
|
Get the bucket Access Control List (ACL).
|
|
1285
1301
|
|
|
1286
1302
|
:return: Return the ACL in the shape of a dictionary
|
|
1287
1303
|
"""
|
|
1288
|
-
|
|
1289
|
-
Bucket=self.
|
|
1304
|
+
return self.s3_client.get_bucket_acl(
|
|
1305
|
+
Bucket=self._get_mounted_bucket(),
|
|
1290
1306
|
)
|
|
1291
|
-
return response
|
|
1292
1307
|
|
|
1293
|
-
@check_mounted
|
|
1294
1308
|
def modify_single_object_acl(
|
|
1295
1309
|
self,
|
|
1296
1310
|
key: str,
|
|
@@ -1315,14 +1329,13 @@ class HCPHandler:
|
|
|
1315
1329
|
* READ_ACP
|
|
1316
1330
|
"""
|
|
1317
1331
|
self.s3_client.put_object_acl(
|
|
1318
|
-
Bucket=self.
|
|
1332
|
+
Bucket=self._get_mounted_bucket(),
|
|
1319
1333
|
Key=key,
|
|
1320
1334
|
AccessControlPolicy=create_access_control_policy(
|
|
1321
1335
|
{user_ID: permission},
|
|
1322
1336
|
),
|
|
1323
1337
|
)
|
|
1324
1338
|
|
|
1325
|
-
@check_mounted
|
|
1326
1339
|
def modify_single_bucket_acl(self, user_ID: str, permission: str) -> None:
|
|
1327
1340
|
r"""
|
|
1328
1341
|
Modify permissions for a user in the Access Control List (ACL) for the
|
|
@@ -1341,13 +1354,12 @@ class HCPHandler:
|
|
|
1341
1354
|
* READ_ACP
|
|
1342
1355
|
"""
|
|
1343
1356
|
self.s3_client.put_bucket_acl(
|
|
1344
|
-
Bucket=self.
|
|
1357
|
+
Bucket=self._get_mounted_bucket(),
|
|
1345
1358
|
AccessControlPolicy=create_access_control_policy(
|
|
1346
1359
|
{user_ID: permission},
|
|
1347
1360
|
),
|
|
1348
1361
|
)
|
|
1349
1362
|
|
|
1350
|
-
@check_mounted
|
|
1351
1363
|
def modify_object_acl(
|
|
1352
1364
|
self,
|
|
1353
1365
|
key_user_ID_permissions: dict[str, dict[str, str]],
|
|
@@ -1367,14 +1379,13 @@ class HCPHandler:
|
|
|
1367
1379
|
"""
|
|
1368
1380
|
for key, user_ID_permissions in key_user_ID_permissions.items():
|
|
1369
1381
|
self.s3_client.put_object_acl(
|
|
1370
|
-
Bucket=self.
|
|
1382
|
+
Bucket=self._get_mounted_bucket(),
|
|
1371
1383
|
Key=key,
|
|
1372
1384
|
AccessControlPolicy=create_access_control_policy(
|
|
1373
1385
|
user_ID_permissions,
|
|
1374
1386
|
),
|
|
1375
1387
|
)
|
|
1376
1388
|
|
|
1377
|
-
@check_mounted
|
|
1378
1389
|
def modify_bucket_acl(self, user_ID_permissions: dict[str, str]) -> None:
|
|
1379
1390
|
"""
|
|
1380
1391
|
Modify permissions for multiple users for the mounted bucket.
|
|
@@ -1384,7 +1395,7 @@ class HCPHandler:
|
|
|
1384
1395
|
permission to be set to that user
|
|
1385
1396
|
"""
|
|
1386
1397
|
self.s3_client.put_bucket_acl(
|
|
1387
|
-
Bucket=self.
|
|
1398
|
+
Bucket=self._get_mounted_bucket(),
|
|
1388
1399
|
AccessControlPolicy=create_access_control_policy(
|
|
1389
1400
|
user_ID_permissions,
|
|
1390
1401
|
),
|