Update Kubernetes Services Wiki / Generate and Update K8s Wiki (push) Successful in 15s
43 lines
1.7 KiB
Python
43 lines
1.7 KiB
Python
import json
|
|
from http.cookiejar import CookieJar
|
|
from pathlib import Path
|
|
from urllib.request import HTTPCookieProcessor, Request, build_opener
|
|
|
|
|
|
server = "https://repo.hexor.cy"
|
|
cookies = CookieJar()
|
|
session = build_opener(HTTPCookieProcessor(cookies))
|
|
headers = {"Content-Type": "application/json", "Origin": server}
|
|
|
|
|
|
def post(path, body):
|
|
request = Request(server + "/api/v1/" + path, json.dumps(body).encode(), headers)
|
|
with session.open(request, timeout=30) as response:
|
|
return response.read()
|
|
|
|
|
|
manifest = Path("/config/sso.yaml").read_text()
|
|
credentials = Path("/credentials")
|
|
client_secret = (credentials / "client-secret").read_text()
|
|
post("auth/login", {"username": "admin", "password": (credentials / "admin-password").read_text()})
|
|
try:
|
|
headers["X-CSRF-Token"] = next(cookie.value for cookie in cookies if cookie.name == "oa_csrf")
|
|
result = json.loads(post("admin/declarative/apply", {
|
|
"manifest": manifest,
|
|
"force_secrets": True,
|
|
"secrets": {"OIDC_CLIENT_SECRET": client_secret},
|
|
}))
|
|
[provider] = result["items"]
|
|
if provider["name"] != "keycloak" or provider["result"] != "applied":
|
|
raise RuntimeError("OpenArtifact did not apply the Keycloak provider")
|
|
print("Keycloak SSO provider applied")
|
|
publisher = json.loads(post("admin/declarative/apply", {
|
|
"manifest": Path("/config/winget-publisher.yaml").read_text(),
|
|
}))
|
|
items = publisher["items"]
|
|
if len(items) != 3 or any(item["result"] != "applied" for item in items):
|
|
raise RuntimeError("OpenArtifact did not apply the WinGet publisher policy")
|
|
print("WinGet publisher policy applied")
|
|
finally:
|
|
post("auth/logout", {})
|