Skip to content

Commit

Permalink
addinmg validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Moshe-Rappaport-CA committed Sep 12, 2021
1 parent 2edffd1 commit ec92031
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions export.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


def load_rules():
p1 = currDir + '/rules'
p1 = os.path.join(currDir, 'rules')
regofile = 'raw.rego'
rules_path = Path(p1).glob('**/*.json')
loaded_rules = {} # rules loaded from file system
Expand All @@ -32,7 +32,7 @@ def load_rules():


def load_controls(loaded_rules: dict):
p2 = currDir + '/controls'
p2 = os.path.join(currDir, 'controls')
controls_path = Path(p2).glob('**/*.json')
loaded_controls = {}

Expand All @@ -54,7 +54,7 @@ def load_controls(loaded_rules: dict):


def load_frameworks(loaded_controls: dict):
p3 = currDir + '/frameworks'
p3 = os.path.join(currDir, 'frameworks')
frameworks_path = Path(p3).glob('**/*.json')
loaded_frameworks = {}

Expand All @@ -73,6 +73,23 @@ def load_frameworks(loaded_controls: dict):

return loaded_frameworks

def validate_controls():
p4 = os.path.join(currDir, 'controls')
controls_path = list(Path(p4).glob('**/*.json'))
set_of_ids = set()

for path in controls_path:
path_in_str = str(path)

with open(path_in_str, "r") as f:
new_control = json.load(f)

set_of_ids.add(int(new_control["id"][2:]))

sum_of_controls = len(controls_path)
if sum_of_controls != len(set_of_ids):
raise Exception("Error validate the numbers of controls, {} != {}".format(sum_of_controls ,len(set_of_ids)))


def export_json(d: dict, output_path: str):
os.makedirs(output_path, exist_ok=True)
Expand All @@ -85,7 +102,7 @@ def export_json(d: dict, output_path: str):
if __name__ == '__main__':
rules = load_rules()
controls = load_controls(loaded_rules=rules)
# TODO - validate controls
validate_controls()
frameworks = load_frameworks(loaded_controls=controls)

export_json(d=frameworks, output_path="release")

0 comments on commit ec92031

Please sign in to comment.