commit
cd2e02bb82
@ -1,9 +1,9 @@
|
|||||||
from requests import get
|
from requests import get
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
from minio import Minio
|
from minio import Minio
|
||||||
|
|
||||||
|
|
||||||
def main():
|
|
||||||
minio_client = Minio(
|
minio_client = Minio(
|
||||||
"minio.develop.sprinthub.ru:9000",
|
"minio.develop.sprinthub.ru:9000",
|
||||||
access_key="serviceminioadmin",
|
access_key="serviceminioadmin",
|
||||||
@ -11,8 +11,14 @@ def main():
|
|||||||
secure=False
|
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 = get('http://configurator/api/v1/fetch?project=certupdater&stage=development').json()['configs']['hosts']
|
|
||||||
hosts = {**hosts, 'platform.develop.sprinthub.ru': {'host': 'platform-nginx', 'port': 1238}}
|
hosts = {**hosts, 'platform.develop.sprinthub.ru': {'host': 'platform-nginx', 'port': 1238}}
|
||||||
|
|
||||||
config = ''
|
config = ''
|
||||||
@ -38,22 +44,26 @@ def main():
|
|||||||
}}
|
}}
|
||||||
}}\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.mkdir(f'/etc/nginx/{host}')
|
os.makedirs(f'/etc/nginx/{host}', exist_ok=True)
|
||||||
except FileExistsError:
|
except OSError as e:
|
||||||
...
|
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:
|
||||||
with open('/etc/nginx/hosts.conf', 'w') as fp:
|
print(f"Error processing host {host}: {e}", file=sys.stderr)
|
||||||
fp.write(config)
|
continue
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
main()
|
with open('/etc/nginx/hosts.conf', 'w') as fp:
|
||||||
|
fp.write(config)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(f"Error writing config file: {e}", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
@ -1,4 +1,11 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
python3 prepare.py
|
if ! python3 prepare.py; then
|
||||||
nginx -s reload
|
echo "Error running prepare.py" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! nginx -s reload; then
|
||||||
|
echo "Error reloading nginx" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
Loading…
Reference in New Issue
Block a user