From b3e8bff77411b5327ab8ee2d76f9b048dc90d732 Mon Sep 17 00:00:00 2001 From: Zsolt Ero Date: Thu, 9 Oct 2025 01:22:53 +0200 Subject: [PATCH] work --- init-server.py | 10 +-- .../http_host_lib/nginx_config_gen.py | 61 +++++++++---------- ssh_lib/tasks_http_host.py | 2 + 3 files changed, 36 insertions(+), 37 deletions(-) diff --git a/init-server.py b/init-server.py index 963f9c2..a420f82 100755 --- a/init-server.py +++ b/init-server.py @@ -120,11 +120,11 @@ def tile_gen( # -# @cli.command() -# @common_options -# def debug(hostname, user, port, noninteractive): -# c = get_connection(hostname, user, port) -# run_http_host_sync(c) +@cli.command() +@common_options +def debug(hostname, user, port, noninteractive): + c = get_connection(hostname, user, port) + upload_config_and_certs(c) if __name__ == '__main__': diff --git a/modules/http_host/http_host_lib/nginx_config_gen.py b/modules/http_host/http_host_lib/nginx_config_gen.py index 94e3e65..765b4f3 100644 --- a/modules/http_host/http_host_lib/nginx_config_gen.py +++ b/modules/http_host/http_host_lib/nginx_config_gen.py @@ -21,25 +21,23 @@ def write_nginx_config(): conf = config.json_config - curl_help_lines = [] + curl_help_text = '' for domain_data in conf['domains']: - curl_help_lines += process_domain(domain_data) + curl_help_text += process_domain(domain_data) subprocess.run(['nginx', '-t'], check=True) subprocess.run(['systemctl', 'reload', 'nginx'], check=True) - if config.ofm_config.get('skip_planet'): - curl_help_lines = [l for l in curl_help_lines if '/planet' not in l] - else: - curl_help_lines = [l for l in curl_help_lines if '/monaco' not in l] + exclude_path = '/planet' if conf.get('skip_planet') else '/monaco' + curl_help_lines = [l for l in curl_help_text.splitlines() if exclude_path not in l] - curl_help_str = '\n'.join(curl_help_lines) - print(f'test with:\n{curl_help_str}') + curl_help_joined = '\n'.join(curl_help_lines) + print(f'test with:\n{curl_help_joined}') -def process_domain(domain_data) -> list: - if domain_data['cert'] == 'upload': +def process_domain(domain_data) -> str: + if domain_data['cert']['type'] == 'upload': domain_data['cert_file'] = config.nginx_certs_dir / f'{domain_data["slug"]}.cert' domain_data['key_file'] = config.nginx_certs_dir / f'{domain_data["slug"]}.key' @@ -50,38 +48,40 @@ def process_domain(domain_data) -> list: return create_nginx_conf(domain_data) - return [] + return '' -def create_nginx_conf(domain_data: dict): - dynamic_block_lines, curl_help = dynamic_blocks(domain_data) +def create_nginx_conf(domain_data: dict) -> str: + dynamic_block_text, curl_help_text = dynamic_blocks(domain_data) template = (config.nginx_templates / 'common.conf').read_text() - template = template.replace('__DYNAMIC_BLOCKS__', dynamic_block_lines) + template = template.replace('__DYNAMIC_BLOCKS__', dynamic_block_text) template = template.replace('__DOMAIN_SLUG__', domain_data['slug']) template = template.replace('__DOMAIN__', domain_data['domain']) - curl_help = curl_help.replace('__DOMAIN_SLUG__', domain_data['slug']) - curl_help = curl_help.replace('__DOMAIN__', domain_data['domain']) + curl_help_text = curl_help_text.replace('__DOMAIN_SLUG__', domain_data['slug']) + curl_help_text = curl_help_text.replace('__DOMAIN__', domain_data['domain']) (config.nginx_sites_dir / f'ofm-{domain_data["slug"]}.conf').write_text(template) print(f' nginx config written: {domain_data["domain"]} {domain_data["slug"]}') - return curl_help + print('=' * 20, curl_help_text) + + return curl_help_text -def dynamic_blocks(domain_data: dict): - nginx_conf_lines = '' - curl_help_lines = [] +def dynamic_blocks(domain_data: dict) -> tuple[str, str]: + nginx_conf_text = '' + curl_help_text = '' for subdir in config.mnt_dir.iterdir(): if not subdir.is_dir(): continue area, version = subdir.name.split('-') - nginx_conf_lines += create_version_location( + nginx_conf_text += create_version_location( area=area, version=version, mnt_dir=subdir, domain_data=domain_data ) @@ -90,12 +90,10 @@ def dynamic_blocks(domain_data: dict): f'/{area}/{version}/14/8529/5975.pbf', f'/{area}/{version}/9999/9999/9999.pbf', # empty_tile test ]: - curl_help_lines += [ - f'curl -H "Host: __DOMAIN_SLUG__" -I http://localhost/{path}', - f'curl -sI https://__DOMAIN__{path} | sort', - ] + curl_help_text += f'curl -H "Host: __DOMAIN_SLUG__" -I http://localhost/{path}\n' + curl_help_text += f'curl -sI https://__DOMAIN__{path} | sort\n' - nginx_conf_lines += create_latest_locations(domain_data=domain_data) + nginx_conf_text += create_latest_locations(domain_data=domain_data) for area in config.areas: for path in [ @@ -104,14 +102,13 @@ def dynamic_blocks(domain_data: dict): f'/{area}/19700101_old_version_test/14/8529/5975.pbf', f'/{area}/19700101_old_version_test/9999/9999/9999.pbf', # empty_tile test ]: - curl_help_lines += [ - f'curl -H "Host: __DOMAIN_SLUG__" -I http://localhost/{path}', - f'curl -sI https://__DOMAIN__{path} | sort', - ] + curl_help_text += f'curl -H "Host: __DOMAIN_SLUG__" -I http://localhost/{path}\n' + curl_help_text += f'curl -sI https://__DOMAIN__{path} | sort\n' - nginx_conf_lines += '\n' + (config.nginx_templates / 'static_blocks.conf').read_text() + nginx_conf_text += '\n' + (config.nginx_templates / 'static_blocks.conf').read_text() + print(curl_help_text) - return nginx_conf_lines, curl_help_lines + return nginx_conf_text, curl_help_text def create_version_location(*, area: str, version: str, mnt_dir: Path, domain_data: dict) -> str: diff --git a/ssh_lib/tasks_http_host.py b/ssh_lib/tasks_http_host.py index 7aafb87..7d91cf5 100644 --- a/ssh_lib/tasks_http_host.py +++ b/ssh_lib/tasks_http_host.py @@ -1,4 +1,5 @@ import json +import sys from pathlib import Path import json5 @@ -71,6 +72,7 @@ def upload_config_and_certs(c): domain_data['slug'] = slugify(domain_data['domain'], separator='_') if domain_data['cert']['type'] == 'upload': + print(domain_data) local_cert_path = Path(domain_data['cert']['cert_path']) # handle relative paths - make them relative to config.local_config_dir