Skip to content

Commit 658995f

Browse files
Get postgresw sslmode from appbinding clientconfig url
Signed-off-by: souravbiswassanto <[email protected]>
1 parent 7572785 commit 658995f

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ BIN_PLATFORMS := $(DOCKER_PLATFORMS)
5858
OS := $(if $(GOOS),$(GOOS),$(shell go env GOOS))
5959
ARCH := $(if $(GOARCH),$(GOARCH),$(shell go env GOARCH))
6060

61-
BASEIMAGE_PROD ?= postgres:15.1-alpine
62-
BASEIMAGE_DBG ?= postgres:15.1
61+
BASEIMAGE_PROD ?= postgres:16.1-alpine
62+
BASEIMAGE_DBG ?= postgres:16.1
6363

6464
IMAGE := $(REGISTRY)/$(BIN)
6565
VERSION_PROD := $(VERSION)

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)