catocli 2.0.1__py3-none-any.whl → 2.0.3__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.

Potentially problematic release.


This version of catocli might be problematic. Click here for more details.

Files changed (108) hide show
  1. catocli/Utils/clidriver.py +41 -6
  2. catocli/__init__.py +1 -1
  3. catocli/parsers/custom/__init__.py +7 -5
  4. catocli/parsers/custom/customLib.py +490 -1
  5. catocli/parsers/custom/export_rules/__init__.py +5 -1
  6. catocli/parsers/custom/export_rules/export_rules.py +32 -183
  7. catocli/parsers/custom/export_sites/__init__.py +20 -0
  8. catocli/parsers/custom/export_sites/export_sites.py +365 -0
  9. catocli/parsers/custom/import_rules_to_tf/__init__.py +3 -3
  10. catocli/parsers/custom/import_rules_to_tf/import_rules_to_tf.py +20 -146
  11. catocli/parsers/custom/import_sites_to_tf/__init__.py +45 -0
  12. catocli/parsers/custom/import_sites_to_tf/import_sites_to_tf.py +891 -0
  13. catocli/parsers/mutation_accountManagement/__init__.py +18 -21
  14. catocli/parsers/mutation_admin/__init__.py +18 -21
  15. catocli/parsers/mutation_container/__init__.py +6 -7
  16. catocli/parsers/mutation_hardware/__init__.py +6 -7
  17. catocli/parsers/mutation_policy/__init__.py +666 -588
  18. catocli/parsers/mutation_policy_terminalServer/README.md +7 -0
  19. catocli/parsers/mutation_policy_terminalServer_addRule/README.md +18 -0
  20. catocli/parsers/mutation_policy_terminalServer_addSection/README.md +18 -0
  21. catocli/parsers/mutation_policy_terminalServer_createPolicyRevision/README.md +18 -0
  22. catocli/parsers/mutation_policy_terminalServer_discardPolicyRevision/README.md +18 -0
  23. catocli/parsers/mutation_policy_terminalServer_moveRule/README.md +18 -0
  24. catocli/parsers/mutation_policy_terminalServer_moveSection/README.md +18 -0
  25. catocli/parsers/mutation_policy_terminalServer_publishPolicyRevision/README.md +18 -0
  26. catocli/parsers/mutation_policy_terminalServer_removeRule/README.md +18 -0
  27. catocli/parsers/mutation_policy_terminalServer_removeSection/README.md +18 -0
  28. catocli/parsers/mutation_policy_terminalServer_updatePolicy/README.md +18 -0
  29. catocli/parsers/mutation_policy_terminalServer_updateRule/README.md +18 -0
  30. catocli/parsers/mutation_policy_terminalServer_updateSection/README.md +18 -0
  31. catocli/parsers/mutation_sandbox/__init__.py +12 -14
  32. catocli/parsers/mutation_site/__init__.py +189 -175
  33. catocli/parsers/mutation_site_addSocketAddOnCard/README.md +17 -0
  34. catocli/parsers/mutation_site_removeSocketAddOnCard/README.md +17 -0
  35. catocli/parsers/mutation_site_startSiteUpgrade/README.md +17 -0
  36. catocli/parsers/mutation_sites/__init__.py +189 -175
  37. catocli/parsers/mutation_sites_addSocketAddOnCard/README.md +17 -0
  38. catocli/parsers/mutation_sites_removeSocketAddOnCard/README.md +17 -0
  39. catocli/parsers/mutation_sites_startSiteUpgrade/README.md +17 -0
  40. catocli/parsers/mutation_xdr/__init__.py +18 -21
  41. catocli/parsers/parserApiClient.py +36 -11
  42. catocli/parsers/query_accountBySubdomain/__init__.py +6 -7
  43. catocli/parsers/query_accountManagement/__init__.py +6 -7
  44. catocli/parsers/query_accountMetrics/__init__.py +6 -7
  45. catocli/parsers/query_accountRoles/__init__.py +6 -7
  46. catocli/parsers/query_accountSnapshot/__init__.py +6 -7
  47. catocli/parsers/query_admin/__init__.py +6 -7
  48. catocli/parsers/query_admins/__init__.py +6 -7
  49. catocli/parsers/query_appStats/__init__.py +6 -7
  50. catocli/parsers/query_appStatsTimeSeries/__init__.py +6 -7
  51. catocli/parsers/query_auditFeed/__init__.py +6 -7
  52. catocli/parsers/query_catalogs/__init__.py +6 -7
  53. catocli/parsers/query_container/__init__.py +6 -7
  54. catocli/parsers/query_devices/README.md +2 -1
  55. catocli/parsers/query_devices/__init__.py +6 -7
  56. catocli/parsers/query_entityLookup/__init__.py +6 -7
  57. catocli/parsers/query_events/__init__.py +6 -7
  58. catocli/parsers/query_eventsFeed/README.md +1 -1
  59. catocli/parsers/query_eventsFeed/__init__.py +6 -7
  60. catocli/parsers/query_eventsTimeSeries/__init__.py +6 -7
  61. catocli/parsers/query_hardware/__init__.py +6 -7
  62. catocli/parsers/query_hardwareManagement/__init__.py +6 -7
  63. catocli/parsers/query_licensing/__init__.py +6 -7
  64. catocli/parsers/query_policy/README.md +2 -1
  65. catocli/parsers/query_policy/__init__.py +6 -7
  66. catocli/parsers/query_sandbox/__init__.py +6 -7
  67. catocli/parsers/query_site/README.md +2 -1
  68. catocli/parsers/query_site/__init__.py +6 -7
  69. catocli/parsers/query_siteLocation/__init__.py +4 -8
  70. catocli/parsers/query_subDomains/__init__.py +6 -7
  71. catocli/parsers/query_xdr/__init__.py +12 -14
  72. catocli/parsers/raw/README.md +4 -0
  73. catocli/parsers/raw/__init__.py +5 -2
  74. {catocli-2.0.1.dist-info → catocli-2.0.3.dist-info}/METADATA +1 -1
  75. {catocli-2.0.1.dist-info → catocli-2.0.3.dist-info}/RECORD +108 -67
  76. graphql_client/api/call_api.py +12 -6
  77. models/mutation.policy.remotePortFwd.updateRule.json +6 -6
  78. models/mutation.policy.terminalServer.addRule.json +2403 -0
  79. models/mutation.policy.terminalServer.addSection.json +1358 -0
  80. models/mutation.policy.terminalServer.createPolicyRevision.json +1873 -0
  81. models/mutation.policy.terminalServer.discardPolicyRevision.json +1807 -0
  82. models/mutation.policy.terminalServer.moveRule.json +1605 -0
  83. models/mutation.policy.terminalServer.moveSection.json +1259 -0
  84. models/mutation.policy.terminalServer.publishPolicyRevision.json +1864 -0
  85. models/mutation.policy.terminalServer.removeRule.json +1253 -0
  86. models/mutation.policy.terminalServer.removeSection.json +958 -0
  87. models/mutation.policy.terminalServer.updatePolicy.json +1883 -0
  88. models/mutation.policy.terminalServer.updateRule.json +2096 -0
  89. models/mutation.policy.terminalServer.updateSection.json +1111 -0
  90. models/mutation.site.addSocketAddOnCard.json +1050 -0
  91. models/mutation.site.removeSocketAddOnCard.json +786 -0
  92. models/mutation.site.startSiteUpgrade.json +802 -0
  93. models/mutation.sites.addSocketAddOnCard.json +1050 -0
  94. models/mutation.sites.removeSocketAddOnCard.json +786 -0
  95. models/mutation.sites.startSiteUpgrade.json +802 -0
  96. models/query.devices.json +311 -2
  97. models/query.events.json +48 -0
  98. models/query.eventsFeed.json +12 -0
  99. models/query.eventsTimeSeries.json +36 -0
  100. models/query.licensing.json +21815 -10093
  101. models/query.policy.json +1898 -305
  102. models/query.site.json +225 -0
  103. models/query.siteLocation.json +97190 -295396
  104. schema/catolib.py +63 -30
  105. {catocli-2.0.1.dist-info → catocli-2.0.3.dist-info}/LICENSE +0 -0
  106. {catocli-2.0.1.dist-info → catocli-2.0.3.dist-info}/WHEEL +0 -0
  107. {catocli-2.0.1.dist-info → catocli-2.0.3.dist-info}/entry_points.txt +0 -0
  108. {catocli-2.0.1.dist-info → catocli-2.0.3.dist-info}/top_level.txt +0 -0
schema/catolib.py CHANGED
@@ -552,7 +552,7 @@ def show_version_info(args, configuration=None):
552
552
  print("Unable to check for updates (check your internet connection)")
553
553
  return [{"success": True, "current_version": catocli.__version__, "latest_version": latest_version if not args.current_only else None}]
554
554
 
555
- def get_configuration():
555
+ def get_configuration(skip_api_key=False):
556
556
  configuration = Configuration()
557
557
  configuration.verify_ssl = False
558
558
  configuration.debug = CATO_DEBUG
@@ -574,7 +574,9 @@ def get_configuration():
574
574
  print(f"Run 'catocli configure set --profile {profile_name}' to update your credentials.")
575
575
  exit(1)
576
576
 
577
- configuration.api_key["x-api-key"] = credentials['cato_token']
577
+ # Only set API key if not using custom headers file
578
+ if not skip_api_key:
579
+ configuration.api_key["x-api-key"] = credentials['cato_token']
578
580
  configuration.host = credentials['endpoint']
579
581
  configuration.accountID = credentials['account_id']
580
582
 
@@ -590,6 +592,7 @@ https://github.com/catonetworks/cato-api-explorer
590
592
  parser = argparse.ArgumentParser(prog='catocli', usage='%(prog)s <operationType> <operationName> [options]', description=defaultReadmeStr)
591
593
  parser.add_argument('--version', action='version', version=catocli.__version__)
592
594
  parser.add_argument('-H', '--header', action='append', dest='headers', help='Add custom headers in "Key: Value" format. Can be used multiple times.')
595
+ parser.add_argument('--headers-file', dest='headers_file', help='Load headers from a file. Each line should contain a header in "Key: Value" format.')
593
596
  subparsers = parser.add_subparsers()
594
597
 
595
598
  # Version command - enhanced with update checking
@@ -624,6 +627,28 @@ def parse_headers(header_strings):
624
627
  headers[key.strip()] = value.strip()
625
628
  return headers
626
629
 
630
+ def parse_headers_from_file(file_path):
631
+ headers = {}
632
+ try:
633
+ with open(file_path, 'r') as f:
634
+ for line_num, line in enumerate(f, 1):
635
+ line = line.strip()
636
+ if not line or line.startswith('#'):
637
+ # Skip empty lines and comments
638
+ continue
639
+ if ':' not in line:
640
+ print(f"ERROR: Invalid header format in {file_path} at line {line_num}: '{line}'. Use 'Key: Value' format.")
641
+ exit(1)
642
+ key, value = line.split(':', 1)
643
+ headers[key.strip()] = value.strip()
644
+ except FileNotFoundError:
645
+ print(f"ERROR: Headers file '{file_path}' not found.")
646
+ exit(1)
647
+ except IOError as e:
648
+ print(f"ERROR: Could not read headers file '{file_path}': {e}")
649
+ exit(1)
650
+ return headers
651
+
627
652
  def main(args=None):
628
653
  # Check if no arguments provided or help is requested
629
654
  if args is None:
@@ -644,13 +669,20 @@ def main(args=None):
644
669
  if hasattr(args, 'func') and hasattr(args.func, '__module__') and 'configure' in str(args.func.__module__):
645
670
  response = args.func(args, None)
646
671
  else:
672
+ # Check if using headers file to determine if we should skip API key
673
+ using_headers_file = hasattr(args, 'headers_file') and args.headers_file
674
+
647
675
  # Get configuration from profiles
648
- configuration = get_configuration()
676
+ configuration = get_configuration(skip_api_key=using_headers_file)
649
677
 
650
678
  # Parse custom headers if provided
679
+ custom_headers = {}
651
680
  if hasattr(args, 'headers') and args.headers:
652
- custom_headers = parse_headers(args.headers)
653
- configuration.custom_headers.update(custom_headers)
681
+ custom_headers.update(parse_headers(args.headers))
682
+ if hasattr(args, 'headers_file') and args.headers_file:
683
+ custom_headers.update(parse_headers_from_file(args.headers_file))
684
+ if custom_headers:
685
+ configuration.custom_headers.update(custom_headers)
654
686
  # Handle account ID override
655
687
  if args.func.__name__ != "createRawRequest":
656
688
  if hasattr(args, 'accountID') and args.accountID is not None:
@@ -685,10 +717,13 @@ def writeOperationParsers(catoApiSchema):
685
717
  from ..parserApiClient import createRawRequest, get_help
686
718
 
687
719
  def raw_parse(raw_parser):
688
- raw_parser.add_argument('json', help='Query, Variables and opertaionName in JSON format.')
689
- raw_parser.add_argument('-t', const=True, default=False, nargs='?', help='Print test request preview without sending api call')
720
+ raw_parser.add_argument('json', nargs='?', default='{{}}', help='Query, Variables and opertaionName in JSON format (defaults to empty object if not provided).')
721
+ raw_parser.add_argument('-t', const=True, default=False, nargs='?', help='Print GraphQL query without sending API call')
690
722
  raw_parser.add_argument('-v', const=True, default=False, nargs='?', help='Verbose output')
691
723
  raw_parser.add_argument('-p', const=True, default=False, nargs='?', help='Pretty print')
724
+ raw_parser.add_argument('-H', '--header', action='append', dest='headers', help='Add custom headers in "Key: Value" format. Can be used multiple times.')
725
+ raw_parser.add_argument('--headers-file', dest='headers_file', help='Load headers from a file. Each line should contain a header in "Key: Value" format.')
726
+ raw_parser.add_argument('--endpoint', dest='endpoint', help='Override the API endpoint URL (e.g., https://api.catonetworks.com/api/v1/graphql2)')
692
727
  raw_parser.set_defaults(func=createRawRequest,operation_name='raw')
693
728
  """
694
729
  parserPath = "../catocli/parsers/raw"
@@ -704,15 +739,11 @@ def query_siteLocation_parse(query_subparsers):
704
739
  query_siteLocation_parser = query_subparsers.add_parser('siteLocation',
705
740
  help='siteLocation local cli query',
706
741
  usage=get_help("query_siteLocation"))
707
-
708
- query_siteLocation_parser.add_argument('json', help='Variables in JSON format.')
742
+ query_siteLocation_parser.add_argument('json', nargs='?', default='{{}}', help='Variables in JSON format (defaults to empty object if not provided).')
709
743
  query_siteLocation_parser.add_argument('-accountID', help='Override the CATO_ACCOUNT_ID environment variable with this value.')
710
- query_siteLocation_parser.add_argument('-t', const=True, default=False, nargs='?',
711
- help='Print test request preview without sending api call')
712
- query_siteLocation_parser.add_argument('-v', const=True, default=False, nargs='?',
713
- help='Verbose output')
714
- query_siteLocation_parser.add_argument('-p', const=True, default=False, nargs='?',
715
- help='Pretty print')
744
+ query_siteLocation_parser.add_argument('-t', const=True, default=False, nargs='?', help='Print GraphQL query without sending API call')
745
+ query_siteLocation_parser.add_argument('-v', const=True, default=False, nargs='?', help='Verbose output')
746
+ query_siteLocation_parser.add_argument('-p', const=True, default=False, nargs='?', help='Pretty print')
716
747
  query_siteLocation_parser.set_defaults(func=querySiteLocation,operation_name='query.siteLocation')
717
748
  """
718
749
  parserPath = "../catocli/parsers/query_siteLocation"
@@ -738,14 +769,13 @@ def {parserName}_parse({operationType}_subparsers):
738
769
  """
739
770
  if "path" in parser:
740
771
  cliDriverStr += f"""
741
- {parserName}_parser.add_argument('json', help='Variables in JSON format.')
772
+ {parserName}_parser.add_argument('json', nargs='?', default='{{}}', help='Variables in JSON format (defaults to empty object if not provided).')
742
773
  {parserName}_parser.add_argument('-accountID', help='Override the CATO_ACCOUNT_ID environment variable with this value.')
743
- {parserName}_parser.add_argument('-t', const=True, default=False, nargs='?',
744
- help='Print test request preview without sending api call')
745
- {parserName}_parser.add_argument('-v', const=True, default=False, nargs='?',
746
- help='Verbose output')
747
- {parserName}_parser.add_argument('-p', const=True, default=False, nargs='?',
748
- help='Pretty print')
774
+ {parserName}_parser.add_argument('-t', const=True, default=False, nargs='?', help='Print GraphQL query without sending API call')
775
+ {parserName}_parser.add_argument('-v', const=True, default=False, nargs='?', help='Verbose output')
776
+ {parserName}_parser.add_argument('-p', const=True, default=False, nargs='?', help='Pretty print')
777
+ {parserName}_parser.add_argument('-H', '--header', action='append', dest='headers', help='Add custom headers in "Key: Value" format. Can be used multiple times.')
778
+ {parserName}_parser.add_argument('--headers-file', dest='headers_file', help='Load headers from a file. Each line should contain a header in "Key: Value" format.')
749
779
  {parserName}_parser.set_defaults(func=createRequest,operation_name='{parserName.replace("_",".")}')
750
780
  """
751
781
  else:
@@ -770,14 +800,13 @@ def renderSubParser(subParser,parentParserPath):
770
800
  if "path" in subOperation:
771
801
  command = parentParserPath.replace("_"," ")+" "+subOperationName
772
802
  cliDriverStr += f"""
773
- {subParserPath}_parser.add_argument('json', help='Variables in JSON format.')
803
+ {subParserPath}_parser.add_argument('json', nargs='?', default='{{}}', help='Variables in JSON format (defaults to empty object if not provided).')
774
804
  {subParserPath}_parser.add_argument('-accountID', help='Override the CATO_ACCOUNT_ID environment variable with this value.')
775
- {subParserPath}_parser.add_argument('-t', const=True, default=False, nargs='?',
776
- help='Print test request preview without sending api call')
777
- {subParserPath}_parser.add_argument('-v', const=True, default=False, nargs='?',
778
- help='Verbose output')
779
- {subParserPath}_parser.add_argument('-p', const=True, default=False, nargs='?',
780
- help='Pretty print')
805
+ {subParserPath}_parser.add_argument('-t', const=True, default=False, nargs='?', help='Print GraphQL query without sending API call')
806
+ {subParserPath}_parser.add_argument('-v', const=True, default=False, nargs='?', help='Verbose output')
807
+ {subParserPath}_parser.add_argument('-p', const=True, default=False, nargs='?', help='Pretty print')
808
+ {subParserPath}_parser.add_argument('-H', '--header', action='append', dest='headers', help='Add custom headers in "Key: Value" format. Can be used multiple times.')
809
+ {subParserPath}_parser.add_argument('--headers-file', dest='headers_file', help='Load headers from a file. Each line should contain a header in "Key: Value" format.')
781
810
  {subParserPath}_parser.set_defaults(func=createRequest,operation_name='{subOperation["path"]}')
782
811
  """
783
812
  else:
@@ -803,6 +832,10 @@ def writeReadmes(catoApiSchema):
803
832
  `catocli raw '{ "query": "query operationNameHere($yourArgument:String!) { field1 field2 }", "variables": { "yourArgument": "string", "accountID": "10949" }, "operationName": "operationNameHere" } '`
804
833
 
805
834
  `catocli raw '{ "query": "mutation operationNameHere($yourArgument:String!) { field1 field2 }", "variables": { "yourArgument": "string", "accountID": "10949" }, "operationName": "operationNameHere" } '`
835
+
836
+ #### Override API endpoint
837
+
838
+ `catocli raw --endpoint https://custom-api.example.com/graphql '<json>'`
806
839
  """
807
840
  parserPath = "../catocli/parsers/raw"
808
841
  if not os.path.exists(parserPath):
@@ -1009,7 +1042,7 @@ def generateGraphqlPayload(variablesObj,operation,operationName):
1009
1042
  queryStr += ") {\n" + renderArgsAndFields("", variablesObj, operation, operation["type"]["definition"], " ") + " }"
1010
1043
  queryStr += indent + "\n}";
1011
1044
  body = {
1012
- "query":queryStr.replace("\n", " ").replace("\t", " ").replace(" ", " ").replace(" ", " ").replace(" ", " "),
1045
+ "query":queryStr,
1013
1046
  "variables":variablesObj,
1014
1047
  "operationName":renderCamelCase(".".join(operationAry)),
1015
1048
  }