Compare commits
No commits in common. "cd2e02bb8225dc3abd886f3355c32fe0026c0668" and "7e4b38e9da44fe3fdc1da24d3b7de60fc4842296" have entirely different histories.
cd2e02bb82
...
7e4b38e9da
@ -1,69 +1,59 @@
|
|||||||
from requests import get
|
from requests import get
|
||||||
import os
|
import os
|
||||||
import sys
|
|
||||||
from minio import Minio
|
from minio import Minio
|
||||||
|
|
||||||
|
|
||||||
minio_client = Minio(
|
def main():
|
||||||
"minio.develop.sprinthub.ru:9000",
|
minio_client = Minio(
|
||||||
access_key="serviceminioadmin",
|
"minio.develop.sprinthub.ru:9000",
|
||||||
secret_key=os.getenv("MINIO_SECRET_KEY", "minioadmin"),
|
access_key="serviceminioadmin",
|
||||||
secure=False
|
secret_key=os.getenv("MINIO_SECRET_KEY", "minioadmin"),
|
||||||
)
|
secure=False
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
|
||||||
response = get('http://configurator/api/v1/fetch?project=certupdater&stage=development')
|
|
||||||
response.raise_for_status() # Raises an exception for HTTP errors
|
|
||||||
hosts = response.json()['configs']['hosts']
|
|
||||||
except Exception as e:
|
|
||||||
print(f"Error fetching config: {e}", file=sys.stderr)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
hosts = {**hosts, 'platform.develop.sprinthub.ru': {'host': 'platform-nginx', 'port': 1238}}
|
hosts = get('http://configurator/api/v1/fetch?project=certupdater&stage=development').json()['configs']['hosts']
|
||||||
|
hosts = {**hosts, 'platform.develop.sprinthub.ru': {'host': 'platform-nginx', 'port': 1238}}
|
||||||
|
|
||||||
config = ''
|
config = ''
|
||||||
for host, params in hosts.items():
|
for host, params in hosts.items():
|
||||||
config += '''
|
config += '''
|
||||||
server {{
|
server {{
|
||||||
listen 443 ssl http2;
|
listen 443 ssl http2;
|
||||||
listen [::]:443 ssl http2;
|
listen [::]:443 ssl http2;
|
||||||
server_name {host};
|
server_name {host};
|
||||||
|
|
||||||
ssl_certificate /etc/nginx/{host}/fullchain.pem;
|
ssl_certificate /etc/nginx/{host}/fullchain.pem;
|
||||||
ssl_certificate_key /etc/nginx/{host}/privkey.pem;
|
ssl_certificate_key /etc/nginx/{host}/privkey.pem;
|
||||||
|
|
||||||
add_header X-Frame-Options "SAMEORIGIN" always;
|
add_header X-Frame-Options "SAMEORIGIN" always;
|
||||||
add_header X-XSS-Protection "1; mode=block" always;
|
add_header X-XSS-Protection "1; mode=block" always;
|
||||||
add_header X-Content-Type-Options "nosniff" always;
|
add_header X-Content-Type-Options "nosniff" always;
|
||||||
add_header Referrer-Policy "no-refferer-when-downgrade" always;
|
add_header Referrer-Policy "no-refferer-when-downgrade" always;
|
||||||
add_header Content-Security-Policy "default-src * data: 'unsafe-eval' 'unsafe-inline'" always;
|
add_header Content-Security-Policy "default-src * data: 'unsafe-eval' 'unsafe-inline'" always;
|
||||||
|
|
||||||
location / {{
|
location / {{
|
||||||
resolver 127.0.0.11;
|
resolver 127.0.0.11;
|
||||||
proxy_pass http://{target_host}:{port}$request_uri;
|
proxy_pass http://{target_host}:{port}$request_uri;
|
||||||
}}
|
}}
|
||||||
}}\n\n
|
}}\n\n
|
||||||
'''.format(host=host, target_host=params['host'], port=params['port'])
|
'''.format(host=host, target_host=params['host'], port=params['port'])
|
||||||
try:
|
|
||||||
fullchain = minio_client.get_object("certupdater", f'certificates/{host}/fullchain.pem')
|
fullchain = minio_client.get_object("certupdater", f'certificates/{host}/fullchain.pem')
|
||||||
privkey = minio_client.get_object("certupdater", f'certificates/{host}/privkey.pem')
|
privkey = minio_client.get_object("certupdater", f'certificates/{host}/privkey.pem')
|
||||||
try:
|
try:
|
||||||
os.makedirs(f'/etc/nginx/{host}', exist_ok=True)
|
os.mkdir(f'/etc/nginx/{host}')
|
||||||
except OSError as e:
|
except FileExistsError:
|
||||||
print(f"Error creating directory: {e}", file=sys.stderr)
|
...
|
||||||
continue
|
|
||||||
|
|
||||||
with open(f"/etc/nginx/{host}/fullchain.pem", 'wb') as fp:
|
with open(f"/etc/nginx/{host}/fullchain.pem", 'wb') as fp:
|
||||||
fp.write(fullchain.data)
|
fp.write(fullchain.data)
|
||||||
with open(f"/etc/nginx/{host}/privkey.pem", 'wb') as fp:
|
with open(f"/etc/nginx/{host}/privkey.pem", 'wb') as fp:
|
||||||
fp.write(privkey.data)
|
fp.write(privkey.data)
|
||||||
except Exception as e:
|
|
||||||
print(f"Error processing host {host}: {e}", file=sys.stderr)
|
|
||||||
continue
|
|
||||||
|
|
||||||
try:
|
|
||||||
with open('/etc/nginx/hosts.conf', 'w') as fp:
|
with open('/etc/nginx/hosts.conf', 'w') as fp:
|
||||||
fp.write(config)
|
fp.write(config)
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
main()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error writing config file: {e}", file=sys.stderr)
|
print(e)
|
||||||
sys.exit(1)
|
|
||||||
|
@ -1,11 +1,4 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
if ! python3 prepare.py; then
|
python3 prepare.py
|
||||||
echo "Error running prepare.py" >&2
|
nginx -s reload
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! nginx -s reload; then
|
|
||||||
echo "Error reloading nginx" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
Loading…
Reference in New Issue
Block a user