From c4ace0d3e40057942c2fee69e89b0b08cf88a0f6 Mon Sep 17 00:00:00 2001 From: lgtm <1gtm@users.noreply.github.com> Date: Fri, 23 Aug 2024 03:39:48 -0700 Subject: [PATCH] Get postgresw sslmode from appbinding clientconfig url (#1322) (#1330) Signed-off-by: souravbiswassanto --- pkg/util.go | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/pkg/util.go b/pkg/util.go index 90d3ecdfe..3887b01a5 100644 --- a/pkg/util.go +++ b/pkg/util.go @@ -19,6 +19,7 @@ package pkg import ( "context" "fmt" + "net/url" "os" "path/filepath" "strings" @@ -203,14 +204,26 @@ func (session *sessionWrapper) waitForDBReady(waitTimeout int32) error { } func getSSLMODE(appBinding *v1alpha1.AppBinding) (string, error) { - sslmodeString := appBinding.Spec.ClientConfig.Service.Query - if sslmodeString == "" { - return "", nil - } - temps := strings.Split(sslmodeString, "=") - if len(temps) != 2 { - return "", fmt.Errorf("the sslmode is not valid. please provide the valid template. the temlpate should be like this: sslmode=") + if appBinding.Spec.ClientConfig.Service != nil { + sslmodeString := appBinding.Spec.ClientConfig.Service.Query + if sslmodeString == "" { + return "", nil + } + temps := strings.Split(sslmodeString, "=") + if len(temps) != 2 { + return "", fmt.Errorf("the sslmode is not valid. please provide the valid template. the temlpate should be like this: sslmode=") + } + return strings.TrimSpace(temps[1]), nil + } else if appBinding.Spec.ClientConfig.URL != nil { + parsedURL, err := url.Parse(*appBinding.Spec.ClientConfig.URL) + if err != nil { + return "", err + } + queryParams := parsedURL.Query() + sslmode := queryParams.Get("sslmode") + klog.Infoln("SSLMODE: ", sslmode) + return sslmode, nil } - return strings.TrimSpace(temps[1]), nil + return "", nil }