mirror of
https://github.com/khuedoan/homelab.git
synced 2024-12-23 01:24:36 +07:00
fix(hacks): patch secret if existed (#131)
This commit is contained in:
parent
250e6d2712
commit
529a2651a7
@ -31,9 +31,14 @@ gitea_url = f"http://{gitea_user}:{urllib.parse.quote_plus(gitea_pass)}@{gitea_h
|
|||||||
|
|
||||||
kanidm_host = client.NetworkingV1Api().read_namespaced_ingress('kanidm', 'kanidm').spec.rules[0].host
|
kanidm_host = client.NetworkingV1Api().read_namespaced_ingress('kanidm', 'kanidm').spec.rules[0].host
|
||||||
|
|
||||||
def create_secret(name: str, namespace: str, data: dict) -> None:
|
def apply_secret(name: str, namespace: str, data: dict) -> None:
|
||||||
try:
|
try:
|
||||||
client.CoreV1Api().read_namespaced_secret(name, namespace)
|
client.CoreV1Api().read_namespaced_secret(name, namespace)
|
||||||
|
patch_body = client.V1Secret(
|
||||||
|
metadata=client.V1ObjectMeta(name=name),
|
||||||
|
data=data,
|
||||||
|
)
|
||||||
|
client.CoreV1Api().replace_namespaced_secret(name, namespace, patch_body)
|
||||||
except client.exceptions.ApiException:
|
except client.exceptions.ApiException:
|
||||||
# Secret doesn't exist, create a new one
|
# Secret doesn't exist, create a new one
|
||||||
new_secret = client.V1Secret(
|
new_secret = client.V1Secret(
|
||||||
@ -60,7 +65,7 @@ def setup_gitea_access_token(name: str, scopes: list[str]) -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
if resp.status_code == 201:
|
if resp.status_code == 201:
|
||||||
create_secret(
|
apply_secret(
|
||||||
f"gitea.{name}",
|
f"gitea.{name}",
|
||||||
"global-secrets",
|
"global-secrets",
|
||||||
{
|
{
|
||||||
@ -92,7 +97,7 @@ def setup_gitea_oauth_app(name: str, redirect_uri: str) -> None:
|
|||||||
)
|
)
|
||||||
|
|
||||||
if resp.status_code == 201:
|
if resp.status_code == 201:
|
||||||
create_secret(
|
apply_secret(
|
||||||
f"gitea.{name}",
|
f"gitea.{name}",
|
||||||
"global-secrets",
|
"global-secrets",
|
||||||
{
|
{
|
||||||
@ -190,7 +195,7 @@ def setup_kanidm_oauth_app(name: str, redirect_uri: str) -> None:
|
|||||||
check=True,
|
check=True,
|
||||||
).stdout.decode("utf-8"))['secret']
|
).stdout.decode("utf-8"))['secret']
|
||||||
|
|
||||||
create_secret(
|
apply_secret(
|
||||||
f"kanidm.{name}",
|
f"kanidm.{name}",
|
||||||
"global-secrets",
|
"global-secrets",
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user