-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adding in all rules build * doc update * bump version
- Loading branch information
Showing
5 changed files
with
62 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,42 @@ | |
import json | ||
import glob | ||
import re | ||
import urllib.request | ||
|
||
def download_resource_type_list(): | ||
url = "https://cloudformation-schema.s3.us-west-2.amazonaws.com/resourcetypelist.json" | ||
response = urllib.request.urlopen(url) | ||
data = json.loads(response.read()) | ||
return data | ||
|
||
def create_guard_rules_registry_all_rules(dirName, version): | ||
aws_rules_directory = dirName + '/rules/aws/**/*.guard' | ||
controls = ["all rules in AWS Guard Rules Registry"] | ||
mappings = [] | ||
resource_list = download_resource_type_list() | ||
for build_file in glob.iglob(aws_rules_directory, recursive=True): | ||
reports_on = [] | ||
build_file_relative_path = os.path.relpath(build_file) | ||
for resource in resource_list: | ||
with open(build_file) as build_file_contents: | ||
if re.search(resource, build_file_contents.read()) is not None: | ||
reports_on.append(resource) | ||
rule_json = { | ||
"guardFilePath": build_file_relative_path, | ||
"reportsOn": reports_on, | ||
"controls": controls | ||
} | ||
mappings.append(rule_json) | ||
all_rules_json = { | ||
"owner": "AWS", | ||
"ruleSetName": "guard-rules-registry-all-rules", | ||
"version": version, | ||
"description": "All AWS Guard Rules Registry in single rule set", | ||
"contact": "[email protected]", | ||
"mappings": mappings | ||
} | ||
with open('mappings/rule_set_guard_rules_registry_all_rules.json', 'w', encoding='utf-8') as outfile: | ||
json.dump(all_rules_json, outfile, ensure_ascii=False, indent=2) | ||
|
||
def create_output_directory(): | ||
path = "./docker/output/" | ||
|
@@ -36,7 +72,8 @@ def build_custom_message(rule_set, control_list ): | |
'''.format(ruleset=rule_set, Control_List=control_list ) | ||
return message | ||
|
||
def main(directory): | ||
def main(directory, version): | ||
create_guard_rules_registry_all_rules(directory, version) | ||
basedirectory = directory + '/mappings/rule_set_*.json' | ||
create_output_directory() | ||
for build_file in glob.iglob(basedirectory, recursive=True): | ||
|
@@ -63,6 +100,8 @@ def main(directory): | |
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser(description='Guard Rules Registry Build') | ||
parser.add_argument("-d","--directory", required=False,default=os.getcwd(),help="Directory to download the audio to") | ||
parser.add_argument("-r","--release", required=True,default="1.0.0",help="The release version for all rules file") | ||
args = parser.parse_args() | ||
directory = args.directory | ||
main(directory) | ||
version = args.release | ||
main(directory, version) |