From bddb60af84a0e8b95a251044da228c4190f66746 Mon Sep 17 00:00:00 2001 From: Michal Kralik Date: Thu, 25 Jan 2024 15:57:20 +0100 Subject: [PATCH] EVEREST-778: fix everest URL construction (#270) --- go.mod | 2 +- go.sum | 4 ++-- pkg/everest/client/client.go | 9 +++++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 02e4e5cc..4645646b 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/operator-framework/api v0.20.0 github.com/operator-framework/operator-lifecycle-manager v0.26.0 github.com/percona/everest-operator v0.6.0-dev1.0.20240119104008-aeb868d82769 - github.com/percona/percona-everest-backend v0.5.1-0.20240123094558-a63eea5787bb + github.com/percona/percona-everest-backend v0.5.1-0.20240123134200-9c8e5d2d31d2 github.com/spf13/cobra v1.8.0 github.com/spf13/viper v1.18.1 github.com/stretchr/testify v1.8.4 diff --git a/go.sum b/go.sum index ee70a5cc..2be4f08a 100644 --- a/go.sum +++ b/go.sum @@ -543,8 +543,8 @@ github.com/percona/everest-operator v0.6.0-dev1.0.20240119104008-aeb868d82769 h1 github.com/percona/everest-operator v0.6.0-dev1.0.20240119104008-aeb868d82769/go.mod h1:o84NcJlAImYMpKK9+PIjS4V8SSREt1uZOqNhHt5qXMg= github.com/percona/percona-backup-mongodb v1.8.1-0.20230920143330-3b1c2e263901 h1:BDgsZRCjEuxl2/z4yWBqB0s8d20shuIDks7/RVdZiLs= github.com/percona/percona-backup-mongodb v1.8.1-0.20230920143330-3b1c2e263901/go.mod h1:fZRCMpUqkWlLVdRKqqaj001LoVP2eo6F0ZhoMPeXDng= -github.com/percona/percona-everest-backend v0.5.1-0.20240123094558-a63eea5787bb h1:PMkyTQoiMN2Tg7DeyfTYTOAe5wrZwNeHLfwt4h2p8Og= -github.com/percona/percona-everest-backend v0.5.1-0.20240123094558-a63eea5787bb/go.mod h1:10coAH1cUBk0Z3tHbYNTtN362I0i5VsHQxkwacZBaQA= +github.com/percona/percona-everest-backend v0.5.1-0.20240123134200-9c8e5d2d31d2 h1:EVXrbcJ1g+Ye5qyph1unuXsWYSeSU9WujYMk/rmmkIc= +github.com/percona/percona-everest-backend v0.5.1-0.20240123134200-9c8e5d2d31d2/go.mod h1:10coAH1cUBk0Z3tHbYNTtN362I0i5VsHQxkwacZBaQA= github.com/percona/percona-postgresql-operator v0.0.0-20231220140959-ad5eef722609 h1:+UOK4gcHrRgqjo4smgfwT7/0apF6PhAJdQIdAV4ub/M= github.com/percona/percona-postgresql-operator v0.0.0-20231220140959-ad5eef722609/go.mod h1:znzhtSTF6moUOGNPzVpgfFEMaqIe/ijTSHY8BNDkiEA= github.com/percona/percona-server-mongodb-operator v1.15.0 h1:pcP9GMi9f05VFi8e/TQifBrR+cvOkYMiv1xAftkESBs= diff --git a/pkg/everest/client/client.go b/pkg/everest/client/client.go index fdca4bd9..d77a9bee 100644 --- a/pkg/everest/client/client.go +++ b/pkg/everest/client/client.go @@ -23,6 +23,7 @@ import ( "fmt" "io" "net/http" + "net/url" "github.com/percona/percona-everest-backend/client" ) @@ -43,9 +44,13 @@ func NewEverest(everestClient *client.Client) *Everest { } // NewEverestFromURL returns a new Everest from a provided URL. -func NewEverestFromURL(url, everestPwd string) (*Everest, error) { +func NewEverestFromURL(rawURL, everestPwd string) (*Everest, error) { + u, err := url.Parse(rawURL) + if err != nil { + return nil, errors.Join(err, errors.New("could not parse Everest URL")) + } everestCl, err := client.NewClient( - fmt.Sprintf("%s/v1", url), + u.JoinPath("v1").String(), client.WithRequestEditorFn(func(ctx context.Context, req *http.Request) error { req.Header.Set("Cookie", fmt.Sprintf("everest_token=%s", everestPwd)) return nil