From c79e49b080ee7cae8192779b477ce6b6f5052780 Mon Sep 17 00:00:00 2001 From: Pierre-Emmanuel Jacquier <15922119+pierre-emmanuelJ@users.noreply.github.com> Date: Wed, 24 Jan 2024 14:09:07 +0000 Subject: [PATCH] Vendor: Update egoscale v3 Signed-off-by: Pierre-Emmanuel Jacquier <15922119+pierre-emmanuelJ@users.noreply.github.com> --- driver/controller.go | 2 +- go.mod | 2 +- go.sum | 4 +-- vendor/github.com/exoscale/egoscale/v3/api.go | 27 +++++++++++++++++-- .../github.com/exoscale/egoscale/v3/client.go | 15 +++++++++++ vendor/modules.txt | 2 +- 6 files changed, 45 insertions(+), 7 deletions(-) diff --git a/driver/controller.go b/driver/controller.go index 54432eac..64d9ab70 100644 --- a/driver/controller.go +++ b/driver/controller.go @@ -164,7 +164,7 @@ func (d *controllerService) CreateVolume(ctx context.Context, req *csi.CreateVol BlockStorageSnapshot: snapshotTarget, } - if err := v3.Validate(request); err != nil { + if err := d.client.Validate(request); err != nil { klog.Errorf("create block storage volume validation: %v", err) return nil, err } diff --git a/go.mod b/go.mod index 25807dab..b39ea64c 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.21 require ( github.com/container-storage-interface/spec v1.8.0 - github.com/exoscale/egoscale v0.102.4-0.20240117105256-1ace995a320f + github.com/exoscale/egoscale v0.102.4-0.20240124100014-b414c838f92a github.com/golang/protobuf v1.5.3 golang.org/x/sys v0.15.0 google.golang.org/grpc v1.58.0 diff --git a/go.sum b/go.sum index cc03f8ff..62b5bf89 100644 --- a/go.sum +++ b/go.sum @@ -6,8 +6,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/emicklei/go-restful/v3 v3.9.0 h1:XwGDlfxEnQZzuopoqxwSEllNcCOM9DhhFyhFIIGKwxE= github.com/emicklei/go-restful/v3 v3.9.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc= -github.com/exoscale/egoscale v0.102.4-0.20240117105256-1ace995a320f h1:3Gid+5UXIV7j3hjOnkLbcOgEmlx/GSmdlMEgCvZiWLM= -github.com/exoscale/egoscale v0.102.4-0.20240117105256-1ace995a320f/go.mod h1:RPf2Gah6up+6kAEayHTQwqapzXlm93f0VQas/UEGU5c= +github.com/exoscale/egoscale v0.102.4-0.20240124100014-b414c838f92a h1:6QyDUx529CBX1yFQEUilvMK/ok5j44nJjc/0URKGufU= +github.com/exoscale/egoscale v0.102.4-0.20240124100014-b414c838f92a/go.mod h1:RPf2Gah6up+6kAEayHTQwqapzXlm93f0VQas/UEGU5c= github.com/go-logr/logr v1.2.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= diff --git a/vendor/github.com/exoscale/egoscale/v3/api.go b/vendor/github.com/exoscale/egoscale/v3/api.go index e9ce979e..cbdb31b2 100644 --- a/vendor/github.com/exoscale/egoscale/v3/api.go +++ b/vendor/github.com/exoscale/egoscale/v3/api.go @@ -127,8 +127,31 @@ func Ptr[T any](v T) *T { } // Validate any struct from schema or request -func Validate(r any) error { - return validator.New().Struct(r) +func (c Client) Validate(s any) error { + err := c.validate.Struct(s) + if err == nil { + return nil + } + + // Print better error messages + validationErrors := err.(validator.ValidationErrors) + + if len(validationErrors) > 0 { + e := validationErrors[0] + errorString := fmt.Sprintf( + "Request validation error: '%s' = '%v' does not validate ", + e.StructNamespace(), + e.Value(), + ) + if e.Param() == "" { + errorString += fmt.Sprintf("'%s'", e.ActualTag()) + } else { + errorString += fmt.Sprintf("'%s=%v'", e.ActualTag(), e.Param()) + } + return fmt.Errorf(errorString) + } + + return err } func prepareJSONBody(body any) (*bytes.Reader, error) { diff --git a/vendor/github.com/exoscale/egoscale/v3/client.go b/vendor/github.com/exoscale/egoscale/v3/client.go index c1134ba2..c8126141 100644 --- a/vendor/github.com/exoscale/egoscale/v3/client.go +++ b/vendor/github.com/exoscale/egoscale/v3/client.go @@ -12,6 +12,7 @@ import ( "time" "github.com/exoscale/egoscale/version" + "github.com/go-playground/validator/v10" ) // URL represents a zoned url endpoint. @@ -57,6 +58,7 @@ type Client struct { httpClient *http.Client timeout time.Duration pollingInterval time.Duration + validate *validator.Validate trace bool // A list of callbacks for modifying requests which are generated before sending over @@ -99,6 +101,14 @@ func ClientOptWithTrace() ClientOpt { } } +// ClientOptWithValidator returns a ClientOpt with a given validator. +func ClientOptWithValidator(validate *validator.Validate) ClientOpt { + return func(c *Client) error { + c.validate = validate + return nil + } +} + // ClientOptWithURL returns a ClientOpt With a given zone URL. func ClientOptWithURL(url URL) ClientOpt { return func(c *Client) error { @@ -141,6 +151,7 @@ func NewClient(apiKey, apiSecret string, opts ...ClientOpt) (*Client, error) { serverURL: string(CHGva2), httpClient: http.DefaultClient, pollingInterval: pollingInterval, + validate: validator.New(), } for _, opt := range opts { @@ -161,6 +172,7 @@ func (c *Client) WithURL(url URL) *Client { httpClient: c.httpClient, requestInterceptors: c.requestInterceptors, pollingInterval: c.pollingInterval, + validate: c.validate, } } @@ -174,6 +186,7 @@ func (c *Client) WithTrace() *Client { requestInterceptors: c.requestInterceptors, pollingInterval: c.pollingInterval, trace: true, + validate: c.validate, } } @@ -186,6 +199,7 @@ func (c *Client) WithHttpClient(client *http.Client) *Client { httpClient: client, requestInterceptors: c.requestInterceptors, pollingInterval: c.pollingInterval, + validate: c.validate, } } @@ -198,6 +212,7 @@ func (c *Client) WithRequestInterceptor(f ...RequestInterceptorFn) *Client { httpClient: c.httpClient, requestInterceptors: append(c.requestInterceptors, f...), pollingInterval: c.pollingInterval, + validate: c.validate, } } diff --git a/vendor/modules.txt b/vendor/modules.txt index 2de17323..de11a14b 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -8,7 +8,7 @@ github.com/davecgh/go-spew/spew ## explicit; go 1.13 github.com/emicklei/go-restful/v3 github.com/emicklei/go-restful/v3/log -# github.com/exoscale/egoscale v0.102.4-0.20240117105256-1ace995a320f +# github.com/exoscale/egoscale v0.102.4-0.20240124100014-b414c838f92a ## explicit; go 1.20 github.com/exoscale/egoscale/v3 github.com/exoscale/egoscale/version