Created
March 25, 2020 19:53
-
-
Save ajxchapman/443c1673e0948f92e59452e3b5951c99 to your computer and use it in GitHub Desktop.
Revisions
-
ajxchapman created this gist
Mar 25, 2020 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,45 @@ import json import re import sys scopes = [] f = sys.stdin if len(sys.argv) == 2: f = open(sys.argv[1]) scopes_defs = [x.strip().lower() for x in f.readlines() if len(x.strip())] for scope_def in scopes_defs: scope = { "enabled" : True, "host" : scope_def, "protocol" : "any" } if scope["host"].startswith("http://") or scope["host"].startswith("https://"): scope["protocol"], scope["host"] = scope["host"].split("//", 1) scope["protocol"] = scope["protocol"].rstrip(":") if scope["host"].startswith("*"): scope["host"] = ".*{}$".format(re.escape(scope["host"].lstrip("*"))) if "/" in scope["host"]: scope["host"], scope["file"] = scope["host"].split("/", 1) if not len(scope["file"]): del scope["file"] else: scope["file"] = "^/{}.*".format(re.escape(scope["file"].rstrip("*"))) if ":" in scope["host"]: scope["host"], scope["port"] = scope["host"].split(":", 1) scopes.append(scope) print(json.dumps({ "target": { "scope": { "advanced_mode": True, "exclude": [], "include": scopes } } }, indent=4))