36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
from pathlib import Path
|
|
import os
|
|
import yaml
|
|
|
|
root = Path(__file__).resolve().parent.parent
|
|
directory = root / "infra/otel/grafana/provisioning/datasources"
|
|
|
|
template = directory / "datasources.yaml.template"
|
|
output = directory / "datasources.yaml"
|
|
certs = root / "infra/certs"
|
|
|
|
data = yaml.safe_load(template.read_text())
|
|
|
|
pem = {
|
|
"tlsCACert": (certs / "ca.crt").read_text(),
|
|
"tlsClientCert": (certs / "grafana.crt").read_text(),
|
|
"tlsClientKey": (certs / "grafana.key").read_text(),
|
|
}
|
|
|
|
for datasource in data["datasources"]:
|
|
if datasource["name"] not in ("Prometheus", "Loki", "Tempo"):
|
|
continue
|
|
|
|
datasource.setdefault("jsonData", {})
|
|
datasource["jsonData"]["tlsAuth"] = True
|
|
datasource["jsonData"]["tlsAuthWithCACert"] = True
|
|
datasource["jsonData"]["tlsSkipVerify"] = False
|
|
datasource["secureJsonData"] = pem.copy()
|
|
|
|
output.write_text(yaml.safe_dump(data, sort_keys=False, allow_unicode=True))
|
|
os.chmod(output, 0o600)
|
|
|
|
print(f"Generated {output.relative_to(root)}")
|
|
print("Permissions: 600")
|
|
print("PEM contents were not printed.")
|