cortexapps-cli 0.25.0__tar.gz → 0.26.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {cortexapps_cli-0.25.0 → cortexapps_cli-0.26.0}/PKG-INFO +9 -1
- {cortexapps_cli-0.25.0 → cortexapps_cli-0.26.0}/README.rst +8 -0
- {cortexapps_cli-0.25.0 → cortexapps_cli-0.26.0}/cortexapps_cli/cortex.py +98 -92
- {cortexapps_cli-0.25.0 → cortexapps_cli-0.26.0}/pyproject.toml +1 -1
- {cortexapps_cli-0.25.0 → cortexapps_cli-0.26.0}/LICENSE +0 -0
- {cortexapps_cli-0.25.0 → cortexapps_cli-0.26.0}/cortexapps_cli/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: cortexapps-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.26.0
|
|
4
4
|
Summary: Command Line Interface for cortexapps
|
|
5
5
|
License: MIT
|
|
6
6
|
Author: Cortex Apps
|
|
@@ -62,6 +62,14 @@ homebrew
|
|
|
62
62
|
brew tap cortexapps/tap
|
|
63
63
|
brew install cortexapps-cli
|
|
64
64
|
|
|
65
|
+
----------------------
|
|
66
|
+
docker
|
|
67
|
+
----------------------
|
|
68
|
+
|
|
69
|
+
.. code:: bash
|
|
70
|
+
|
|
71
|
+
docker run -e CORTEX_API_KEY=<your API key> cortexapp/cli <Cortex CLI arguments>
|
|
72
|
+
|
|
65
73
|
===================
|
|
66
74
|
Usage
|
|
67
75
|
===================
|
|
@@ -41,6 +41,14 @@ homebrew
|
|
|
41
41
|
brew tap cortexapps/tap
|
|
42
42
|
brew install cortexapps-cli
|
|
43
43
|
|
|
44
|
+
----------------------
|
|
45
|
+
docker
|
|
46
|
+
----------------------
|
|
47
|
+
|
|
48
|
+
.. code:: bash
|
|
49
|
+
|
|
50
|
+
docker run -e CORTEX_API_KEY=<your API key> cortexapp/cli <Cortex CLI arguments>
|
|
51
|
+
|
|
44
52
|
===================
|
|
45
53
|
Usage
|
|
46
54
|
===================
|
|
@@ -522,13 +522,13 @@ def add_argument_type(subparser, option="-t", help_text='The resource type.', re
|
|
|
522
522
|
metavar=''
|
|
523
523
|
)
|
|
524
524
|
|
|
525
|
-
def add_argument_types(subparser, option="-t", help_text='Comma-separated list of entity types.', required=True):
|
|
525
|
+
def add_argument_types(subparser, option="-t", help_text='Comma-separated list of entity types.', required=True, default=argparse.SUPPRESS):
|
|
526
526
|
subparser.add_argument(
|
|
527
527
|
option,
|
|
528
528
|
'--types',
|
|
529
529
|
help=help_text,
|
|
530
530
|
required=required,
|
|
531
|
-
default=
|
|
531
|
+
default=default,
|
|
532
532
|
metavar=''
|
|
533
533
|
)
|
|
534
534
|
|
|
@@ -711,6 +711,8 @@ def subparser_backup_opts(subparsers):
|
|
|
711
711
|
def subparser_backup_export(subparser):
|
|
712
712
|
sp = subparser.add_parser('export', help='Export tenant')
|
|
713
713
|
add_argument_export_directory(sp)
|
|
714
|
+
add_argument_types(sp, required=False, default="ALL", help_text="Entity types to export. In addition to Cortex x-cortex-type values, this can include scorecard and ip-allowlist. Defaults to all types.")
|
|
715
|
+
add_argument_page_size(sp, help_text="Number of entities to return in each catalog API call, defaults to 50.")
|
|
714
716
|
sp.set_defaults(func=export)
|
|
715
717
|
|
|
716
718
|
def export(args):
|
|
@@ -744,8 +746,7 @@ def export(args):
|
|
|
744
746
|
resource_types_list = []
|
|
745
747
|
for t in data['definitions']:
|
|
746
748
|
resource_types_list.append(t['type'])
|
|
747
|
-
|
|
748
|
-
resource_types="service,domain"
|
|
749
|
+
|
|
749
750
|
for resource_type in sorted(resource_types_list):
|
|
750
751
|
print("--> " + resource_type)
|
|
751
752
|
resource_file=resource_definitions_directory + "/" + resource_type + ".json"
|
|
@@ -756,99 +757,104 @@ def export(args):
|
|
|
756
757
|
with open(resource_file, 'w') as f:
|
|
757
758
|
f.write(resource_definition_output.getvalue())
|
|
758
759
|
f.close()
|
|
759
|
-
if "type" in args:
|
|
760
|
-
delattr(args, 'type')
|
|
761
760
|
|
|
762
761
|
print("Getting catalog entities")
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
762
|
+
this_page = 0
|
|
763
|
+
total_pages = -1
|
|
764
|
+
args.yaml = True
|
|
765
|
+
|
|
766
|
+
while not this_page == total_pages:
|
|
767
|
+
descriptors=json_directory + "/descriptors-" + str(this_page) + ".json"
|
|
768
|
+
catalog_output = io.StringIO()
|
|
769
|
+
with redirect_stdout(catalog_output):
|
|
770
|
+
save_types = args.types
|
|
771
|
+
if args.types == "ALL":
|
|
772
|
+
delattr(args, 'types')
|
|
773
|
+
catalog_list_descriptors(args)
|
|
774
|
+
args.types = save_types
|
|
775
|
+
|
|
776
|
+
with open(descriptors, 'w') as f:
|
|
768
777
|
f.write(catalog_output.getvalue())
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
with redirect_stdout(scorecards_descriptor_output):
|
|
819
|
-
scorecards_descriptor(args)
|
|
820
|
-
with open(scorecard_file, 'w') as f:
|
|
821
|
-
f.write(scorecards_descriptor_output.getvalue())
|
|
822
|
-
delattr(args, 'tag')
|
|
778
|
+
data = json.loads(catalog_output.getvalue())
|
|
779
|
+
total_pages = data['totalPages']
|
|
780
|
+
this_page = this_page + 1
|
|
781
|
+
args.page = this_page
|
|
782
|
+
|
|
783
|
+
for descriptor in data['descriptors']:
|
|
784
|
+
y = yaml.safe_load(str(descriptor))
|
|
785
|
+
tag = y['info']['x-cortex-tag']
|
|
786
|
+
# Slash will be interpreted as a sub-directory
|
|
787
|
+
output_tag = tag.replace("/", "-")
|
|
788
|
+
print("--> " + tag)
|
|
789
|
+
f1 = open(catalog_directory + "/" + output_tag + ".yaml", 'w')
|
|
790
|
+
f1.write(str(descriptor) + "\n")
|
|
791
|
+
|
|
792
|
+
if any(export_type == "ALL" or export_type == "ip-allowlist" for export_type in args.types.split()):
|
|
793
|
+
print("Getting IP Allowlist definitions")
|
|
794
|
+
ip_allowlist_json=json_directory + "/ip-allowlist.json"
|
|
795
|
+
ip_allowlist_output = io.StringIO()
|
|
796
|
+
with redirect_stdout(ip_allowlist_output):
|
|
797
|
+
ip_allowlist_get(args)
|
|
798
|
+
with open(ip_allowlist_json, 'w') as f:
|
|
799
|
+
f.write(ip_allowlist_output.getvalue())
|
|
800
|
+
|
|
801
|
+
if any(export_type == "ALL" or export_type == "scorecard" for export_type in args.types.split()):
|
|
802
|
+
print("Getting scorecards")
|
|
803
|
+
scorecards_json=json_directory + "/scorecards.json"
|
|
804
|
+
scorecards_output = io.StringIO()
|
|
805
|
+
with redirect_stdout(scorecards_output):
|
|
806
|
+
scorecards_list(args)
|
|
807
|
+
with open(scorecards_json, 'w') as f:
|
|
808
|
+
f.write(scorecards_output.getvalue())
|
|
809
|
+
|
|
810
|
+
data = json.loads(scorecards_output.getvalue())
|
|
811
|
+
|
|
812
|
+
# Can't sort json keys, so need to create a list first so it can be sorted.
|
|
813
|
+
scorecard_list = []
|
|
814
|
+
for scorecard in data['scorecards']:
|
|
815
|
+
scorecard_list.append(scorecard['tag'])
|
|
816
|
+
|
|
817
|
+
for tag in sorted(scorecard_list):
|
|
818
|
+
print("--> " + tag)
|
|
819
|
+
scorecard_file=scorecard_directory + "/" + tag + ".yaml"
|
|
820
|
+
args.tag=tag
|
|
821
|
+
scorecards_descriptor_output = io.StringIO()
|
|
822
|
+
with redirect_stdout(scorecards_descriptor_output):
|
|
823
|
+
scorecards_descriptor(args)
|
|
824
|
+
with open(scorecard_file, 'w') as f:
|
|
825
|
+
f.write(scorecards_descriptor_output.getvalue())
|
|
826
|
+
delattr(args, 'tag')
|
|
823
827
|
|
|
824
828
|
# CORTEX teams; will not try to import IDP-backed teams. Those would get re-imported after re-establishing the IDP integration.
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
#
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
829
|
+
# 2024-05-06 Will already have teams as entitites from catalog export, so should be no need to also export teams.
|
|
830
|
+
# print("Getting teams")
|
|
831
|
+
# teams_json=json_directory + "/teams.json"
|
|
832
|
+
# teams_output = io.StringIO()
|
|
833
|
+
# with redirect_stdout(teams_output):
|
|
834
|
+
# teams_list(args)
|
|
835
|
+
# with open(teams_json, 'w') as f:
|
|
836
|
+
# f.write(teams_output.getvalue())
|
|
837
|
+
#
|
|
838
|
+
# data = json.loads(teams_output.getvalue())
|
|
839
|
+
#
|
|
840
|
+
# # Can't sort json keys, so need to create a list first so it can be sorted.
|
|
841
|
+
# # Has to be a dictionary because we also need to know about the type of team.
|
|
842
|
+
# team_list = dict()
|
|
843
|
+
# for team in data['teams']:
|
|
844
|
+
# team_list[team['teamTag']] = team['type']
|
|
845
|
+
#
|
|
846
|
+
# for team_tag, type in OrderedDict(sorted(team_list.items())).items():
|
|
847
|
+
# if type != "CORTEX":
|
|
848
|
+
# continue
|
|
849
|
+
# print("--> " + team_tag)
|
|
850
|
+
# output_tag = team_tag.replace("/", "-")
|
|
851
|
+
# team_file=teams_directory + "/" + output_tag + ".json"
|
|
852
|
+
# args.teamTag=team_tag
|
|
853
|
+
# team_output = io.StringIO()
|
|
854
|
+
# with redirect_stdout(team_output):
|
|
855
|
+
# teams_get(args)
|
|
856
|
+
# with open(team_file, 'w') as f:
|
|
857
|
+
# f.write(team_output.getvalue())
|
|
852
858
|
|
|
853
859
|
print("\nExport complete!")
|
|
854
860
|
print("Contents available in " + args.directory)
|
|
File without changes
|
|
File without changes
|