From aa0d4ee4ba3f4a09d6bf9173014e88d1b93d9113 Mon Sep 17 00:00:00 2001
From: OZGCloud <ozgcloud@mgm-tp.com>
Date: Tue, 31 Oct 2023 13:42:24 +0100
Subject: [PATCH] use usermanagerapi user

---
 goofy-client/apps/goofy-e2e/Jenkinsfile       | 21 +++++++++++++------
 .../src/fixtures/argocd/by-ea-dev.yaml        |  2 +-
 .../src/fixtures/argocd/by-main-dev.yaml      |  2 +-
 3 files changed, 17 insertions(+), 8 deletions(-)

diff --git a/goofy-client/apps/goofy-e2e/Jenkinsfile b/goofy-client/apps/goofy-e2e/Jenkinsfile
index ea409ea465..39a5c9197f 100644
--- a/goofy-client/apps/goofy-e2e/Jenkinsfile
+++ b/goofy-client/apps/goofy-e2e/Jenkinsfile
@@ -705,7 +705,7 @@ Map getUserManagerDatabaseSecret(String namespace) {
 
 String getKeycloakUuid(realm, userName) {
     def shScript = """curl -H 'Content-Type: application/json' \
-                        -H 'Authorization: bearer ${getKeycloakAccessToken()}' \
+                        -H 'Authorization: bearer ${getKeycloakAccessToken(realm)}' \
                         'https://${env.SSO_URL}/admin/realms/${realm}/users'
                     """
 
@@ -720,12 +720,21 @@ String getKeycloakUuid(realm, userName) {
 	}
 }
 
-String getKeycloakAccessToken() {
-	withCredentials([usernamePassword(credentialsId: 'keycloak-ovh-cluster', usernameVariable: 'USER', passwordVariable: 'PASSWORD')]) {
-		def token = readJSON text: sh (script: 'curl -d "client_id=admin-cli" -d "username=$USER" -d "password=$PASSWORD" -d "grant_type=password" https://$SSO_URL/realms/master/protocol/openid-connect/token', returnStdout: true)
+Map getUserManagerApiUserCredentials(String namespace) {
+    userManagerApiUserCredentials = readJSON ( text: sh (script: "kubectl get secret usermanagerapiuser-credentials -n ${namespace} -o jsonpath={.data}", returnStdout: true))
 
-		return token.access_token
-	}
+    return [
+        "user": decodeString(userManagerApiUserCredentials.name),
+        "password": decodeString(userManagerApiUserCredentials.password)
+    ]
+}
+
+String getKeycloakAccessToken(String realm) {
+    userManagerApiUserCredentials = getUserManagerApiUserCredentials(realm)
+
+	def token = readJSON text: sh (script: "set +x && curl -d \"client_id=admin-cli\" -d \"username=${userManagerApiUserCredentials.user}\" -d \"password=${userManagerApiUserCredentials.password}\" -d \"grant_type=password\" https://$SSO_URL/realms/$realm/protocol/openid-connect/token", returnStdout: true)
+
+	return token.access_token
 }
 
 Void sendFailureMessage() {
diff --git a/goofy-client/apps/goofy-e2e/src/fixtures/argocd/by-ea-dev.yaml b/goofy-client/apps/goofy-e2e/src/fixtures/argocd/by-ea-dev.yaml
index f0c713ae8b..f92ceb1220 100644
--- a/goofy-client/apps/goofy-e2e/src/fixtures/argocd/by-ea-dev.yaml
+++ b/goofy-client/apps/goofy-e2e/src/fixtures/argocd/by-ea-dev.yaml
@@ -1,7 +1,7 @@
 kop:
   bezeichner: mastere2eea
   environment: dev
-  
+e2eTest: true
 goofy:
   env:
     overrideSpringProfiles: "oc,ea,e2e,dev"
diff --git a/goofy-client/apps/goofy-e2e/src/fixtures/argocd/by-main-dev.yaml b/goofy-client/apps/goofy-e2e/src/fixtures/argocd/by-main-dev.yaml
index 1d34176d07..abb0413e07 100644
--- a/goofy-client/apps/goofy-e2e/src/fixtures/argocd/by-main-dev.yaml
+++ b/goofy-client/apps/goofy-e2e/src/fixtures/argocd/by-main-dev.yaml
@@ -1,7 +1,7 @@
 kop:
   bezeichner: mastere2emain
   environment: dev
-
+e2eTest: true
 goofy:
   env:
     overrideSpringProfiles: "oc,e2e,dev"
-- 
GitLab