NGPIris 5.6.8__tar.gz → 5.7.0.dev1__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.dev1/NGPIris/__init__.py +4 -0
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/NGPIris/cli/__init__.py +36 -161
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/NGPIris/cli/helpers.py +18 -6
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/NGPIris/cli/sections.py +0 -4
- ngpiris-5.7.0.dev1/NGPIris/hci/__init__.py +3 -0
- ngpiris-5.7.0.dev1/NGPIris/hci/exceptions.py +25 -0
- ngpiris-5.7.0.dev1/NGPIris/hci/hci.py +245 -0
- ngpiris-5.7.0.dev1/NGPIris/hci/hci_api_requests.py +162 -0
- ngpiris-5.7.0.dev1/NGPIris/hci/helpers.py +86 -0
- ngpiris-5.7.0.dev1/NGPIris/hci/query_string.py +100 -0
- ngpiris-5.7.0.dev1/NGPIris/hci/types.py +300 -0
- ngpiris-5.7.0.dev1/NGPIris/hcp/__init__.py +3 -0
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/NGPIris/hcp/hcp.py +188 -195
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/NGPIris/hcp/helpers.py +3 -12
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/NGPIris/hcp/statistics.py +0 -3
- ngpiris-5.7.0.dev1/NGPIris/hcp/types.py +45 -0
- ngpiris-5.7.0.dev1/NGPIris/parse_credentials/__init__.py +3 -0
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/NGPIris/parse_credentials/parse_credentials.py +5 -11
- ngpiris-5.7.0.dev1/NGPIris/utils/__init__.py +3 -0
- ngpiris-5.7.0.dev1/NGPIris/utils/deprecation.py +43 -0
- ngpiris-5.7.0.dev1/NGPIris.egg-info/PKG-INFO +204 -0
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/NGPIris.egg-info/SOURCES.txt +10 -4
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/NGPIris.egg-info/requires.txt +5 -7
- ngpiris-5.7.0.dev1/PKG-INFO +204 -0
- ngpiris-5.7.0.dev1/README.md +186 -0
- ngpiris-5.7.0.dev1/docs/NGPIris.cli.rst +16 -0
- ngpiris-5.7.0.dev1/docs/NGPIris.hci.rst +45 -0
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/docs/NGPIris.hcp.rst +16 -25
- ngpiris-5.7.0.dev1/docs/NGPIris.parse_credentials.rst +12 -0
- ngpiris-5.7.0.dev1/docs/NGPIris.utils.rst +12 -0
- ngpiris-5.7.0.dev1/docs/NGPIris_base.rst +13 -0
- ngpiris-5.7.0.dev1/docs/NGPIris_tutorial.md +614 -0
- ngpiris-5.7.0.dev1/docs/_static/Iris_HCP_HCI.png +0 -0
- ngpiris-5.7.0.dev1/docs/_static/gms.png +0 -0
- ngpiris-5.7.0.dev1/docs/conf.py +99 -0
- ngpiris-5.7.0.dev1/docs/glossary.rst +49 -0
- ngpiris-5.7.0.dev1/docs/index.rst +22 -0
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/pyproject.toml +17 -11
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/tests/data/80MB_test_file +1 -1
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/tests/data/A/A_80MB_file_0 +1 -1
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/tests/data/A/A_80MB_file_1 +1 -1
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/tests/data/A/B/B_80MB_file_0 +1 -1
- ngpiris-5.7.0.dev1/tests/test_hci.py +61 -0
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/tests/test_hcp.py +61 -56
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/tests/test_parse_credentials.py +6 -2
- ngpiris-5.6.8/NGPIris/__init__.py +0 -4
- ngpiris-5.6.8/NGPIris/hci/__init__.py +0 -0
- ngpiris-5.6.8/NGPIris/hci/exceptions.py +0 -0
- ngpiris-5.6.8/NGPIris/hci/hci.py +0 -222
- ngpiris-5.6.8/NGPIris/hci/helpers.py +0 -100
- ngpiris-5.6.8/NGPIris/hcp/__init__.py +0 -0
- ngpiris-5.6.8/NGPIris/parse_credentials/__init__.py +0 -3
- ngpiris-5.6.8/NGPIris/utils/__init__.py +0 -3
- ngpiris-5.6.8/NGPIris.egg-info/PKG-INFO +0 -197
- ngpiris-5.6.8/PKG-INFO +0 -197
- ngpiris-5.6.8/README.md +0 -177
- ngpiris-5.6.8/docs/IRIS_5_changelog.md +0 -43
- ngpiris-5.6.8/docs/NGPIris.cli.rst +0 -10
- ngpiris-5.6.8/docs/NGPIris.hci.rst +0 -37
- ngpiris-5.6.8/docs/NGPIris.parse_credentials.rst +0 -21
- ngpiris-5.6.8/docs/NGPIris.rst +0 -22
- ngpiris-5.6.8/docs/NGPIris.utils.rst +0 -21
- ngpiris-5.6.8/docs/Tutorial.md +0 -317
- ngpiris-5.6.8/docs/conf.py +0 -36
- ngpiris-5.6.8/docs/index.rst +0 -21
- ngpiris-5.6.8/docs/modules.rst +0 -7
- ngpiris-5.6.8/tests/test_hci.py +0 -91
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/LICENSE +0 -0
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/MANIFEST.in +0 -0
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/NGPIris/hcp/exceptions.py +0 -0
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/NGPIris/utils/utils.py +0 -0
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/NGPIris.egg-info/dependency_links.txt +0 -0
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/NGPIris.egg-info/entry_points.txt +0 -0
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/NGPIris.egg-info/top_level.txt +0 -0
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/docs/Makefile +0 -0
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/docs/make.bat +0 -0
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/setup.cfg +0 -0
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/tests/data/complete_creds_0.json +0 -0
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/tests/data/complete_creds_1.json +0 -0
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/tests/data/complete_creds_2.json +0 -0
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/tests/data/incomplete_creds_0.json +0 -0
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/tests/data/incomplete_creds_1.json +0 -0
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/tests/data/incomplete_creds_2.json +0 -0
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/tests/data/incomplete_creds_3.json +0 -0
- {ngpiris-5.6.8 → ngpiris-5.7.0.dev1}/tests/data/incomplete_creds_4.json +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# ruff: noqa: SLF001
|
|
1
|
+
# ruff: noqa: SLF001 # noqa: N999
|
|
2
2
|
|
|
3
3
|
import sys
|
|
4
4
|
from json import dump
|
|
@@ -6,7 +6,6 @@ from pathlib import Path
|
|
|
6
6
|
from typing import TYPE_CHECKING, Any
|
|
7
7
|
|
|
8
8
|
import click
|
|
9
|
-
from bitmath import SI, Byte
|
|
10
9
|
from tabulate import tabulate
|
|
11
10
|
|
|
12
11
|
from NGPIris import HCPHandler
|
|
@@ -16,6 +15,7 @@ from NGPIris.cli.helpers import (
|
|
|
16
15
|
download_file,
|
|
17
16
|
download_folder,
|
|
18
17
|
ensure_destination_dir,
|
|
18
|
+
format_object_sizes,
|
|
19
19
|
render_objects_table,
|
|
20
20
|
)
|
|
21
21
|
from NGPIris.cli.sections import SectionedGroup
|
|
@@ -87,7 +87,7 @@ def cli(
|
|
|
87
87
|
is_flag=True,
|
|
88
88
|
)
|
|
89
89
|
@click.pass_context
|
|
90
|
-
def copy(
|
|
90
|
+
def copy(
|
|
91
91
|
context: Context,
|
|
92
92
|
bucket: str,
|
|
93
93
|
source: str,
|
|
@@ -115,57 +115,6 @@ def copy( # noqa: PLR0913
|
|
|
115
115
|
)
|
|
116
116
|
|
|
117
117
|
|
|
118
|
-
@cli.command(
|
|
119
|
-
section="Object commands",
|
|
120
|
-
short_help="Move objects in a bucket/namespace on the HCP.",
|
|
121
|
-
)
|
|
122
|
-
@click.argument("bucket")
|
|
123
|
-
@click.argument("source")
|
|
124
|
-
@click.argument("destination")
|
|
125
|
-
@click.option(
|
|
126
|
-
"-db",
|
|
127
|
-
"--destination_bucket",
|
|
128
|
-
help="Choose another destination bucket than the source bucket",
|
|
129
|
-
default="",
|
|
130
|
-
)
|
|
131
|
-
@click.option(
|
|
132
|
-
"-dr",
|
|
133
|
-
"--dry_run",
|
|
134
|
-
help=(
|
|
135
|
-
"Simulate the command execution without making actual changes. "
|
|
136
|
-
"Useful for testing and verification"
|
|
137
|
-
),
|
|
138
|
-
is_flag=True,
|
|
139
|
-
)
|
|
140
|
-
@click.pass_context
|
|
141
|
-
def move( # noqa: PLR0913
|
|
142
|
-
context: Context,
|
|
143
|
-
bucket: str,
|
|
144
|
-
source: str,
|
|
145
|
-
destination: str,
|
|
146
|
-
destination_bucket: str,
|
|
147
|
-
dry_run: bool,
|
|
148
|
-
) -> None:
|
|
149
|
-
"""
|
|
150
|
-
Move objects in a bucket/namespace on the HCP.
|
|
151
|
-
|
|
152
|
-
BUCKET is the bucket where SOURCE is.
|
|
153
|
-
|
|
154
|
-
SOURCE is the object to be moved.
|
|
155
|
-
|
|
156
|
-
DESTINATION is the destination path (the path where the object will be
|
|
157
|
-
moved to).
|
|
158
|
-
"""
|
|
159
|
-
hcp_h: HCPHandler = create_HCPHandler(context)
|
|
160
|
-
hcp_h.mount_bucket(bucket)
|
|
161
|
-
if not dry_run:
|
|
162
|
-
hcp_h.move_file(source, destination, destination_bucket)
|
|
163
|
-
else:
|
|
164
|
-
click.echo(
|
|
165
|
-
'This command would have moved the file object "' + source + '"',
|
|
166
|
-
)
|
|
167
|
-
|
|
168
|
-
|
|
169
118
|
@cli.command(
|
|
170
119
|
section="Object commands",
|
|
171
120
|
short_help="Delete objects in a bucket/namespace on the HCP.",
|
|
@@ -255,9 +204,11 @@ def delete(
|
|
|
255
204
|
+ "(this list excludes any potential sub-folders):",
|
|
256
205
|
)
|
|
257
206
|
render_objects_table(
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
207
|
+
format_object_sizes(
|
|
208
|
+
hcp_h.list_objects(
|
|
209
|
+
hcp_object,
|
|
210
|
+
files_only=True,
|
|
211
|
+
)
|
|
261
212
|
),
|
|
262
213
|
-1,
|
|
263
214
|
)
|
|
@@ -294,7 +245,7 @@ def delete(
|
|
|
294
245
|
is_flag=True,
|
|
295
246
|
)
|
|
296
247
|
@click.pass_context
|
|
297
|
-
def download(
|
|
248
|
+
def download(
|
|
298
249
|
context: Context,
|
|
299
250
|
bucket: str,
|
|
300
251
|
source: str,
|
|
@@ -378,7 +329,7 @@ def download( # noqa: PLR0913
|
|
|
378
329
|
is_flag=True,
|
|
379
330
|
)
|
|
380
331
|
@click.pass_context
|
|
381
|
-
def list_objects(
|
|
332
|
+
def list_objects(
|
|
382
333
|
context: Context,
|
|
383
334
|
bucket: str,
|
|
384
335
|
path: str | None,
|
|
@@ -414,24 +365,6 @@ def list_objects( # noqa: PLR0913
|
|
|
414
365
|
for obj in objects:
|
|
415
366
|
yield str(obj) + "\n"
|
|
416
367
|
|
|
417
|
-
def list_objects_generator(
|
|
418
|
-
hcp_h: HCPHandler,
|
|
419
|
-
path: str,
|
|
420
|
-
output_mode: HCPHandler.ListObjectsOutputMode,
|
|
421
|
-
files_only: bool,
|
|
422
|
-
) -> Generator[dict[str, Any], Any]:
|
|
423
|
-
objects = hcp_h.list_objects(
|
|
424
|
-
path,
|
|
425
|
-
output_mode=output_mode,
|
|
426
|
-
files_only=files_only,
|
|
427
|
-
)
|
|
428
|
-
for obj in objects:
|
|
429
|
-
if obj.get("Size", 0):
|
|
430
|
-
obj["Size"] = str(
|
|
431
|
-
Byte(obj.get("Size", 0)).best_prefix(system=SI)
|
|
432
|
-
)
|
|
433
|
-
yield obj
|
|
434
|
-
|
|
435
368
|
hcp_h: HCPHandler = create_HCPHandler(context)
|
|
436
369
|
hcp_h.mount_bucket(bucket)
|
|
437
370
|
output_mode = (
|
|
@@ -464,11 +397,12 @@ def list_objects( # noqa: PLR0913
|
|
|
464
397
|
)
|
|
465
398
|
else:
|
|
466
399
|
render_objects_table(
|
|
467
|
-
|
|
468
|
-
hcp_h
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
400
|
+
format_object_sizes(
|
|
401
|
+
hcp_h.list_objects(
|
|
402
|
+
path_with_slash,
|
|
403
|
+
output_mode=output_mode,
|
|
404
|
+
files_only=files_only,
|
|
405
|
+
)
|
|
472
406
|
),
|
|
473
407
|
batch_size,
|
|
474
408
|
)
|
|
@@ -514,7 +448,7 @@ def list_objects( # noqa: PLR0913
|
|
|
514
448
|
default=5,
|
|
515
449
|
)
|
|
516
450
|
@click.pass_context
|
|
517
|
-
def upload(
|
|
451
|
+
def upload(
|
|
518
452
|
context: Context,
|
|
519
453
|
bucket: str,
|
|
520
454
|
source: str,
|
|
@@ -688,103 +622,44 @@ def list_buckets(
|
|
|
688
622
|
|
|
689
623
|
@cli.command(
|
|
690
624
|
section="Search commands",
|
|
691
|
-
short_help=
|
|
692
|
-
"Make a simple search using substrings in a bucket/namespace on "
|
|
693
|
-
"the HCP."
|
|
694
|
-
),
|
|
625
|
+
short_help="Search objects using the HCP built-in metadata index.",
|
|
695
626
|
)
|
|
696
627
|
@click.argument("bucket")
|
|
697
628
|
@click.argument("search_string")
|
|
698
629
|
@click.option(
|
|
699
|
-
"-
|
|
700
|
-
"--
|
|
701
|
-
help="
|
|
630
|
+
"-e",
|
|
631
|
+
"--extended-information",
|
|
632
|
+
help="Display additional information for each search result",
|
|
702
633
|
default=False,
|
|
703
634
|
is_flag=True,
|
|
704
635
|
)
|
|
705
636
|
@click.pass_context
|
|
706
|
-
def
|
|
637
|
+
def search(
|
|
707
638
|
context: Context,
|
|
708
639
|
bucket: str,
|
|
709
640
|
search_string: str,
|
|
710
|
-
|
|
641
|
+
extended_information: bool,
|
|
711
642
|
) -> None:
|
|
712
643
|
"""
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
NOTE: This command does not use the HCI. Instead, it uses a linear search of
|
|
716
|
-
all the objects in the HCP. As such, this search might be slow.
|
|
644
|
+
Search objects in a bucket/namespace using the HCP metadata index.
|
|
717
645
|
|
|
718
646
|
BUCKET is the name of the bucket in which to make the search.
|
|
719
647
|
|
|
720
|
-
SEARCH_STRING is
|
|
648
|
+
SEARCH_STRING is the substring to search for in object paths.
|
|
721
649
|
"""
|
|
722
650
|
hcp_h: HCPHandler = create_HCPHandler(context)
|
|
723
651
|
hcp_h.mount_bucket(bucket)
|
|
724
|
-
|
|
725
|
-
search_string,
|
|
726
|
-
case_sensitive=case_sensitive,
|
|
727
|
-
)
|
|
728
|
-
click.echo("Search results:")
|
|
729
|
-
render_objects_table(
|
|
730
|
-
list_of_results,
|
|
731
|
-
-1,
|
|
732
|
-
)
|
|
733
|
-
|
|
652
|
+
search_results = hcp_h.mqe_search_in_bucket(search_string)
|
|
734
653
|
|
|
735
|
-
@cli.command(
|
|
736
|
-
section="Search commands",
|
|
737
|
-
short_help=(
|
|
738
|
-
"Make a fuzzy search using a search string in a bucket/namespace"
|
|
739
|
-
"on the HCP."
|
|
740
|
-
),
|
|
741
|
-
)
|
|
742
|
-
@click.argument("bucket")
|
|
743
|
-
@click.argument("search_string")
|
|
744
|
-
@click.option(
|
|
745
|
-
"-cs",
|
|
746
|
-
"--case_sensitive",
|
|
747
|
-
help="Use case sensitivity? Default value is False",
|
|
748
|
-
default=False,
|
|
749
|
-
is_flag=True,
|
|
750
|
-
)
|
|
751
|
-
@click.option(
|
|
752
|
-
"-t",
|
|
753
|
-
"--threshold",
|
|
754
|
-
help="Set the threshold for the fuzzy search score. Default value is 80",
|
|
755
|
-
default=80,
|
|
756
|
-
)
|
|
757
|
-
@click.pass_context
|
|
758
|
-
def fuzzy_search(
|
|
759
|
-
context: Context,
|
|
760
|
-
bucket: str,
|
|
761
|
-
search_string: str,
|
|
762
|
-
case_sensitive: bool,
|
|
763
|
-
threshold: int,
|
|
764
|
-
) -> None:
|
|
765
|
-
"""
|
|
766
|
-
Make a fuzzy search using a search string in a bucket/namespace on the HCP.
|
|
767
|
-
|
|
768
|
-
NOTE: This command does not use the HCI. Instead, it uses the RapidFuzz
|
|
769
|
-
library in order to find objects in the HCP. As such, this search might be
|
|
770
|
-
slow.
|
|
771
|
-
|
|
772
|
-
BUCKET is the name of the bucket in which to make the search.
|
|
773
|
-
|
|
774
|
-
SEARCH_STRING is any string that is to be used for the search.
|
|
775
|
-
"""
|
|
776
|
-
hcp_h: HCPHandler = create_HCPHandler(context)
|
|
777
|
-
hcp_h.mount_bucket(bucket)
|
|
778
|
-
list_of_results = hcp_h.fuzzy_search_in_bucket(
|
|
779
|
-
search_string,
|
|
780
|
-
case_sensitive=case_sensitive,
|
|
781
|
-
threshold=threshold,
|
|
782
|
-
)
|
|
783
654
|
click.echo("Search results:")
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
655
|
+
if extended_information:
|
|
656
|
+
render_objects_table(
|
|
657
|
+
format_object_sizes(search_results),
|
|
658
|
+
-1,
|
|
659
|
+
)
|
|
660
|
+
else:
|
|
661
|
+
for result in search_results:
|
|
662
|
+
click.echo(result["Key"])
|
|
788
663
|
|
|
789
664
|
|
|
790
665
|
# ---------------------------- Utility commands ----------------------------
|
|
@@ -857,8 +732,8 @@ def iris_generate_credentials_file(path: str, name: str) -> None:
|
|
|
857
732
|
credentials_dict = {
|
|
858
733
|
"hcp": {
|
|
859
734
|
"endpoint": "",
|
|
860
|
-
"
|
|
861
|
-
"
|
|
735
|
+
"username": "",
|
|
736
|
+
"password": "",
|
|
862
737
|
},
|
|
863
738
|
"hci": {
|
|
864
739
|
"username": "",
|
|
@@ -4,11 +4,11 @@ from pathlib import Path
|
|
|
4
4
|
from typing import TYPE_CHECKING, Any
|
|
5
5
|
|
|
6
6
|
import click
|
|
7
|
-
from bitmath import Byte, TiB
|
|
7
|
+
from bitmath import SI, Byte, TiB
|
|
8
8
|
from boto3 import set_stream_logger
|
|
9
9
|
from tabulate import tabulate
|
|
10
10
|
|
|
11
|
-
from NGPIris import HCPHandler
|
|
11
|
+
from NGPIris.hcp import HCPHandler
|
|
12
12
|
|
|
13
13
|
if TYPE_CHECKING:
|
|
14
14
|
from collections.abc import Generator
|
|
@@ -21,10 +21,8 @@ def add_trailing_slash(path: str) -> str:
|
|
|
21
21
|
Add a trailing slash ("/") to `path`.
|
|
22
22
|
|
|
23
23
|
:param path: Arbitrary string
|
|
24
|
-
:type path: str
|
|
25
24
|
|
|
26
25
|
:return: Arbitrary string with `"/"` at the end
|
|
27
|
-
:rtype: str
|
|
28
26
|
"""
|
|
29
27
|
if not path.endswith("/"):
|
|
30
28
|
path += "/"
|
|
@@ -36,10 +34,8 @@ def create_HCPHandler(context: Context) -> HCPHandler:
|
|
|
36
34
|
Returns a `HCPHandler` based on the given command `context`.
|
|
37
35
|
|
|
38
36
|
:param context: The `click` context from the entered command
|
|
39
|
-
:type context: Context
|
|
40
37
|
|
|
41
38
|
:return: An `HCPHandler` instance based on the given command `context`
|
|
42
|
-
:rtype: HCPHandler
|
|
43
39
|
"""
|
|
44
40
|
if context.parent:
|
|
45
41
|
parent_context = context.parent
|
|
@@ -166,6 +162,22 @@ def download_file(
|
|
|
166
162
|
hcp_h.download_file(source, downloaded_source.as_posix())
|
|
167
163
|
|
|
168
164
|
|
|
165
|
+
def format_object_sizes(
|
|
166
|
+
objects: Generator[dict[str, Any], Any],
|
|
167
|
+
) -> Generator[dict[str, Any], Any]:
|
|
168
|
+
"""
|
|
169
|
+
Format object sizes into human-readable SI units for CLI output.
|
|
170
|
+
|
|
171
|
+
:param objects: Generator of objects with size metadata
|
|
172
|
+
|
|
173
|
+
:yield: Objects with formatted sizes
|
|
174
|
+
"""
|
|
175
|
+
for obj in objects:
|
|
176
|
+
if obj.get("Size"):
|
|
177
|
+
obj["Size"] = str(Byte(int(obj["Size"])).best_prefix(system=SI))
|
|
178
|
+
yield obj
|
|
179
|
+
|
|
180
|
+
|
|
169
181
|
def render_objects_table(
|
|
170
182
|
table_data: Generator[dict[str, Any], Any], batch_size: int
|
|
171
183
|
) -> None:
|
|
@@ -47,10 +47,6 @@ class SectionedGroup(click.Group):
|
|
|
47
47
|
) -> Callable[[Callable[..., Any]], click.Command] | click.Command:
|
|
48
48
|
"""
|
|
49
49
|
Override Group.command to accept a 'section' kwarg.
|
|
50
|
-
|
|
51
|
-
@cli.command(section="User Commands")
|
|
52
|
-
def add():
|
|
53
|
-
...
|
|
54
50
|
"""
|
|
55
51
|
section = kwargs.pop("section", None)
|
|
56
52
|
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# ruff: noqa: N801
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class HCI_ResponseError(Exception):
|
|
5
|
+
"""
|
|
6
|
+
General Response Error from the HCI.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class DataNotSuppliedToPOSTError(Exception):
|
|
11
|
+
"""
|
|
12
|
+
Data was not supplied to a POST request.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class DataSuppliedToGETError(Exception):
|
|
17
|
+
"""
|
|
18
|
+
Data was supplied to a GET request.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class IndexNotFoundError(Exception):
|
|
23
|
+
"""
|
|
24
|
+
The HCI index could not be found.
|
|
25
|
+
"""
|
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
from json import load
|
|
2
|
+
from pathlib import Path
|
|
3
|
+
from typing import Literal
|
|
4
|
+
from warnings import deprecated
|
|
5
|
+
|
|
6
|
+
from requests import Response, post
|
|
7
|
+
from urllib3 import disable_warnings
|
|
8
|
+
|
|
9
|
+
from NGPIris.hci.exceptions import IndexNotFoundError
|
|
10
|
+
from NGPIris.hci.helpers import (
|
|
11
|
+
get_index_response,
|
|
12
|
+
get_query_response,
|
|
13
|
+
)
|
|
14
|
+
from NGPIris.hci.query_string import QueryString
|
|
15
|
+
from NGPIris.hci.types import (
|
|
16
|
+
FacetRequest,
|
|
17
|
+
IndexResponse,
|
|
18
|
+
QueryRequest,
|
|
19
|
+
QueryResponse,
|
|
20
|
+
SortField,
|
|
21
|
+
to_QueryRequest,
|
|
22
|
+
)
|
|
23
|
+
from NGPIris.parse_credentials import CredentialsHandler
|
|
24
|
+
from NGPIris.utils.deprecation import _add_deprecation_in_doc_string
|
|
25
|
+
|
|
26
|
+
_REQUEST_TOKEN_DEP_MSG = (
|
|
27
|
+
":py:func:`request_token` is deprecated in favor of integrating its " # noqa: S105
|
|
28
|
+
"functionality into the :py:class:`HCIHandler` constructor"
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
_QUERY_FROM_JSON_DEP_MSG = (
|
|
32
|
+
":py:meth:`query_from_JSON` is deprecated due to "
|
|
33
|
+
"implementation issues in a type safe way with "
|
|
34
|
+
":py:class:`~NGPIris.hci.query_string.QueryString`"
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
class HCIHandler:
|
|
39
|
+
"""
|
|
40
|
+
Class for handling HCI requests.
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
def __init__(
|
|
44
|
+
self, credentials: str | dict[str, str], use_ssl: bool = False
|
|
45
|
+
) -> None:
|
|
46
|
+
"""
|
|
47
|
+
Class for handling HCI requests.
|
|
48
|
+
|
|
49
|
+
:param credentials:
|
|
50
|
+
If ``credentials`` is a :py:type:`str`, then it will be interpreted
|
|
51
|
+
as a path to the JSON credentials file. If ``credentials`` is a
|
|
52
|
+
:py:type:`dict`, then a dictionary with the appropriate HCI
|
|
53
|
+
credentials is expected::
|
|
54
|
+
|
|
55
|
+
{
|
|
56
|
+
"username" : "",
|
|
57
|
+
"password" : "",
|
|
58
|
+
"address" : "",
|
|
59
|
+
"auth_port" : "",
|
|
60
|
+
"api_port" : ""
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
:param use_ssl: Boolean choice between using SSL
|
|
64
|
+
"""
|
|
65
|
+
if type(credentials) is str:
|
|
66
|
+
credentials_handler = CredentialsHandler(credentials)
|
|
67
|
+
self.hci = credentials_handler.hci
|
|
68
|
+
|
|
69
|
+
self.address = self.hci["address"]
|
|
70
|
+
self.username = self.hci["username"]
|
|
71
|
+
self.password = self.hci["password"]
|
|
72
|
+
self.realm = self.hci.get("realm", "LOCAL")
|
|
73
|
+
elif type(credentials) is dict:
|
|
74
|
+
self.address = credentials["address"]
|
|
75
|
+
self.username = credentials["username"]
|
|
76
|
+
self.password = credentials["password"]
|
|
77
|
+
self.realm = self.hci.get("realm", "LOCAL")
|
|
78
|
+
|
|
79
|
+
self.use_ssl = use_ssl
|
|
80
|
+
|
|
81
|
+
if not self.use_ssl:
|
|
82
|
+
disable_warnings()
|
|
83
|
+
|
|
84
|
+
self.token = self._request_token()
|
|
85
|
+
|
|
86
|
+
@_add_deprecation_in_doc_string(_REQUEST_TOKEN_DEP_MSG, "v5.6.7")
|
|
87
|
+
@deprecated(_REQUEST_TOKEN_DEP_MSG)
|
|
88
|
+
def request_token(self) -> None:
|
|
89
|
+
"""
|
|
90
|
+
Request a token from the HCI, which is stored in the HCIHandler object.
|
|
91
|
+
The token is used for every operation that needs to send a request to
|
|
92
|
+
HCI.
|
|
93
|
+
|
|
94
|
+
:raises ConnectionError:
|
|
95
|
+
If there was a problem when requesting a token
|
|
96
|
+
"""
|
|
97
|
+
self.token = self._request_token()
|
|
98
|
+
|
|
99
|
+
def _request_token(self) -> str:
|
|
100
|
+
"""
|
|
101
|
+
Request a token from the HCI. The token is used for every operation
|
|
102
|
+
that needs to send a request to HCI.
|
|
103
|
+
|
|
104
|
+
:raises ConnectionError:
|
|
105
|
+
If there was a problem when requesting a token
|
|
106
|
+
"""
|
|
107
|
+
match self.realm:
|
|
108
|
+
case "HCI":
|
|
109
|
+
url = (
|
|
110
|
+
"https://keycloak."
|
|
111
|
+
+ self.address
|
|
112
|
+
+ "/realms/"
|
|
113
|
+
+ self.realm
|
|
114
|
+
+ "/protocol/openid-connect/token"
|
|
115
|
+
)
|
|
116
|
+
data = {
|
|
117
|
+
"grant_type": "client_credentials",
|
|
118
|
+
"client_id": self.username,
|
|
119
|
+
"client_secret": self.password,
|
|
120
|
+
"realm": self.realm,
|
|
121
|
+
}
|
|
122
|
+
case _: # Same as "LOCAL"
|
|
123
|
+
url = "https://" + self.address + ":8000" + "/auth/oauth/"
|
|
124
|
+
data = {
|
|
125
|
+
"grant_type": "password",
|
|
126
|
+
"username": self.username,
|
|
127
|
+
"password": self.password,
|
|
128
|
+
"scope": "*",
|
|
129
|
+
"client_secret": "hci-client",
|
|
130
|
+
"client_id": "hci-client",
|
|
131
|
+
"realm": "LOCAL",
|
|
132
|
+
}
|
|
133
|
+
try:
|
|
134
|
+
response: Response = post(
|
|
135
|
+
url, data=data, verify=self.use_ssl, timeout=15
|
|
136
|
+
)
|
|
137
|
+
except: # noqa: E722 # pragma: no cover
|
|
138
|
+
error_msg: str = (
|
|
139
|
+
"The token request made at "
|
|
140
|
+
+ url
|
|
141
|
+
+ " failed. Please check your connection."
|
|
142
|
+
)
|
|
143
|
+
raise ConnectionError(error_msg) from None
|
|
144
|
+
|
|
145
|
+
token: str = response.json()["access_token"]
|
|
146
|
+
return token
|
|
147
|
+
|
|
148
|
+
def list_index_names(self) -> list[str]:
|
|
149
|
+
"""
|
|
150
|
+
Retrieve a list of all index names.
|
|
151
|
+
|
|
152
|
+
:return: A list of index names
|
|
153
|
+
"""
|
|
154
|
+
return [entry["name"] for entry in get_index_response(self)]
|
|
155
|
+
|
|
156
|
+
def look_up_index(self, index_name: str) -> IndexResponse:
|
|
157
|
+
"""
|
|
158
|
+
Look up index information in the form of a dictionary by submitting
|
|
159
|
+
the index name. Will return an empty dictionary if no index was found.
|
|
160
|
+
|
|
161
|
+
:param index_name: The index name
|
|
162
|
+
|
|
163
|
+
:return: A dictionary containing information about an index
|
|
164
|
+
"""
|
|
165
|
+
for entry in get_index_response(self):
|
|
166
|
+
if entry["name"] == index_name:
|
|
167
|
+
return entry
|
|
168
|
+
|
|
169
|
+
msg = "The index " + index_name + " could not be found"
|
|
170
|
+
raise IndexNotFoundError(msg)
|
|
171
|
+
|
|
172
|
+
def query(self, query_dict: QueryRequest) -> QueryResponse:
|
|
173
|
+
"""
|
|
174
|
+
Make query to an HCI index, with a :py:class:`QueryRequest` typed
|
|
175
|
+
dictionary.
|
|
176
|
+
|
|
177
|
+
:param query_dict:
|
|
178
|
+
Dictionary consisting of the query. For more information see the
|
|
179
|
+
specification of :py:class:`QueryRequest`
|
|
180
|
+
|
|
181
|
+
:return:
|
|
182
|
+
:py:class:`QueryResponse` typed dictionary containing the query
|
|
183
|
+
response
|
|
184
|
+
"""
|
|
185
|
+
return get_query_response(query_dict, self)
|
|
186
|
+
|
|
187
|
+
@_add_deprecation_in_doc_string(_QUERY_FROM_JSON_DEP_MSG, "v5.7.0")
|
|
188
|
+
@deprecated(_QUERY_FROM_JSON_DEP_MSG)
|
|
189
|
+
def query_from_JSON(self, query_path: str) -> QueryResponse:
|
|
190
|
+
"""
|
|
191
|
+
Make query to an HCI index, with pre-written query in a JSON file.
|
|
192
|
+
|
|
193
|
+
:param query_path: Path to the JSON file
|
|
194
|
+
|
|
195
|
+
:return: Dictionary containing the raw query
|
|
196
|
+
"""
|
|
197
|
+
msg = "This method has not been properly implemented yet"
|
|
198
|
+
raise NotImplementedError(msg)
|
|
199
|
+
with Path(query_path).open() as inp:
|
|
200
|
+
return self.query(to_QueryRequest(load(inp)))
|
|
201
|
+
|
|
202
|
+
def basic_query(
|
|
203
|
+
self,
|
|
204
|
+
index_name: str,
|
|
205
|
+
query_string: QueryString | None = None,
|
|
206
|
+
items_to_return: int = 0,
|
|
207
|
+
facets: list[str] | None = None,
|
|
208
|
+
sort_fields: list[tuple[str, Literal["DESC", "ASC"]]] | None = None,
|
|
209
|
+
) -> QueryResponse:
|
|
210
|
+
"""
|
|
211
|
+
Make a query to the HCI based on the parameters of this method.
|
|
212
|
+
|
|
213
|
+
:param index_name: Name of the index
|
|
214
|
+
|
|
215
|
+
:param query_string: The Solr query string.
|
|
216
|
+
|
|
217
|
+
:param items_to_return: Number of results that should be returned
|
|
218
|
+
|
|
219
|
+
:param facets:
|
|
220
|
+
List of facets that should be returned included in the response.
|
|
221
|
+
|
|
222
|
+
:param sort_fields:
|
|
223
|
+
List of tuples of fields and sort orders
|
|
224
|
+
|
|
225
|
+
:return: The response in the form of a dictionary
|
|
226
|
+
"""
|
|
227
|
+
if sort_fields is None:
|
|
228
|
+
sort_fields = []
|
|
229
|
+
if facets is None:
|
|
230
|
+
facets = []
|
|
231
|
+
if query_string is None:
|
|
232
|
+
query_string = QueryString()
|
|
233
|
+
|
|
234
|
+
facetRequests = [FacetRequest({"fieldName": facet}) for facet in facets]
|
|
235
|
+
sortFields = [
|
|
236
|
+
SortField(sortField=sf, sortOrder=so) for sf, so in sort_fields
|
|
237
|
+
]
|
|
238
|
+
query_dict: QueryRequest = {
|
|
239
|
+
"indexName": index_name,
|
|
240
|
+
"queryString": query_string,
|
|
241
|
+
"itemsToReturn": items_to_return,
|
|
242
|
+
"facetRequests": facetRequests,
|
|
243
|
+
"sortFields": sortFields,
|
|
244
|
+
}
|
|
245
|
+
return self.query(query_dict)
|