-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsparser.py
executable file
·50 lines (43 loc) · 1.6 KB
/
sparser.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import yaml
import re
import os
import secrets
import string
from random import randint
def generate_password(password_length):
alphabet = string.ascii_letters +string.digits
characters = [secrets.choice(alphabet) for i in range(password_length)]
password = ''.join(characters)
return password
def secrets_file():
if os.path.isfile('./secrets.yml'):
with open("secrets.yml", "r") as ymlfile:
cfg = yaml.safe_load(ymlfile)
return cfg
else:
with open("secrets.yml.example", "r") as ymlfile:
cfg = yaml.safe_load(ymlfile)
return cfg
def input_file():
with open("docker-compose.yml.template", "r") as inputfile:
inf = inputfile.read()
return inf
def output_file(output):
with open("docker-compose.yml", "w+") as outputfile:
outputfile.write(output)
if __name__ == '__main__':
secret_list = secrets_file()
document = input_file()
for category in secret_list['secrets']:
for namekey in secret_list['secrets'][category]:
print(namekey)
if str(secret_list['secrets'][category][namekey]) == "GENERATE_PASS":
password = generate_password(8)
document=document.replace(namekey, generate_password(8))
elif str(secret_list['secrets'][category][namekey]) == "GENERATE_NICK":
document=document.replace(namekey, "gkci_"+ str(randint(1, 100)))
else:
document=document.replace(namekey, str(secret_list['secrets'][category][namekey]))
output_file(document)