#!/venv/bin/python import os.path import yaml import jinja2 def write_config(filename, **kwargs): with open(filename + ".jnj") as f: template = jinja2.Template(f.read()) rendered = template.render(kwargs) with open(filename, 'w') as f: f.write(rendered) def generate_nginx_config(): """ Generates nginx config from the app config """ use_https = os.path.exists('conf/stack/ssl.key') write_config('conf/nginx/nginx.conf', use_https=use_https) def generate_server_config(config): """ Generates server config from the app config """ tuf_server = config.get('TUF_SERVER', None) signing_enabled = config.get('FEATURE_SIGNING', False) write_config('conf/nginx/server-base.conf', tuf_server=tuf_server, signing_enabled=signing_enabled) if __name__ == "__main__": with open('conf/stack/config.yaml', 'r') as f: config = yaml.load(f) generate_server_config(config) generate_nginx_config()