36 lines
1.3 KiB
Python
36 lines
1.3 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")
|
|
finally:
|
|
post("auth/logout", {})
|