Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cherry-pick] Get postgresw sslmode from appbinding clientconfig url (#1322) #1323

Merged
merged 1 commit into from
Aug 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Loading