Files
SnarfCode/scripts/patch_semaphore_env.py

68 lines
2.2 KiB
Python

import paramiko
import sys
import json
sys.stdout.reconfigure(encoding='utf-8')
key_path = r'C:\Users\Snarf\.ssh\id_ed25519_snarfnet'
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect("140.44.4.41", username="root", key_filename=key_path, timeout=10)
oidc_config = {
"authentik": {
"display_name": "Sign in with Authentik",
"provider_url": "https://authentik.snarfnet.net/application/o/semaphore/",
"client_id": "semaphore-2e50dbdf",
"client_secret": "V4uazPXN9toUn5Jf2DfsRIFrygf1T0Vcltga-APrzTRjWFN0DIIqNw",
"redirect_url": "https://semaphore.snarfnet.net/auth/oidc/authentik/redirect",
"username_claim": "preferred_username",
"name_claim": "name",
"email_claim": "email",
"scopes": ["openid", "profile", "email", "groups"]
}
}
val = json.dumps(oidc_config)
# Use patch json
patch = {
"spec": {
"template": {
"spec": {
"containers": [
{
"name": "semaphore",
"env": [
{
"name": "SEMAPHORE_OIDC_PROVIDERS",
"value": val
}
]
}
]
}
}
}
}
patch_str = json.dumps(patch)
print("Patching deployment/semaphore...")
stdin, stdout, stderr = ssh.exec_command(f"k3s kubectl patch deployment semaphore -n infrastructure -p '{patch_str}'")
print(stdout.read().decode())
err = stderr.read().decode()
if err: print("Patch stderr:", err)
stdin, stdout, stderr = ssh.exec_command("k3s kubectl rollout status deployment/semaphore -n infrastructure --timeout=60s")
print(stdout.read().decode())
stdin, stdout, stderr = ssh.exec_command("k3s kubectl get pods -n infrastructure -l app.kubernetes.io/name=semaphore -o jsonpath='{.items[0].metadata.name}'")
new_pod = stdout.read().decode().strip()
print(f"Active pod: {new_pod}")
stdin, stdout, stderr = ssh.exec_command(f"k3s kubectl exec -n infrastructure {new_pod} -- env | grep SEMAPHORE_OIDC_PROVIDERS")
print("Active pod env:\n", stdout.read().decode())
ssh.close()