From 2a7329e4c16688a67002e3f11652d10ecf0ae011 Mon Sep 17 00:00:00 2001
From: Francisco Barros <francisco.borges.aurindo.barros@cern.ch>
Date: Mon, 20 Feb 2023 12:20:39 +0100
Subject: [PATCH] Updating ConsoleLinks related to SSO/Portal

---
 .../projectlifecyclepolicy_controller.go      |  9 +++++-
 main.go                                       | 30 ++++++++++---------
 2 files changed, 24 insertions(+), 15 deletions(-)

diff --git a/controllers/projectlifecyclepolicy_controller.go b/controllers/projectlifecyclepolicy_controller.go
index 3162d025..dd7685bb 100644
--- a/controllers/projectlifecyclepolicy_controller.go
+++ b/controllers/projectlifecyclepolicy_controller.go
@@ -19,6 +19,8 @@ package controllers
 import (
 	"context"
 	"fmt"
+	"os"
+	"path"
 	"time"
 
 	"github.com/go-logr/logr"
@@ -87,6 +89,8 @@ type ProjectLifecyclePolicyReconciler struct {
 	// The text to show in the NamespaceDashboard ConsoleLink providing info about the current application category
 	// in the Application Portal when category is Official
 	ApplicationCategoryOfficialLinkText string
+	// The link to the Webservices Portal
+	WebservicesPortalLink string
 }
 
 // +kubebuilder:rbac:groups=webservices.cern.ch,resources=projectlifecyclepolicies,verbs=get;list;watch;create;update;patch;delete
@@ -243,8 +247,11 @@ func (r *ProjectLifecyclePolicyReconciler) Reconcile(ctx context.Context, req ct
 		// Undefined or empty string
 		categoryLinkText = r.ApplicationCategoryUndefinedLinkText
 	}
+	// Generate the Link for the specific application in the webservices portal
+	// The current format is {WebservicesPortalLink}/{Cluster_name}/{ApplicationName}
+	webservicesPortalLinkOfApplication := r.WebservicesPortalLink + path.Join(os.Getenv("CLUSTER_NAME"), policy.Namespace)
 	if err := r.ensureConsoleLink(*policy, policy.Namespace+"-category-management",
-		categoryLinkText, appManagementUrl, policy.Spec.ApplicationCategoryLink); err != nil {
+		categoryLinkText, webservicesPortalLinkOfApplication, policy.Spec.ApplicationCategoryLink); err != nil {
 		r.logErrorAndSetFailedStatus(ctx, log, policy, err, "Failed to set ConsoleLink for category management")
 		return ctrl.Result{}, err
 	}
diff --git a/main.go b/main.go
index b910b694..8228f756 100644
--- a/main.go
+++ b/main.go
@@ -46,6 +46,15 @@ import (
 var (
 	scheme   = runtime.NewScheme()
 	setupLog = ctrl.Log.WithName("setup")
+	// Settings for the Application Portal management link generated by the PojectLifecyclePolicy controller.
+	// These are set globally because it is likely that if they change, we should update all existing links.
+	applicationPortalBaseUrl             = ""
+	applicationPortalLinkText            = ""
+	applicationCategoryUndefinedLinkText = ""
+	applicationCategoryTestLinkText      = ""
+	applicationCategoryPersonalLinkText  = ""
+	applicationCategoryOfficialLinkText  = ""
+	webservicesPortalLink                = "https://webservices-portal.web.cern.ch/"
 )
 
 func init() {
@@ -64,14 +73,6 @@ func main() {
 	metricsAddr := ""
 	healthAddr := ""
 	namespace := ""
-	// Settings for the Application Portal management link generated by the PojectLifecyclePolicy controller.
-	// These are set globally because it is likely that if they change, we should update all existing links.
-	applicationPortalBaseUrl := ""
-	applicationPortalLinkText := ""
-	applicationCategoryUndefinedLinkText := ""
-	applicationCategoryTestLinkText := ""
-	applicationCategoryPersonalLinkText := ""
-	applicationCategoryOfficialLinkText := ""
 
 	flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
 	flag.StringVar(&healthAddr, "health-addr", ":8081", "The address the healthz endpoint binds to.")
@@ -85,23 +86,23 @@ func main() {
 		"Base URL to generate a link to manage an application in the Application Portal. "+
 			"The application ID will be appended to the base URL to generate to full URL.")
 	flag.StringVar(&applicationPortalLinkText, "application-portal-link-text",
-		"Manage roles and ownership for this application",
+		"Configure SSO roles for users of this application",
 		"The text to show in the NamespaceDashboard ConsoleLink providing the general-purpose link from the OKD console "+
 			"to the application's management page in the Application Portal.")
 	flag.StringVar(&applicationCategoryUndefinedLinkText, "application-category-undefined-link-text",
-		"This application's category is UNDEFINED - click here to set category",
-		"The text to show in the NamespaceDashboard ConsoleLink providing info about the current application category "+
+		"Manage application owner, administrators and category in the Web Services Portal (this application's category is UNDEFINED - click here to set category)",
+		"The text to show in the NamespaceDashboard Consotest-fborgesa-creationreg4-category-managementleLink providing info about the current application category "+
 			"in the Application Portal when category is Undefined")
 	flag.StringVar(&applicationCategoryTestLinkText, "application-category-test-link-text",
-		"This application's category is TEST: it will be DELETED when owner leaves - click here to change",
+		"Manage application owner, administrators and category in the Web Services Portal (this application's category is TEST: it will be DELETED when owner leaves)",
 		"The text to show in the NamespaceDashboard ConsoleLink providing info about the current application category "+
 			"in the Application Portal when category is Test")
 	flag.StringVar(&applicationCategoryPersonalLinkText, "application-category-personal-link-text",
-		"This application's category is PERSONAL: it will be DELETED when owner leaves - click here to change",
+		"Manage application owner, administrators and category in the Web Services Portal (this application's category is PERSONAL: it will be DELETED when owner leaves)",
 		"The text to show in the NamespaceDashboard ConsoleLink providing info about the current application category "+
 			"in the Application Portal when category is Personal")
 	flag.StringVar(&applicationCategoryOfficialLinkText, "application-category-official-link-text",
-		"This application's category is OFFICIAL: it will be REASSIGNED when owner leaves - click here to change",
+		"Manage application owner, administrators and category in the Web Services Portal (this application's category is OFFICIAL: it will be REASSIGNED when owner leaves)",
 		"The text to show in the NamespaceDashboard ConsoleLink providing info about the current application category "+
 			"in the Application Portal when category is Official")
 
@@ -206,6 +207,7 @@ func main() {
 		ApplicationCategoryTestLinkText:      applicationCategoryTestLinkText,
 		ApplicationCategoryPersonalLinkText:  applicationCategoryPersonalLinkText,
 		ApplicationCategoryOfficialLinkText:  applicationCategoryOfficialLinkText,
+		WebservicesPortalLink:                webservicesPortalLink,
 	}).SetupWithManager(mgr); err != nil {
 		setupLog.Error(err, "unable to create controller", "controller", "ProjectLifecyclePolicy")
 		os.Exit(1)
-- 
GitLab