Better parsing of the secrets file for verification
This commit is contained in:
parent
cc349b0c45
commit
32b07ce637
2 changed files with 11 additions and 8 deletions
16
install.py
16
install.py
|
@ -46,7 +46,7 @@ class Installer:
|
|||
with open("secrets.template", "r") as template_file:
|
||||
template_content = [
|
||||
line.strip()
|
||||
for line in template_file.readlines()
|
||||
for line in template_file.read().split("\n\n")
|
||||
if not line.startswith("#") and line.strip()
|
||||
]
|
||||
except FileNotFoundError:
|
||||
|
@ -63,10 +63,10 @@ class Installer:
|
|||
print("No 'secrets' file found. Did you forget to create it?")
|
||||
sys.exit(1)
|
||||
|
||||
# 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]
|
||||
template_keys = [line.split("=")[0] for line in template_content if "=" in line]
|
||||
secrets_keys = [line.split("=")[0] for line in secrets_content if "=" in line]
|
||||
|
||||
# Check that the template file and secrets file have the same keys
|
||||
if template_keys != secrets_keys:
|
||||
print(
|
||||
"'secrets.template' and 'secrets' don't have the same keys.\n"
|
||||
|
@ -74,12 +74,12 @@ class Installer:
|
|||
)
|
||||
sys.exit(1)
|
||||
|
||||
secrets_values = [line.split("=")[1] for line in secrets_content if "=" in line]
|
||||
|
||||
# Check that each key has a value that has been set:
|
||||
for line in secrets_content:
|
||||
key, value = line.split("=")
|
||||
value = value.replace("'", "").replace('"', "")
|
||||
for i, value in enumerate(secrets_values):
|
||||
if not value:
|
||||
print(line)
|
||||
key = secrets_keys[i]
|
||||
print(f" 'secrets' file has no value for {key}, please add one.")
|
||||
sys.exit(1)
|
||||
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
# secrets - is sourced by some commands - this is a template
|
||||
|
||||
SETUP_COCKPIT_EMAIL='john@doe.com'
|
||||
|
||||
SSH_REPO='user@ho.st'
|
||||
|
||||
BORG_PASSPHRASE='passphrase'
|
||||
|
||||
BORG_EXCLUDES="\
|
||||
/path/to/exlude/*
|
||||
/another/*/path/to/exlude/*
|
||||
|
|
Loading…
Add table
Reference in a new issue