NGPIris 5.7.0.dev3__py3-none-any.whl → 5.7.0.dev4__py3-none-any.whl
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/cli/__init__.py +1 -1
- NGPIris/hci/hci_api_requests.py +2 -2
- NGPIris/hcp/exceptions.py +12 -0
- NGPIris/hcp/hcp.py +108 -97
- NGPIris/hcp/helpers.py +243 -42
- NGPIris/hcp/statistics.py +3 -7
- NGPIris/hcp/types.py +147 -1
- {ngpiris-5.7.0.dev3.dist-info → ngpiris-5.7.0.dev4.dist-info}/METADATA +13 -8
- {ngpiris-5.7.0.dev3.dist-info → ngpiris-5.7.0.dev4.dist-info}/RECORD +13 -13
- {ngpiris-5.7.0.dev3.dist-info → ngpiris-5.7.0.dev4.dist-info}/WHEEL +0 -0
- {ngpiris-5.7.0.dev3.dist-info → ngpiris-5.7.0.dev4.dist-info}/entry_points.txt +0 -0
- {ngpiris-5.7.0.dev3.dist-info → ngpiris-5.7.0.dev4.dist-info}/licenses/LICENSE +0 -0
- {ngpiris-5.7.0.dev3.dist-info → ngpiris-5.7.0.dev4.dist-info}/top_level.txt +0 -0
NGPIris/cli/__init__.py
CHANGED
NGPIris/hci/hci_api_requests.py
CHANGED
|
@@ -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:
|
NGPIris/hcp/exceptions.py
CHANGED
|
@@ -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
|
|
NGPIris/hcp/hcp.py
CHANGED
|
@@ -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
|
),
|
NGPIris/hcp/helpers.py
CHANGED
|
@@ -1,27 +1,53 @@
|
|
|
1
|
+
import base64
|
|
2
|
+
import hashlib
|
|
1
3
|
import sys
|
|
2
|
-
from functools import wraps
|
|
3
4
|
from pathlib import Path
|
|
4
|
-
from typing import TYPE_CHECKING
|
|
5
|
+
from typing import TYPE_CHECKING, Any, Literal, overload
|
|
5
6
|
|
|
7
|
+
from requests import HTTPError, Response, get, post
|
|
6
8
|
from tqdm import tqdm
|
|
9
|
+
from types_boto3_s3.type_defs import (
|
|
10
|
+
AccessControlPolicyTypeDef,
|
|
11
|
+
DeleteObjectsOutputTypeDef,
|
|
12
|
+
ResponseMetadataTypeDef,
|
|
13
|
+
)
|
|
7
14
|
|
|
15
|
+
from NGPIris.hci.exceptions import (
|
|
16
|
+
DataSuppliedToGETError,
|
|
17
|
+
)
|
|
8
18
|
from NGPIris.hcp.exceptions import (
|
|
19
|
+
IncorrectPostDataError,
|
|
9
20
|
MetadataCouldNotBeFoundError,
|
|
10
|
-
NoBucketMountedError,
|
|
11
21
|
NoStatusCodeSuppliedError,
|
|
22
|
+
NotFoundError,
|
|
23
|
+
NotSufficientPermissionsError,
|
|
12
24
|
ObjectDoesNotExistError,
|
|
13
25
|
OperationNotPermittedError,
|
|
14
26
|
UnknownStatusCodeError,
|
|
15
27
|
)
|
|
28
|
+
from NGPIris.hcp.types import (
|
|
29
|
+
ModifyBucketOptions,
|
|
30
|
+
ModifyBucketOptionsTHQ,
|
|
31
|
+
POSTRequestDataWrapper,
|
|
32
|
+
StandardTypeDict,
|
|
33
|
+
from_ModifyBucketOptions_to_dict,
|
|
34
|
+
from_ModifyBucketOptionsTHQ_to_dict,
|
|
35
|
+
)
|
|
16
36
|
|
|
17
37
|
if TYPE_CHECKING:
|
|
18
38
|
from collections.abc import Callable
|
|
19
39
|
|
|
40
|
+
from botocore.exceptions import ClientError
|
|
20
41
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
42
|
+
|
|
43
|
+
def create_access_control_policy(
|
|
44
|
+
user_ID_permissions: dict[str, str],
|
|
45
|
+
) -> AccessControlPolicyTypeDef:
|
|
46
|
+
"""
|
|
47
|
+
Creates a `AccessControlPolicyTypeDef` typed dictionary for given
|
|
48
|
+
`user_ID_permissions`.
|
|
49
|
+
"""
|
|
50
|
+
grants = []
|
|
25
51
|
for user_ID, permission in user_ID_permissions.items():
|
|
26
52
|
if permission not in [
|
|
27
53
|
"FULL_CONTROL",
|
|
@@ -39,8 +65,12 @@ def create_access_control_policy(user_ID_permissions: dict[str, str]) -> dict:
|
|
|
39
65
|
},
|
|
40
66
|
"Permission": permission,
|
|
41
67
|
}
|
|
42
|
-
|
|
43
|
-
return
|
|
68
|
+
grants.append(grantee)
|
|
69
|
+
return AccessControlPolicyTypeDef(
|
|
70
|
+
{
|
|
71
|
+
"Grants": grants,
|
|
72
|
+
}
|
|
73
|
+
)
|
|
44
74
|
|
|
45
75
|
|
|
46
76
|
def raise_path_error(path: str) -> None:
|
|
@@ -55,44 +85,21 @@ def raise_path_error(path: str) -> None:
|
|
|
55
85
|
raise FileNotFoundError('"' + path + '"' + " does not exist")
|
|
56
86
|
|
|
57
87
|
|
|
58
|
-
def
|
|
59
|
-
|
|
60
|
-
Decorator for checking if a bucket is mounted. This is meant to be used by
|
|
61
|
-
class methods, hence the possibly odd typing.
|
|
62
|
-
|
|
63
|
-
:param method: An arbitrary class method of the `HCPHandler` class
|
|
64
|
-
|
|
65
|
-
:return: A decorated class method of the `HCPHandler` class
|
|
66
|
-
"""
|
|
67
|
-
|
|
68
|
-
@wraps(method)
|
|
69
|
-
def check_if_mounted(*args: P.args, **kwargs: P.kwargs) -> R:
|
|
70
|
-
self = args[0]
|
|
71
|
-
if not self.bucket_name: # pyright: ignore[reportAttributeAccessIssue]
|
|
72
|
-
msg = "No bucket is mounted"
|
|
73
|
-
raise NoBucketMountedError(msg)
|
|
74
|
-
return method(*args, **kwargs)
|
|
75
|
-
|
|
76
|
-
return check_if_mounted
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
def operation_response_code_handler(
|
|
80
|
-
response: dict,
|
|
88
|
+
def _response_metadata_code_handler(
|
|
89
|
+
metadata: ResponseMetadataTypeDef | None,
|
|
81
90
|
operation: str,
|
|
82
91
|
obj: str | dict | None = None,
|
|
83
92
|
bucket: str | None = None,
|
|
84
93
|
) -> None:
|
|
85
94
|
"""
|
|
86
|
-
|
|
87
|
-
errors.
|
|
95
|
+
Raises errors for different status codes.
|
|
88
96
|
|
|
89
|
-
:
|
|
97
|
+
:raises OperationNotPermittedError: If status code is 403
|
|
90
98
|
|
|
91
|
-
:
|
|
92
|
-
|
|
93
|
-
|
|
99
|
+
:raises ObjectDoesNotExistError: If status code is 404
|
|
100
|
+
|
|
101
|
+
:raises NoStatusCodeSuppliedError: If there is no status code
|
|
94
102
|
"""
|
|
95
|
-
metadata: dict = response.get("ResponseMetadata", {})
|
|
96
103
|
if metadata:
|
|
97
104
|
status_code: int | None = metadata.get("HTTPStatusCode")
|
|
98
105
|
match status_code:
|
|
@@ -138,10 +145,61 @@ def operation_response_code_handler(
|
|
|
138
145
|
)
|
|
139
146
|
raise UnknownStatusCodeError(msg)
|
|
140
147
|
else:
|
|
141
|
-
msg =
|
|
148
|
+
msg = str(MetadataCouldNotBeFoundError.__doc__)
|
|
142
149
|
raise MetadataCouldNotBeFoundError(msg)
|
|
143
150
|
|
|
144
151
|
|
|
152
|
+
def client_error_response_code_handler(
|
|
153
|
+
error: ClientError,
|
|
154
|
+
operation: str,
|
|
155
|
+
obj: str | dict | None = None,
|
|
156
|
+
bucket: str | None = None,
|
|
157
|
+
) -> None:
|
|
158
|
+
"""
|
|
159
|
+
Check for status codes from response. If it's anything but 200, raise
|
|
160
|
+
errors.
|
|
161
|
+
|
|
162
|
+
:param response: The response dictionary from an S3 operation
|
|
163
|
+
|
|
164
|
+
:param operation:
|
|
165
|
+
The type of operation that will be displayed in the error
|
|
166
|
+
message.
|
|
167
|
+
|
|
168
|
+
:raises OperationNotPermittedError: If status code is 403
|
|
169
|
+
|
|
170
|
+
:raises ObjectDoesNotExistError: If status code is 404
|
|
171
|
+
|
|
172
|
+
:raises NoStatusCodeSuppliedError: If there is no status code
|
|
173
|
+
"""
|
|
174
|
+
metadata = error.response.get("ResponseMetadata")
|
|
175
|
+
_response_metadata_code_handler(metadata, operation, obj, bucket) # pyright: ignore[reportArgumentType]
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
def delete_object_response_code_handler(
|
|
179
|
+
response: DeleteObjectsOutputTypeDef,
|
|
180
|
+
obj: str | dict | None = None,
|
|
181
|
+
bucket: str | None = None,
|
|
182
|
+
) -> None:
|
|
183
|
+
"""
|
|
184
|
+
Check for status codes from response. If it's anything but 200, raise
|
|
185
|
+
errors.
|
|
186
|
+
|
|
187
|
+
:param response: The response dictionary from an S3 operation
|
|
188
|
+
|
|
189
|
+
:param operation:
|
|
190
|
+
The type of operation that will be displayed in the error
|
|
191
|
+
message.
|
|
192
|
+
|
|
193
|
+
:raises OperationNotPermittedError: If status code is 403
|
|
194
|
+
|
|
195
|
+
:raises ObjectDoesNotExistError: If status code is 404
|
|
196
|
+
|
|
197
|
+
:raises NoStatusCodeSuppliedError: If there is no status code
|
|
198
|
+
"""
|
|
199
|
+
metadata = response.get("ResponseMetadata")
|
|
200
|
+
_response_metadata_code_handler(metadata, "Delete", obj, bucket)
|
|
201
|
+
|
|
202
|
+
|
|
145
203
|
def progress_bar_handler[**P, R](
|
|
146
204
|
show_progress_bar: bool,
|
|
147
205
|
file_size: int,
|
|
@@ -150,7 +208,7 @@ def progress_bar_handler[**P, R](
|
|
|
150
208
|
method_kwargs: dict,
|
|
151
209
|
) -> None:
|
|
152
210
|
"""
|
|
153
|
-
Helper function for
|
|
211
|
+
Helper function for progress bar logic.
|
|
154
212
|
"""
|
|
155
213
|
|
|
156
214
|
def _progress_bar_handler(*args: P.args, **kwargs: P.kwargs) -> None:
|
|
@@ -161,7 +219,7 @@ def progress_bar_handler[**P, R](
|
|
|
161
219
|
unit_scale=True,
|
|
162
220
|
desc=desc,
|
|
163
221
|
) as pbar:
|
|
164
|
-
kwargs["Callback"] = lambda bytes_transferred: pbar.update(
|
|
222
|
+
kwargs["Callback"] = lambda bytes_transferred: pbar.update( # noqa: PLW0108
|
|
165
223
|
bytes_transferred,
|
|
166
224
|
)
|
|
167
225
|
method(*args, **kwargs)
|
|
@@ -169,3 +227,146 @@ def progress_bar_handler[**P, R](
|
|
|
169
227
|
method(*args, **kwargs)
|
|
170
228
|
|
|
171
229
|
_progress_bar_handler(**method_kwargs) # pyright: ignore[reportCallIssue]
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def add_content_md5_to_headers(params: dict, **kwargs) -> None: # noqa: ARG001
|
|
233
|
+
"""
|
|
234
|
+
Function for adding the Content-MD5 header to the
|
|
235
|
+
`before-call.s3.DeleteObjects` event. The reason for this is because the HCP
|
|
236
|
+
requires it and is not supplied automatically since `boto3==1.36.0`.
|
|
237
|
+
"""
|
|
238
|
+
# Hash the exact serialized XML request body, not the Python Delete dict.
|
|
239
|
+
digest = hashlib.md5(
|
|
240
|
+
params["body"],
|
|
241
|
+
usedforsecurity=False,
|
|
242
|
+
).digest()
|
|
243
|
+
|
|
244
|
+
params["headers"]["Content-MD5"] = base64.b64encode(digest).decode("ascii")
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
def _get_transformed_post_data(
|
|
248
|
+
post_data_wrapper: POSTRequestDataWrapper | None = None,
|
|
249
|
+
) -> StandardTypeDict:
|
|
250
|
+
"""
|
|
251
|
+
This function is a bit *cursed*, but the point of it is to type narrow
|
|
252
|
+
albeit in a somewhat unorthodox way.
|
|
253
|
+
"""
|
|
254
|
+
if post_data_wrapper:
|
|
255
|
+
post_data = post_data_wrapper.data
|
|
256
|
+
datatype = post_data_wrapper.datatype
|
|
257
|
+
if datatype is ModifyBucketOptions:
|
|
258
|
+
return from_ModifyBucketOptions_to_dict(
|
|
259
|
+
post_data # pyright: ignore[reportArgumentType]
|
|
260
|
+
)
|
|
261
|
+
elif datatype is ModifyBucketOptionsTHQ: # noqa: RET505
|
|
262
|
+
return from_ModifyBucketOptionsTHQ_to_dict(
|
|
263
|
+
post_data # pyright: ignore[reportArgumentType]
|
|
264
|
+
)
|
|
265
|
+
msg = "The given request POST data is not correct."
|
|
266
|
+
raise IncorrectPostDataError(msg)
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def _handle_MAPI_response(response: Response, url: str) -> None:
|
|
270
|
+
try:
|
|
271
|
+
response.raise_for_status()
|
|
272
|
+
except HTTPError as http_e:
|
|
273
|
+
if response.status_code == 403: # noqa: PLR2004
|
|
274
|
+
msg = "You lack the sufficient permissions needed for your request"
|
|
275
|
+
raise NotSufficientPermissionsError(msg) from http_e
|
|
276
|
+
if response.status_code == 404: # noqa: PLR2004
|
|
277
|
+
msg = "The request URL " + str(url) + " could not be found"
|
|
278
|
+
raise NotFoundError(msg) from http_e
|
|
279
|
+
raise
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
@overload
|
|
283
|
+
def make_MAPI_request(
|
|
284
|
+
url: str,
|
|
285
|
+
token: str,
|
|
286
|
+
use_ssl: bool,
|
|
287
|
+
request_type: Literal["GET"],
|
|
288
|
+
additional_headers: dict[str, str] | None = None,
|
|
289
|
+
post_data_wrapper: None = None,
|
|
290
|
+
) -> dict[Any, Any]: ...
|
|
291
|
+
@overload
|
|
292
|
+
def make_MAPI_request(
|
|
293
|
+
url: str,
|
|
294
|
+
token: str,
|
|
295
|
+
use_ssl: bool,
|
|
296
|
+
request_type: Literal["POST"],
|
|
297
|
+
additional_headers: dict[str, str] | None = None,
|
|
298
|
+
post_data_wrapper: POSTRequestDataWrapper | None = None,
|
|
299
|
+
) -> None: ...
|
|
300
|
+
def make_MAPI_request(
|
|
301
|
+
url: str,
|
|
302
|
+
token: str,
|
|
303
|
+
use_ssl: bool,
|
|
304
|
+
request_type: Literal["GET", "POST"],
|
|
305
|
+
additional_headers: dict[str, str] | None = None,
|
|
306
|
+
post_data_wrapper: POSTRequestDataWrapper | None = None,
|
|
307
|
+
) -> dict[Any, Any] | None:
|
|
308
|
+
"""
|
|
309
|
+
Function for making either a ``GET`` or ``POST`` request to the HCP
|
|
310
|
+
Management API (MAPI).
|
|
311
|
+
|
|
312
|
+
:param url: The endpoint URL for the MAPI request.
|
|
313
|
+
|
|
314
|
+
:param token: Authentication token for the endpoint.
|
|
315
|
+
|
|
316
|
+
:param use_ssl: Boolean choice between using SSL
|
|
317
|
+
|
|
318
|
+
:param request_type: Choice request type
|
|
319
|
+
|
|
320
|
+
:param additional_headers: Optional additional headers
|
|
321
|
+
|
|
322
|
+
:param post_data_wrapper:
|
|
323
|
+
Wrapper class object containing ``POST`` data if that option was picked
|
|
324
|
+
in :py:obj:`request_type`
|
|
325
|
+
|
|
326
|
+
:raises NotSufficientPermissionsError:
|
|
327
|
+
If sufficient permissions was not supplied for your request
|
|
328
|
+
|
|
329
|
+
:raises NotFoundError:
|
|
330
|
+
If the request :py:obj:`url` could not be found
|
|
331
|
+
|
|
332
|
+
:return:
|
|
333
|
+
Either a response in the form of a :py:type:`dict` if the
|
|
334
|
+
:py:obj:`request_type` is ``GET``, otherwise :py:type:`None`
|
|
335
|
+
"""
|
|
336
|
+
if additional_headers is None:
|
|
337
|
+
additional_headers = {}
|
|
338
|
+
|
|
339
|
+
if (request_type == "GET") and post_data_wrapper:
|
|
340
|
+
msg = "Request type is set to GET, but data was also supplied"
|
|
341
|
+
raise DataSuppliedToGETError(msg)
|
|
342
|
+
|
|
343
|
+
base_headers = {
|
|
344
|
+
"Authorization": "HCP " + token,
|
|
345
|
+
"Cookie": "hcp-ns-auth=" + token,
|
|
346
|
+
"Accept": "application/json",
|
|
347
|
+
}
|
|
348
|
+
headers = base_headers | additional_headers
|
|
349
|
+
match request_type:
|
|
350
|
+
case "GET":
|
|
351
|
+
response = get(
|
|
352
|
+
url,
|
|
353
|
+
headers=headers,
|
|
354
|
+
verify=use_ssl,
|
|
355
|
+
timeout=60,
|
|
356
|
+
)
|
|
357
|
+
case "POST":
|
|
358
|
+
transformed_post_data = _get_transformed_post_data(
|
|
359
|
+
post_data_wrapper
|
|
360
|
+
)
|
|
361
|
+
|
|
362
|
+
response = post(
|
|
363
|
+
url,
|
|
364
|
+
json=transformed_post_data,
|
|
365
|
+
headers=headers,
|
|
366
|
+
verify=use_ssl,
|
|
367
|
+
timeout=60,
|
|
368
|
+
)
|
|
369
|
+
|
|
370
|
+
_handle_MAPI_response(response, url)
|
|
371
|
+
|
|
372
|
+
return dict(response.json()) if request_type == "GET" else None
|
NGPIris/hcp/statistics.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
from NGPIris import HCPHandler
|
|
2
|
-
from NGPIris.hcp.helpers import check_mounted
|
|
3
2
|
|
|
4
3
|
|
|
5
4
|
class HCPStatistics(HCPHandler):
|
|
@@ -19,16 +18,14 @@ class HCPStatistics(HCPHandler):
|
|
|
19
18
|
"""
|
|
20
19
|
super().__init__(credentials_path, use_ssl, custom_config_path)
|
|
21
20
|
|
|
22
|
-
@check_mounted
|
|
23
21
|
def get_namespace_settings(self) -> dict:
|
|
24
22
|
"""
|
|
25
23
|
Get namespace/bucket settings.
|
|
26
24
|
|
|
27
25
|
:return: Namespace/bucket settings as a dictionary.
|
|
28
26
|
"""
|
|
29
|
-
return self.get_response("/namespaces/" + self.
|
|
27
|
+
return self.get_response("/namespaces/" + self._get_mounted_bucket()) # pyright: ignore[reportOperatorIssue, reportAttributeAccessIssue]
|
|
30
28
|
|
|
31
|
-
@check_mounted
|
|
32
29
|
def get_namespace_statistics(self) -> dict:
|
|
33
30
|
"""
|
|
34
31
|
Get namespace/bucket statistics.
|
|
@@ -36,10 +33,9 @@ class HCPStatistics(HCPHandler):
|
|
|
36
33
|
:return: Namespace/bucket statistics as a dictionary.
|
|
37
34
|
"""
|
|
38
35
|
return self.get_response( # pyright: ignore[reportAttributeAccessIssue]
|
|
39
|
-
"/namespaces/" + self.
|
|
36
|
+
"/namespaces/" + self._get_mounted_bucket() + "/statistics", # pyright: ignore[reportOperatorIssue]
|
|
40
37
|
)
|
|
41
38
|
|
|
42
|
-
@check_mounted
|
|
43
39
|
def get_namespace_permissions(self) -> dict:
|
|
44
40
|
"""
|
|
45
41
|
Get namespace/bucket permissions.
|
|
@@ -47,5 +43,5 @@ class HCPStatistics(HCPHandler):
|
|
|
47
43
|
:return: Namespace/bucket permissions as a dictionary.
|
|
48
44
|
"""
|
|
49
45
|
return self.get_response( # pyright: ignore[reportAttributeAccessIssue]
|
|
50
|
-
"/namespaces/" + self.
|
|
46
|
+
"/namespaces/" + self._get_mounted_bucket() + "/permissions", # pyright: ignore[reportOperatorIssue]
|
|
51
47
|
)
|
NGPIris/hcp/types.py
CHANGED
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
from
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from typing import TYPE_CHECKING, Any, Literal, TypedDict, TypeIs
|
|
3
|
+
|
|
4
|
+
if TYPE_CHECKING:
|
|
5
|
+
from collections.abc import Callable
|
|
2
6
|
|
|
3
7
|
# ruff: noqa: N801
|
|
4
8
|
|
|
5
9
|
|
|
10
|
+
# MQE types -------------------------------------------------
|
|
11
|
+
|
|
12
|
+
|
|
6
13
|
class MQE_ResultSet(TypedDict):
|
|
7
14
|
"""
|
|
8
15
|
Typed dictionary for the `ResultSet` dictionaries inside of
|
|
@@ -43,3 +50,142 @@ class MQE_QueryResult(TypedDict):
|
|
|
43
50
|
query: MQE_Query
|
|
44
51
|
resultSet: list[MQE_ResultSet]
|
|
45
52
|
status: MQE_Status
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
# POST Request types -------------------------------------------------
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
class POSTRequestData(TypedDict):
|
|
59
|
+
"""
|
|
60
|
+
Super type for all :py:class:`TypedDict` sub types that are POST request
|
|
61
|
+
data.
|
|
62
|
+
"""
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
class HardQuotaString(TypedDict):
|
|
66
|
+
"""
|
|
67
|
+
Type for modelling the hard quota string.
|
|
68
|
+
"""
|
|
69
|
+
|
|
70
|
+
size: int
|
|
71
|
+
unit: Literal["GB", "TB"]
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
class ModifyBucketOptions(POSTRequestData, total=False):
|
|
75
|
+
"""
|
|
76
|
+
Type for modelling the POST request data for modifying a bucket.
|
|
77
|
+
"""
|
|
78
|
+
|
|
79
|
+
description: str
|
|
80
|
+
fullyQualifiedName: str
|
|
81
|
+
hardQuota: HardQuotaString
|
|
82
|
+
name: str
|
|
83
|
+
owner: str
|
|
84
|
+
replicationEnabled: bool
|
|
85
|
+
searchEnabled: bool
|
|
86
|
+
softQuota: int # Must be between 10 and 95, inclusive.
|
|
87
|
+
id: str
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
class ModifyBucketOptionsTHQ(POSTRequestData, total=False):
|
|
91
|
+
"""
|
|
92
|
+
Same as :py:class:`ModifyBucketOptions`, but with the hard quota parameter
|
|
93
|
+
being a string. Therefore, it is more prone to errors than
|
|
94
|
+
:py:class:`ModifyBucketOptions`.
|
|
95
|
+
THQ = Transformed Hard Quota.
|
|
96
|
+
"""
|
|
97
|
+
|
|
98
|
+
description: str
|
|
99
|
+
fullyQualifiedName: str
|
|
100
|
+
hardQuota: str
|
|
101
|
+
name: str
|
|
102
|
+
owner: str
|
|
103
|
+
replicationEnabled: bool
|
|
104
|
+
searchEnabled: bool
|
|
105
|
+
softQuota: int # Must be between 10 and 95, inclusive.
|
|
106
|
+
id: str
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
@dataclass
|
|
110
|
+
class POSTRequestDataWrapper:
|
|
111
|
+
"""
|
|
112
|
+
Wrapper class for :py:class:`POSTRequestData` used for type checking.
|
|
113
|
+
"""
|
|
114
|
+
|
|
115
|
+
data: POSTRequestData
|
|
116
|
+
datatype: type[POSTRequestData]
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
NonStandardType = HardQuotaString
|
|
120
|
+
StandardType = str | int | bool
|
|
121
|
+
StandardTypeDict = dict[str, StandardType]
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
def value_is_StandardType(value: Any) -> TypeIs[StandardType]: # noqa: ANN401
|
|
125
|
+
"""
|
|
126
|
+
Type narrowing function for :py:type:`StandardType`.
|
|
127
|
+
"""
|
|
128
|
+
return isinstance(value, StandardType)
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def from_POSTRequestData_to_dict(
|
|
132
|
+
options: POSTRequestData,
|
|
133
|
+
transformation_functions: dict[
|
|
134
|
+
str, Callable[[NonStandardType], StandardType]
|
|
135
|
+
],
|
|
136
|
+
) -> StandardTypeDict:
|
|
137
|
+
"""
|
|
138
|
+
Helper function for turning a :py:class:`POSTRequestData` object or
|
|
139
|
+
subclassed objects into a :py:type:`dict`. It achieves this by a somewhat
|
|
140
|
+
*unorthodox* approach.
|
|
141
|
+
"""
|
|
142
|
+
d: StandardTypeDict = {}
|
|
143
|
+
for key, value in options.items(): # pyright: ignore[reportAssignmentType]
|
|
144
|
+
value: NonStandardType | StandardType
|
|
145
|
+
if value_is_StandardType(value):
|
|
146
|
+
d[key] = value
|
|
147
|
+
elif key in transformation_functions:
|
|
148
|
+
transformation_function = transformation_functions[key]
|
|
149
|
+
|
|
150
|
+
d[key] = transformation_function(value)
|
|
151
|
+
|
|
152
|
+
return d
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def from_ModifyBucketOptions_to_dict(
|
|
156
|
+
options: ModifyBucketOptions,
|
|
157
|
+
) -> StandardTypeDict:
|
|
158
|
+
"""
|
|
159
|
+
Helper function for turning a :py:class:`ModifyBucketOptions` into a
|
|
160
|
+
:py:type:`dict`. It achieves this by a somewhat
|
|
161
|
+
*unorthodox* approach.
|
|
162
|
+
"""
|
|
163
|
+
return from_POSTRequestData_to_dict(
|
|
164
|
+
options,
|
|
165
|
+
{"hardQuota": lambda value: str(value["size"]) + " " + value["unit"]},
|
|
166
|
+
)
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def from_ModifyBucketOptionsTHQ_to_dict(
|
|
170
|
+
options: ModifyBucketOptionsTHQ,
|
|
171
|
+
) -> StandardTypeDict:
|
|
172
|
+
"""
|
|
173
|
+
Helper function for turning a :py:class:`ModifyBucketOptionsTHQ` into a
|
|
174
|
+
:py:type:`dict`. It achieves this by a somewhat
|
|
175
|
+
*unorthodox* approach.
|
|
176
|
+
"""
|
|
177
|
+
return from_POSTRequestData_to_dict(options, {})
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def to_ModifyBucketOptionsTHQ(
|
|
181
|
+
options: ModifyBucketOptions,
|
|
182
|
+
) -> ModifyBucketOptionsTHQ:
|
|
183
|
+
"""
|
|
184
|
+
Helper function for turning a :py:class:`ModifyBucketOptions` into a
|
|
185
|
+
:py:class:`ModifyBucketOptionsTHQ`. It achieves this by a somewhat
|
|
186
|
+
*unorthodox* approach.
|
|
187
|
+
"""
|
|
188
|
+
return ModifyBucketOptionsTHQ(from_ModifyBucketOptions_to_dict(options)) # pyright: ignore[reportArgumentType]
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
# -------------------------------------------------
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: NGPIris
|
|
3
|
-
Version: 5.7.0.
|
|
3
|
+
Version: 5.7.0.dev4
|
|
4
4
|
Author-email: Erik Brink <erik.brink@gu.se>, Sven Kristian Feddersen <sven.kristian.feddersen@gu.se>
|
|
5
5
|
Requires-Python: >=3.14
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
7
7
|
License-File: LICENSE
|
|
8
8
|
Requires-Dist: bitmath==1.3.3.1
|
|
9
|
-
Requires-Dist: boto3==1.
|
|
9
|
+
Requires-Dist: boto3==1.44.10
|
|
10
10
|
Requires-Dist: click>=8.3.0
|
|
11
11
|
Requires-Dist: parse>=1.19.1
|
|
12
12
|
Requires-Dist: requests>=2.31.0
|
|
@@ -15,19 +15,17 @@ Requires-Dist: tabulate>=0.9.0
|
|
|
15
15
|
Requires-Dist: tqdm>=4.66.2
|
|
16
16
|
Requires-Dist: urllib3==2.8.0
|
|
17
17
|
Requires-Dist: typing-extensions>=4.16.0
|
|
18
|
+
Requires-Dist: types-boto3-custom
|
|
18
19
|
Dynamic: license-file
|
|
19
20
|
|
|
20
21
|
# NGP IRIS 👀
|
|
21
22
|
|
|
22
|
-
NGP IRIS, or just Iris, is a tool for interacting with a Hitachi Content Platform (HCP)
|
|
23
|
-
|
|
24
|
-
- A simple, clear, real-time interaction with NGPr file management
|
|
25
|
-
- Improving process flow for performing off-site data analysis by using automated transfer scripts
|
|
26
|
-
|
|
27
|
-
Both of these cases can be achieved as either a [Python package](#as-a-python-package) or as a [Command Line Interface (CLI)](#as-a-command-line-tool).
|
|
23
|
+
NGP IRIS, or just Iris, is a tool for interacting with NGPr, which is a Hitachi Content Platform (HCP), and NGPi, which is a Hitachi Content Intelligence (HCI).
|
|
28
24
|
|
|
29
25
|
## Getting started
|
|
30
26
|
|
|
27
|
+
If you are new to using Iris, check out the beginner's tutorial that can be found in [iris package documentation](#compiling-the-documentation).
|
|
28
|
+
|
|
31
29
|
### Prerequisites
|
|
32
30
|
|
|
33
31
|
- Python 3.14
|
|
@@ -94,6 +92,13 @@ This will prompt Iris to complain about incomplete credentials (since the entrie
|
|
|
94
92
|
|
|
95
93
|
A thorough package documentation can be found in the technical documentation pages. In order to compile the documentation, see [here](#compiling-the-documentation).
|
|
96
94
|
|
|
95
|
+
### Compiling type annotations for `boto3`
|
|
96
|
+
|
|
97
|
+
1. Generate type annotations locally: `uvx --with 'boto3==1.*.*' mypy-boto3-builder` for the current version of `boto3`
|
|
98
|
+
2. Select `boto3-stubs` AWS SDK.
|
|
99
|
+
3. Add S3 service. You might need to de-select other auxiliary services.
|
|
100
|
+
4. The the generated install command such as `uv add --dev vendored/types_boto3_custom-1.43.94-py3-none-any.whl` for `boto3==1.43.94`
|
|
101
|
+
|
|
97
102
|
## Basic usage
|
|
98
103
|
|
|
99
104
|
Iris can be used as a Python package or by using the command line. The following sections cover some examples of how Iris might be used as a package and how to use its various commands. However, we highly recommend reading out the [tutorial](/docs/NGPIris_tutorial.md) containing more example use cases and explanations.
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
NGPIris/__init__.py,sha256=x38JofBWRO0OX8AG0u92j-Q35u1fxx2Q0FVlOTx1YAA,124
|
|
2
|
-
NGPIris/cli/__init__.py,sha256
|
|
2
|
+
NGPIris/cli/__init__.py,sha256=-2bKIrxSITFbS2n2qqMfRKn8Wx4grwtByWtdFIbmbD8,19843
|
|
3
3
|
NGPIris/cli/helpers.py,sha256=Zd1pHFhvsjJufU-ZgF18LHvaXUhF90wfl7PWp54oquY,5712
|
|
4
4
|
NGPIris/cli/sections.py,sha256=9aUkpmIRsWEa8Rq7mjcii4oK6-tEMaYv6XAK7FgWEo4,1894
|
|
5
5
|
NGPIris/hci/__init__.py,sha256=9YlaEPofTVXuFvqZ2aCjsDrLn8zNU97CYwImMHJAswc,68
|
|
6
6
|
NGPIris/hci/exceptions.py,sha256=fLgJQet-zxXoLq4W1MJPE6HzvNwNC1TT3GApGaC8KOc,414
|
|
7
7
|
NGPIris/hci/hci.py,sha256=5f0ERol5F5f5RH9HbQRaWm_ZvUXdhS9G2fkKKJRUyUs,8170
|
|
8
|
-
NGPIris/hci/hci_api_requests.py,sha256=
|
|
8
|
+
NGPIris/hci/hci_api_requests.py,sha256=NqwiotqzEhVznGR8WwT0APyH30RCpGPx3QBc0GgktDU,4701
|
|
9
9
|
NGPIris/hci/helpers.py,sha256=bh8M3PBiMBNlE4tPdO9SPfvhYxPOOXJgbjQ0uQeZoOQ,2675
|
|
10
10
|
NGPIris/hci/query_string.py,sha256=kiGNcCWhnZ_fOINNaXQAAL9uR_rArjd6gVXVB1b-3SA,3362
|
|
11
11
|
NGPIris/hci/types.py,sha256=W8LflWJKDPudHZ0rIW2tdcaZ1zCOBJx2zPTv9ra3zXw,7987
|
|
12
12
|
NGPIris/hcp/__init__.py,sha256=XcwyGKjCIBapkONvurw_sFNJC3EiYenJwRa4foS8unY,68
|
|
13
|
-
NGPIris/hcp/exceptions.py,sha256=
|
|
14
|
-
NGPIris/hcp/hcp.py,sha256=
|
|
15
|
-
NGPIris/hcp/helpers.py,sha256=
|
|
16
|
-
NGPIris/hcp/statistics.py,sha256=
|
|
17
|
-
NGPIris/hcp/types.py,sha256=
|
|
13
|
+
NGPIris/hcp/exceptions.py,sha256=tbICbSzL6nD_PPzoeieQP8VTdwBEv3ebOAlZtRb0nUs,2683
|
|
14
|
+
NGPIris/hcp/hcp.py,sha256=6_Ks8G8jwLN-LrNAoRvgB8vtKeCjL6Ua9ncpv4nu7cg,47176
|
|
15
|
+
NGPIris/hcp/helpers.py,sha256=XsoN6_REMelU_7gC0kO70z0ItnmvD5DXAC-qcObkP90,11508
|
|
16
|
+
NGPIris/hcp/statistics.py,sha256=NmPf_YAXWBDu5zfVZgswPNIMsXRMLOk-NPs5Q-XxP2E,1588
|
|
17
|
+
NGPIris/hcp/types.py,sha256=s5H_-fvFpqimlSvJH_O9q8823OADCEMz0MFP1bELHuI,4719
|
|
18
18
|
NGPIris/parse_credentials/__init__.py,sha256=QFVAAgOC2rGYHUj_auA-5WUobiFqdYa7gbaI4ksp4Qk,98
|
|
19
19
|
NGPIris/parse_credentials/parse_credentials.py,sha256=meUCqTOpsBqTXS-tpN_JUxyvoUXTsYL9il23ClNDIKw,2842
|
|
20
20
|
NGPIris/utils/__init__.py,sha256=MSJyKBuxCBYH7a7C03lO0D5d8exS3t2KTg-qJvWL08o,119
|
|
21
21
|
NGPIris/utils/deprecation.py,sha256=RdG87CjBUpjWdTZUXWjXOTA4hvP_ItUb8JWkhYIExlA,1128
|
|
22
22
|
NGPIris/utils/utils.py,sha256=FqJpQHDJmZk5Pafzm3sW6WfXvEi4sKCM463_pITMx_o,367
|
|
23
|
-
ngpiris-5.7.0.
|
|
24
|
-
ngpiris-5.7.0.
|
|
25
|
-
ngpiris-5.7.0.
|
|
26
|
-
ngpiris-5.7.0.
|
|
27
|
-
ngpiris-5.7.0.
|
|
28
|
-
ngpiris-5.7.0.
|
|
23
|
+
ngpiris-5.7.0.dev4.dist-info/licenses/LICENSE,sha256=ZA2Q9u5AEkH_YoNNDRsz-DBJ6ZuL_foE7RsKFjXd4-c,18093
|
|
24
|
+
ngpiris-5.7.0.dev4.dist-info/METADATA,sha256=ZeLjXycmfyo1PH2MqmT2OpAbPdpkMP8_G4h6LFg6jko,6774
|
|
25
|
+
ngpiris-5.7.0.dev4.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
26
|
+
ngpiris-5.7.0.dev4.dist-info/entry_points.txt,sha256=t8ADhe3ovPm9tW3XDZq1_vKmfHY98Ei_o6WioJobNzU,117
|
|
27
|
+
ngpiris-5.7.0.dev4.dist-info/top_level.txt,sha256=954WCuIJkle_SMtr7MNPapiiLLAFhlKbcz6Bp89-2V0,8
|
|
28
|
+
ngpiris-5.7.0.dev4.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|