Skip to content

Commit 8723264

Browse files
authored
Get postgresw sslmode from appbinding clientconfig url (#1322) (#1326)
Signed-off-by: souravbiswassanto <saurov@appscode.com>
1 parent 0540f53 commit 8723264

File tree

1 file changed

+21
-8
lines changed

1 file changed

+21
-8
lines changed

pkg/util.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package pkg
1919
import (
2020
"context"
2121
"fmt"
22+
"net/url"
2223
"os"
2324
"path/filepath"
2425
"strings"
@@ -203,14 +204,26 @@ func (session *sessionWrapper) waitForDBReady(waitTimeout int32) error {
203204
}
204205

205206
func getSSLMODE(appBinding *v1alpha1.AppBinding) (string, error) {
206-
sslmodeString := appBinding.Spec.ClientConfig.Service.Query
207-
if sslmodeString == "" {
208-
return "", nil
209-
}
210-
temps := strings.Split(sslmodeString, "=")
211-
if len(temps) != 2 {
212-
return "", fmt.Errorf("the sslmode is not valid. please provide the valid template. the temlpate should be like this: sslmode=<your_desire_sslmode>")
207+
if appBinding.Spec.ClientConfig.Service != nil {
208+
sslmodeString := appBinding.Spec.ClientConfig.Service.Query
209+
if sslmodeString == "" {
210+
return "", nil
211+
}
212+
temps := strings.Split(sslmodeString, "=")
213+
if len(temps) != 2 {
214+
return "", fmt.Errorf("the sslmode is not valid. please provide the valid template. the temlpate should be like this: sslmode=<your_desire_sslmode>")
215+
}
216+
return strings.TrimSpace(temps[1]), nil
217+
} else if appBinding.Spec.ClientConfig.URL != nil {
218+
parsedURL, err := url.Parse(*appBinding.Spec.ClientConfig.URL)
219+
if err != nil {
220+
return "", err
221+
}
222+
queryParams := parsedURL.Query()
223+
sslmode := queryParams.Get("sslmode")
224+
klog.Infoln("SSLMODE: ", sslmode)
225+
return sslmode, nil
213226
}
214227

215-
return strings.TrimSpace(temps[1]), nil
228+
return "", nil
216229
}

0 commit comments

Comments
 (0)