Add checks for secrets and template
This commit is contained in:
parent
7988598fa8
commit
44be482846
1 changed files with 25 additions and 2 deletions
27
install.py
27
install.py
|
@ -42,9 +42,19 @@ class Installer:
|
||||||
by the user. If the secrets is wrong, or missing, fail.
|
by the user. If the secrets is wrong, or missing, fail.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open("secrets.template", "r") as template_file:
|
||||||
|
template_content = [
|
||||||
|
line.strip()
|
||||||
|
for line in template_file.readlines()
|
||||||
|
if not line.startswith("#") and line.strip()
|
||||||
|
]
|
||||||
|
except FileNotFoundError:
|
||||||
|
print("No 'secrets.template' file found. Did you delete it?")
|
||||||
|
sys.exit(1)
|
||||||
try:
|
try:
|
||||||
with open("secrets", "r") as secrets_file:
|
with open("secrets", "r") as secrets_file:
|
||||||
secrets = [
|
secrets_content = [
|
||||||
line.strip()
|
line.strip()
|
||||||
for line in secrets_file.readlines()
|
for line in secrets_file.readlines()
|
||||||
if not line.startswith("#") and line.strip()
|
if not line.startswith("#") and line.strip()
|
||||||
|
@ -52,7 +62,20 @@ class Installer:
|
||||||
except FileNotFoundError:
|
except FileNotFoundError:
|
||||||
print("No 'secrets' file found. Did you forget to create it?")
|
print("No 'secrets' file found. Did you forget to create it?")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
for line in secrets:
|
|
||||||
|
# Check that the template file and secrets file have the same keys
|
||||||
|
template_keys = [line.split("=")[0] for line in template_content]
|
||||||
|
secrets_keys = [line.split("=")[0] for line in secrets_content]
|
||||||
|
|
||||||
|
if template_keys != secrets_keys:
|
||||||
|
print(
|
||||||
|
"'secrets.template' and 'secrets' don't have the same keys.\n"
|
||||||
|
"Perhaps you have forgotten to add some?"
|
||||||
|
)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
# Check that each key has a value that has been set:
|
||||||
|
for line in secrets_content:
|
||||||
key, value = line.split("=")
|
key, value = line.split("=")
|
||||||
value = value.replace("'", "").replace('"', "")
|
value = value.replace("'", "").replace('"', "")
|
||||||
if not value:
|
if not value:
|
||||||
|
|
Loading…
Add table
Reference in a new issue