Skip to content

Commit b449ae1

Browse files
committed
Created validator
1 parent 375a088 commit b449ae1

File tree

4 files changed

+44
-2
lines changed

4 files changed

+44
-2
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
FROM nginx:latest
33

44
# Install inotify-tools for file monitoring
5-
RUN apt-get update && apt-get install -y inotify-tools
5+
RUN apt-get update && apt-get install -y inotify-tools python3
66

77
# Copy the initial routes.trp file
88
COPY routes.trp /etc/nginx/routes.trp

routes.trp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-

url_validate_and_trim.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import os.path
2+
3+
formated = []
4+
file_name = "routes.trp"
5+
6+
if not file_name.endswith(".trp"):
7+
file_name = file_name + ".trp"
8+
9+
if not os.path.isfile(file_name):
10+
print("File not found: " + file_name + ". Creating...")
11+
f = open(file_name, "w+")
12+
f.write("")
13+
f.close()
14+
print("File created: " + file_name)
15+
16+
if not os.path.getsize(file_name):
17+
print("File is empty: " + file_name)
18+
19+
with open(file_name, "r+") as f:
20+
print("File found: " + file_name + ". Validating...")
21+
content = f.readlines()
22+
23+
if not content:
24+
print("File is empty: " + file_name + ". Nothing to validate")
25+
26+
for line in content:
27+
print("Validating line: " + line)
28+
if str(line).strip() == '':
29+
print("Skipping empty line")
30+
continue
31+
32+
if " => " in line:
33+
print("Appending line: " + line)
34+
formated.append(line)
35+
36+
if not formated:
37+
print("No lines to write to file: " + file_name)
38+
exit(0)
39+
40+
print("Writing to file: " + file_name)
41+
with open(file_name, "w+") as f:
42+
f.writelines(formated)

watch_routes.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,6 @@ generate_config
6565
echo "Monitoring routes.trp for changes..."
6666
while inotifywait -e modify /etc/nginx/routes.trp; do
6767
echo "routes.trp has been modified. Regenerating Nginx configuration..."
68+
python3 ./url_validate_and_trim.py
6869
generate_config
6970
done

0 commit comments

Comments
 (0)