A bit of refactoring

This commit is contained in:
quietsy
2023-09-22 21:54:00 +03:00
parent cab89dc4c1
commit b5fb66d9a3
+4 -8
View File
@@ -25,11 +25,10 @@ def find_apps():
continue continue
file = open(file_path, "r") file = open(file_path, "r")
content = file.read() content = file.read()
match_proxy(content, file_path, apps) match_proxy(apps, auths, content, file_path)
match_auth(apps, auths)
return apps, auths return apps, auths
def match_proxy(content, file_path, apps): def match_proxy(apps, auths, content, file_path):
results = re.finditer(PROXY_REGEX, content) results = re.finditer(PROXY_REGEX, content)
for result in results: for result in results:
params = result.groupdict() params = result.groupdict()
@@ -39,12 +38,9 @@ def match_proxy(content, file_path, apps):
if file_path.startswith("/config/nginx/site-confs/") or file_path.endswith(".conf"): if file_path.startswith("/config/nginx/site-confs/") or file_path.endswith(".conf"):
file_path = "auto-proxy" if file_path.startswith("/etc/nginx/http.d/") else file_path file_path = "auto-proxy" if file_path.startswith("/etc/nginx/http.d/") else file_path
apps[app].add(file_path) apps[app].add(file_path)
match_auth(auths, app, file_path, content)
def match_auth(apps, auths): def match_auth(auths, app, file_path, content):
for app, file_paths in apps.items():
for file_path in file_paths:
file = open(file_path, "r")
content = file.read()
if re.findall(AUTHELIA_REGEX, content): if re.findall(AUTHELIA_REGEX, content):
auths[app][file_path] = "Authelia" auths[app][file_path] = "Authelia"
elif re.findall(AUTHENTIK_REGEX, content): elif re.findall(AUTHENTIK_REGEX, content):