@@ -0,0 +1,25 @@
|
||||
"""Configure a new deployment; never reads secrets from shell arguments."""
|
||||
import argparse,os,re,secrets
|
||||
from pathlib import Path
|
||||
from dotenv import dotenv_values,set_key
|
||||
|
||||
def main():
|
||||
parser=argparse.ArgumentParser()
|
||||
parser.add_argument('--domain',required=True)
|
||||
parser.add_argument('--env',default='/etc/dilib-dashboard/dashboard.env')
|
||||
args=parser.parse_args()
|
||||
if not re.fullmatch(r'[a-zA-Z0-9](?:[a-zA-Z0-9.-]*[a-zA-Z0-9])?',args.domain):
|
||||
parser.error('Domain ohne Protokoll oder Port angeben')
|
||||
path=Path(args.env)
|
||||
if not path.is_file():parser.error('Env-Datei fehlt; zuerst install-central.sh ausführen')
|
||||
current=dotenv_values(path)
|
||||
# Updating the domain does not rotate existing secrets or change the database.
|
||||
changes={'ALLOWED_HOSTS':args.domain+',127.0.0.1,localhost',
|
||||
'CSRF_TRUSTED_ORIGINS':'https://'+args.domain}
|
||||
for key in ('DJANGO_SECRET_KEY','NICEGUI_STORAGE_SECRET'):
|
||||
if not current.get(key) or current[key].startswith('CHANGE_ME'):
|
||||
changes[key]=secrets.token_urlsafe(64)
|
||||
os.umask(0o077)
|
||||
for key,value in changes.items():set_key(path,key,value,quote_mode='never')
|
||||
print('Domain und gegebenenfalls Secrets gesetzt. DATABASE_URL und SMTP separat konfigurieren.')
|
||||
if __name__=='__main__':main()
|
||||
Reference in New Issue
Block a user