dn-scribe commited on
Commit
21e95e1
·
unverified ·
2 Parent(s): 1ae1d2c22a2ec5

Merge pull request #1 from scribe-security/policy-dataset-update

Browse files
scribe_python_client/client.py CHANGED
@@ -12,15 +12,16 @@ from .constants import (
12
  SCRIBE_VULNERABILITIES_DATASET,
13
  SCRIBE_PRODUCTS_DATASET,
14
  SCRIBE_POLICY_DATASET,
15
- SCRIBE_TEAM_STAT_DATASET
 
16
  )
17
 
18
  class ScribeClient:
19
- scribe_vulnerabilities_dataset = "API Vulnerabilities"
20
- scribe_products_dataset = "asbom_filtered"
21
- scribe_policy_dataset = "Policy results v5"
22
- scribe_team_stat_dataset ="MARKETING Team activity"
23
- scribe_lineage_dataset="extended_lineage_new"
24
 
25
  def get_chache_data(self):
26
  return {
@@ -769,18 +770,21 @@ class ScribeClient:
769
  "columns": [
770
  "logical_app",
771
  "logical_app_version",
 
 
772
  "status",
773
  "time_evaluated",
774
- "initiative_id",
775
- "gen_rule_name",
776
- "status_string",
 
777
  ],
778
  "filters": [
779
- {
780
- "col": "initiative_id",
781
- "op": "like",
782
- "val": initiative
783
- },
784
  {
785
  "col": "logical_app",
786
  "op": "==",
@@ -793,12 +797,12 @@ class ScribeClient:
793
  },
794
  {
795
  "col": "status",
796
- "op": "!=",
797
- "val": 'notApplicable'
798
  }
799
  ],
800
  "metrics": [],
801
- "orderby": [["time_evaluated", False], ["status", True]],
802
  "row_limit": 10
803
  }
804
  ],
@@ -818,44 +822,19 @@ class ScribeClient:
818
  return {}, logical_app_version
819
  return {}, logical_app_version
820
 
821
- def get_policy_results_str(self, logical_app="scribe-platform", logical_app_version=None, initiative="%", with_link=True):
822
  r, logical_app_version = self.get_policy_results(logical_app, logical_app_version, initiative)
823
  if not r:
824
  return "Failed getting policy results"
825
 
 
826
  try:
827
- policy_list = r["result"][0]["data"]
828
- if not policy_list:
829
- return f"No policy results found for product {logical_app}: {logical_app_version} and initiative {initiative}"
830
-
831
- # Prepare headers and rows for the table
832
- headers = ["Rule", "Status", "Time Evaluated", "Type", "Details"]
833
- rows = [
834
- [
835
- result['gen_rule_name'],
836
- result['status'],
837
- result['time_evaluated'],
838
- result['initiative_id'],
839
- result['status_string'].replace('\n', ' ')
840
- ]
841
- for result in policy_list
842
- ]
843
-
844
- # Format the table
845
- table = self.format_table(headers, rows)
846
-
847
- if with_link:
848
- table += self.get_link(
849
- use="product_policy_results",
850
- text="Policy results",
851
- params={"product": logical_app, "product_version": logical_app_version, "show_file_components": "false"}
852
- )
853
 
854
  except Exception as e:
855
  logging.error(f"Error decoding JSON: {e}")
856
- table = "Error getting policy results"
857
-
858
- return table
859
 
860
 
861
  def get_product_lineage(self, logical_app, logical_app_version=None):
 
12
  SCRIBE_VULNERABILITIES_DATASET,
13
  SCRIBE_PRODUCTS_DATASET,
14
  SCRIBE_POLICY_DATASET,
15
+ SCRIBE_TEAM_STAT_DATASET,
16
+ SCRIBE_LINEAGE_DATASET
17
  )
18
 
19
  class ScribeClient:
20
+ scribe_vulnerabilities_dataset = SCRIBE_VULNERABILITIES_DATASET
21
+ scribe_products_dataset = SCRIBE_PRODUCTS_DATASET
22
+ scribe_policy_dataset = SCRIBE_POLICY_DATASET
23
+ scribe_team_stat_dataset = SCRIBE_TEAM_STAT_DATASET
24
+ scribe_lineage_dataset=SCRIBE_LINEAGE_DATASET
25
 
26
  def get_chache_data(self):
27
  return {
 
770
  "columns": [
771
  "logical_app",
772
  "logical_app_version",
773
+ "asset_type",
774
+ "asset_name",
775
  "status",
776
  "time_evaluated",
777
+ "initiative_name",
778
+ "control_name",
779
+ "rule_name",
780
+ "message"
781
  ],
782
  "filters": [
783
+ # {
784
+ # "col": "initiative_name",
785
+ # "op": "like",
786
+ # "val": initiative
787
+ # },
788
  {
789
  "col": "logical_app",
790
  "op": "==",
 
797
  },
798
  {
799
  "col": "status",
800
+ "op": "not in",
801
+ "val": ['Not Applicable', 'Not Applicable']
802
  }
803
  ],
804
  "metrics": [],
805
+ "orderby": [],#["time_evaluated", False], ["status", True]],
806
  "row_limit": 10
807
  }
808
  ],
 
822
  return {}, logical_app_version
823
  return {}, logical_app_version
824
 
825
+ def get_policy_results_str(self, logical_app="scribe-platform", logical_app_version=None, initiative="%", with_link = True):
826
  r, logical_app_version = self.get_policy_results(logical_app, logical_app_version, initiative)
827
  if not r:
828
  return "Failed getting policy results"
829
 
830
+ o = f"Policy results for {logical_app}:\n"
831
  try:
832
+ o = self.query_result_to_str(o, r)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
833
 
834
  except Exception as e:
835
  logging.error(f"Error decoding JSON: {e}")
836
+ o = "Error getting policy results"
837
+ return o
 
838
 
839
 
840
  def get_product_lineage(self, logical_app, logical_app_version=None):
scribe_python_client/constants.py CHANGED
@@ -1,5 +1,5 @@
1
  SCRIBE_VULNERABILITIES_DATASET = "API Vulnerabilities"
2
  SCRIBE_PRODUCTS_DATASET = "asbom_filtered"
3
- SCRIBE_POLICY_DATASET = "Policy results v5"
4
  SCRIBE_TEAM_STAT_DATASET = "MARKETING Team activity"
5
  SCRIBE_LINEAGE_DATASET = "extended_lineage_new"
 
1
  SCRIBE_VULNERABILITIES_DATASET = "API Vulnerabilities"
2
  SCRIBE_PRODUCTS_DATASET = "asbom_filtered"
3
+ SCRIBE_POLICY_DATASET = "policy_initiative"
4
  SCRIBE_TEAM_STAT_DATASET = "MARKETING Team activity"
5
  SCRIBE_LINEAGE_DATASET = "extended_lineage_new"
scribe_python_client/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.1.3"
 
1
+ __version__ = "0.1.4"
setup.py CHANGED
@@ -1,11 +1,22 @@
1
  from setuptools import setup, find_packages
2
  from pathlib import Path
3
- from scribe_python_client.version import __version__
4
 
5
  # Read the README file
6
  this_directory = Path(__file__).parent
7
  long_description = (this_directory / "README.md").read_text()
8
 
 
 
 
 
 
 
 
 
 
 
 
9
  setup(
10
  name='scribe-python-client',
11
  version=__version__,
 
1
  from setuptools import setup, find_packages
2
  from pathlib import Path
3
+
4
 
5
  # Read the README file
6
  this_directory = Path(__file__).parent
7
  long_description = (this_directory / "README.md").read_text()
8
 
9
+ def read_version():
10
+ version_path = Path(__file__).parent / "scribe_python_client" / "version.py"
11
+ with open(version_path) as f:
12
+ for line in f:
13
+ if line.startswith("__version__"):
14
+ delim = '"' if '"' in line else "'"
15
+ return line.split(delim)[1]
16
+ raise RuntimeError("Unable to find version string.")
17
+
18
+ __version__ = read_version()
19
+
20
  setup(
21
  name='scribe-python-client',
22
  version=__version__,