Skip to content

Commit

Permalink
Get postgresw sslmode from appbinding clientconfig url (#1322) (#1324)
Browse files Browse the repository at this point in the history
Signed-off-by: souravbiswassanto <saurov@appscode.com>
  • Loading branch information
1gtm committed Aug 23, 2024
1 parent 719db82 commit 1ffec1f
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions pkg/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package pkg
import (
"context"
"fmt"
"net/url"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -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=<your_desire_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=<your_desire_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
}

0 comments on commit 1ffec1f

Please sign in to comment.