diff --git a/go.mod b/go.mod index 1a1431f..d84bd2d 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/buildkite/yaml v0.0.0-20230306222819-0e4e032d4835 github.com/coreos/go-semver v0.3.1 github.com/gin-gonic/gin v1.9.1 - github.com/go-vela/server v0.23.2 + github.com/go-vela/server v0.23.4-0.20240319161125-1809638e7e72 github.com/go-vela/types v0.23.2 github.com/golang-jwt/jwt/v5 v5.2.1 github.com/google/go-cmp v0.6.0 @@ -29,7 +29,7 @@ require ( github.com/klauspost/cpuid/v2 v2.2.4 // indirect github.com/kr/pretty v0.3.0 // indirect github.com/leodido/go-urn v1.2.4 // indirect - github.com/mattn/go-isatty v0.0.19 // indirect + github.com/mattn/go-isatty v0.0.20 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pelletier/go-toml/v2 v2.0.8 // indirect @@ -41,7 +41,7 @@ require ( golang.org/x/net v0.22.0 // indirect golang.org/x/sys v0.18.0 // indirect golang.org/x/text v0.14.0 // indirect - google.golang.org/protobuf v1.32.0 // indirect + google.golang.org/protobuf v1.33.0 // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index deccf07..49b6e10 100644 --- a/go.sum +++ b/go.sum @@ -30,8 +30,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js= github.com/go-playground/validator/v10 v10.14.0/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= -github.com/go-vela/server v0.23.2 h1:G/JLZPHgokZxthE4PMfiMIZCKdYadoafYEqh/P91ECk= -github.com/go-vela/server v0.23.2/go.mod h1:Iqs8vB35nPcN6GpjmvWwIjBZZ42oKHgOTrGSpz2wvNI= +github.com/go-vela/server v0.23.4-0.20240319161125-1809638e7e72 h1:vREnnFuJCKvnYDzHpo8tnXnjpdWgwJ4u2+XB1aoDZQg= +github.com/go-vela/server v0.23.4-0.20240319161125-1809638e7e72/go.mod h1:uSS5W5UzhNzAsFbKrniwr5OWtq+Q09u/i8H8nr9ls0M= github.com/go-vela/types v0.23.2 h1:QDt2lta7FPEfN2RK/Bn++DkqyjGIB4H/Q4XkFAj3hXQ= github.com/go-vela/types v0.23.2/go.mod h1:aTE6dzssqTGOvU6m2/vsI9NoSW/3hH/yLzf3cCSo0Zk= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= @@ -60,8 +60,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/leodido/go-urn v1.2.4 h1:XlAE/cm/ms7TE/VMVoduSpNBoyc2dOxHs5MZSwAN63Q= github.com/leodido/go-urn v1.2.4/go.mod h1:7ZrI8mTSeBSHl/UaRyKQW1qZeMgak41ANeCNaVckg+4= -github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= -github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= +github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg= github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q= @@ -106,8 +106,8 @@ golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= -google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= +google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= diff --git a/vela/client.go b/vela/client.go index 40eb8fe..ae8b410 100644 --- a/vela/client.go +++ b/vela/client.go @@ -501,6 +501,7 @@ func (c *Client) Do(req *http.Request, respType interface{}) (*Response, error) // ensure response body is not empty so the user may inspect // it further for debugging and troubleshooting resp.Body = io.NopCloser(bytes.NewBuffer(body)) + if err != nil { // if error is present, we still return the response so the caller // may inspect it further for debugging and troubleshooting diff --git a/vela/worker.go b/vela/worker.go index 9985ba1..2350e38 100644 --- a/vela/worker.go +++ b/vela/worker.go @@ -5,6 +5,7 @@ package vela import ( "fmt" + api "github.com/go-vela/server/api/types" "github.com/go-vela/types/library" ) @@ -21,12 +22,12 @@ type WorkerListOptions struct { } // Get returns the provided worker. -func (svc *WorkerService) Get(hostname string) (*library.Worker, *Response, error) { +func (svc *WorkerService) Get(hostname string) (*api.Worker, *Response, error) { // set the API endpoint path we send the request to u := fmt.Sprintf("/api/v1/workers/%s", hostname) - // library Worker type we want to return - v := new(library.Worker) + // api Worker type we want to return + v := new(api.Worker) // send request using client resp, err := svc.client.Call("GET", u, nil, v) @@ -35,7 +36,7 @@ func (svc *WorkerService) Get(hostname string) (*library.Worker, *Response, erro } // GetAll returns a list of all workers. -func (svc *WorkerService) GetAll(opt *WorkerListOptions) (*[]library.Worker, *Response, error) { +func (svc *WorkerService) GetAll(opt *WorkerListOptions) (*[]api.Worker, *Response, error) { // set the API endpoint path we send the request to u := "/api/v1/workers" @@ -46,7 +47,7 @@ func (svc *WorkerService) GetAll(opt *WorkerListOptions) (*[]library.Worker, *Re } // slice library Worker type we want to return - v := new([]library.Worker) + v := new([]api.Worker) // send request using client resp, err := svc.client.Call("GET", u, nil, v) @@ -55,7 +56,7 @@ func (svc *WorkerService) GetAll(opt *WorkerListOptions) (*[]library.Worker, *Re } // Add constructs a worker with the provided details. -func (svc *WorkerService) Add(w *library.Worker) (*library.Token, *Response, error) { +func (svc *WorkerService) Add(w *api.Worker) (*library.Token, *Response, error) { // set the API endpoint path we send the request to u := "/api/v1/workers" @@ -83,12 +84,12 @@ func (svc *WorkerService) RefreshAuth(worker string) (*library.Token, *Response, } // Update modifies a worker with the provided details. -func (svc *WorkerService) Update(worker string, w *library.Worker) (*library.Worker, *Response, error) { +func (svc *WorkerService) Update(worker string, w *api.Worker) (*api.Worker, *Response, error) { // set the API endpoint path we send the request to u := fmt.Sprintf("/api/v1/workers/%s", worker) // library Worker type we want to return - v := new(library.Worker) + v := new(api.Worker) // send request using client resp, err := svc.client.Call("PUT", u, w, v) diff --git a/vela/worker_test.go b/vela/worker_test.go index 82b8624..02cae01 100644 --- a/vela/worker_test.go +++ b/vela/worker_test.go @@ -10,6 +10,7 @@ import ( "reflect" "testing" + api "github.com/go-vela/server/api/types" "github.com/go-vela/server/mock/server" "github.com/go-vela/types/library" @@ -25,7 +26,7 @@ func TestWorker_Get_200(t *testing.T) { data := []byte(server.WorkerResp) - var want library.Worker + var want api.Worker _ = json.Unmarshal(data, &want) // run test @@ -51,7 +52,7 @@ func TestWorker_Get_404(t *testing.T) { s := httptest.NewServer(server.FakeHandler()) c, _ := NewClient(s.URL, "", nil) - want := library.Worker{} + want := api.Worker{} // run test got, resp, err := c.Worker.Get("0") @@ -78,7 +79,7 @@ func TestWorker_GetAll_200(t *testing.T) { data := []byte(server.WorkersResp) - var want []library.Worker + var want []api.Worker _ = json.Unmarshal(data, &want) // run test @@ -109,7 +110,7 @@ func TestWorker_Add_201(t *testing.T) { var want library.Token _ = json.Unmarshal(data, &want) - req := library.Worker{ + req := api.Worker{ ID: Int64(1), Hostname: String("worker_1"), Address: String("http://vela:8080"), @@ -198,10 +199,10 @@ func TestWorker_Update_200(t *testing.T) { data := []byte(server.WorkerResp) - var want library.Worker + var want api.Worker _ = json.Unmarshal(data, &want) - req := library.Worker{ + req := api.Worker{ Active: Bool(true), } @@ -228,9 +229,9 @@ func TestWorker_Update_404(t *testing.T) { s := httptest.NewServer(server.FakeHandler()) c, _ := NewClient(s.URL, "", nil) - want := library.Worker{} + want := api.Worker{} - req := library.Worker{ + req := api.Worker{ Active: Bool(true), } @@ -327,7 +328,7 @@ func ExampleWorkerService_Add() { // Set new token in existing client c.Authentication.SetPersonalAccessTokenAuth("token") - req := library.Worker{ + req := api.Worker{ ID: Int64(1), Hostname: String("worker_1"), Address: String("http://vela:8080"), @@ -374,7 +375,7 @@ func ExampleWorkerService_Update() { // Set new token in existing client c.Authentication.SetPersonalAccessTokenAuth("token") - req := library.Worker{ + req := api.Worker{ Active: Bool(false), }