Compare commits
No commits in common. "e968457afa506604457a1ce26f778719d0cdfcd0" and "2c2920d7b5dc65670fc5c05f40f4fb8cf3d1c7d7" have entirely different histories.
e968457afa
...
2c2920d7b5
@ -9,28 +9,26 @@ minio_client = Minio(
|
|||||||
"minio.develop.sprinthub.ru:9000",
|
"minio.develop.sprinthub.ru:9000",
|
||||||
access_key="serviceminioadmin",
|
access_key="serviceminioadmin",
|
||||||
secret_key=os.getenv("MINIO_SECRET_KEY", "minioadmin"),
|
secret_key=os.getenv("MINIO_SECRET_KEY", "minioadmin"),
|
||||||
secure=False,
|
secure=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def get(url):
|
def get(url):
|
||||||
with urlopen(url) as response:
|
with urlopen(url) as response:
|
||||||
data = response.read().decode("utf-8")
|
data = response.read().decode('utf-8')
|
||||||
return loads(data)
|
return loads(data)
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = get(
|
response = get('http://configurator/api/v1/fetch?project=certupdater&stage=development')
|
||||||
"http://configurator/api/v1/fetch?project=certupdater&stage=development"
|
hosts = response['configs']['hosts']
|
||||||
)
|
|
||||||
hosts = response["configs"]["hosts"]
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error fetching config: {e}", file=sys.stderr)
|
print(f"Error fetching config: {e}", file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
config = ""
|
hosts = {**hosts, 'platform.develop.sprinthub.ru': {'host': 'platform-nginx', 'port': 1238}}
|
||||||
|
|
||||||
|
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;
|
||||||
@ -50,33 +48,27 @@ for host, params in hosts.items():
|
|||||||
proxy_pass http://{target_host}:{port}$request_uri;
|
proxy_pass http://{target_host}:{port}$request_uri;
|
||||||
}}
|
}}
|
||||||
}}\n\n
|
}}\n\n
|
||||||
""".format(
|
'''.format(host=host, target_host=params['host'], port=params['port'])
|
||||||
host=host, target_host=params["host"], port=params["port"]
|
|
||||||
)
|
|
||||||
try:
|
try:
|
||||||
fullchain = minio_client.get_object(
|
fullchain = minio_client.get_object("certupdater", f'certificates/{host}/fullchain.pem')
|
||||||
"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.makedirs(f'/etc/nginx/{host}', exist_ok=True)
|
||||||
except OSError as e:
|
except OSError as e:
|
||||||
print(f"Error creating directory: {e}", file=sys.stderr)
|
print(f"Error creating directory: {e}", file=sys.stderr)
|
||||||
continue
|
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:
|
except Exception as e:
|
||||||
print(f"Error processing host {host}: {e}", file=sys.stderr)
|
print(f"Error processing host {host}: {e}", file=sys.stderr)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
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)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error writing config file: {e}", file=sys.stderr)
|
print(f"Error writing config file: {e}", file=sys.stderr)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
@ -7,17 +7,16 @@ minio_client = Minio(
|
|||||||
"minio.sprinthub.ru:9000",
|
"minio.sprinthub.ru:9000",
|
||||||
access_key="serviceminioadmin",
|
access_key="serviceminioadmin",
|
||||||
secret_key=os.getenv("MINIO_SECRET_KEY", "minioadmin"),
|
secret_key=os.getenv("MINIO_SECRET_KEY", "minioadmin"),
|
||||||
secure=False,
|
secure=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
hosts = get(
|
hosts = get('http://configurator/api/v1/fetch?project=certupdater&stage=production').json()['configs']['hosts']
|
||||||
"http://configurator/api/v1/fetch?project=certupdater&stage=production"
|
hosts = {**hosts, 'platform.sprinthub.ru': {'host': 'platform-nginx', 'port': 1238}}
|
||||||
).json()["configs"]["hosts"]
|
|
||||||
|
|
||||||
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;
|
||||||
@ -37,21 +36,17 @@ for host, params in hosts.items():
|
|||||||
proxy_pass http://{target_host}:{port}$request_uri;
|
proxy_pass http://{target_host}:{port}$request_uri;
|
||||||
}}
|
}}
|
||||||
}}\n\n
|
}}\n\n
|
||||||
""".format(
|
'''.format(host=host, target_host=params['host'], port=params['port'])
|
||||||
host=host, target_host=params["host"], port=params["port"]
|
fullchain = minio_client.get_object("certupdater", f'certificates/{host}/fullchain.pem')
|
||||||
)
|
privkey = minio_client.get_object("certupdater", f'certificates/{host}/privkey.pem')
|
||||||
fullchain = minio_client.get_object(
|
|
||||||
"certupdater", f"certificates/{host}/fullchain.pem"
|
|
||||||
)
|
|
||||||
privkey = minio_client.get_object("certupdater", f"certificates/{host}/privkey.pem")
|
|
||||||
try:
|
try:
|
||||||
os.mkdir(f"/etc/nginx/{host}")
|
os.mkdir(f'/etc/nginx/{host}')
|
||||||
except FileExistsError:
|
except FileExistsError:
|
||||||
...
|
...
|
||||||
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)
|
||||||
|
|
||||||
with open("/etc/nginx/hosts.conf", "w") as fp:
|
with open('/etc/nginx/hosts.conf', 'w') as fp:
|
||||||
fp.write(config)
|
fp.write(config)
|
||||||
|
Loading…
Reference in New Issue
Block a user