Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions vela/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
package vela

import (
"fmt"

"github.com/go-vela/types/library"
)

Expand All @@ -20,6 +22,7 @@ type (
Service *AdminSvcService
Step *AdminStepService
User *AdminUserService
Worker *AdminWorkerService
}

// AdminBuildService handles retrieving admin builds from
Expand Down Expand Up @@ -53,6 +56,10 @@ type (
// AdminUserService handles retrieving admin users from
// the server methods of the Vela API.
AdminUserService service

// AdminWorkerService handles managing admin worker functionality
// from the server methods of the Vela API.
AdminWorkerService service
)

// GetQueueOptions specifies the optional parameters to the
Expand Down Expand Up @@ -196,3 +203,17 @@ func (svc *AdminUserService) Update(u *library.User) (*library.User, *Response,

return v, resp, err
}

// RegistrationToken generates a worker registration token with the provided details.
func (svc *AdminUserService) RegistrationToken(w *library.Worker) (*library.Token, *Response, error) {
// set the API endpoint path we send the request to
url := fmt.Sprintf("/api/v1/workers/%s/register-token", w.GetHostname())

// library Token type we want to return
t := new(library.Token)

// send request using client
resp, err := svc.client.Call("POST", url, nil, t)

return t, resp, err
}
10 changes: 10 additions & 0 deletions vela/authentication.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,13 @@ func extractRefreshToken(cookies []*http.Cookie) string {

return c
}

// ValidateToken makes a request to validate tokens with the Vela server.
func (svc *AuthenticationService) ValidateToken() (*Response, error) {
// set the API endpoint path we send the request to
u := "/validate-token"

// attempt to validate a server token
resp, err := svc.client.Call("GET", u, nil, nil)
return resp, err
}
1 change: 1 addition & 0 deletions vela/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ func NewClient(baseURL, id string, httpClient *http.Client) (*Client, error) {
&AdminSvcService{client: c},
&AdminStepService{client: c},
&AdminUserService{client: c},
&AdminWorkerService{client: c},
}
c.Build = &BuildService{client: c}
c.Deployment = &DeploymentService{client: c}
Expand Down
1 change: 1 addition & 0 deletions vela/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func TestVela_NewClient(t *testing.T) {
&AdminSvcService{client: want},
&AdminStepService{client: want},
&AdminUserService{client: want},
&AdminWorkerService{client: want},
}
want.Build = &BuildService{client: want}
want.Deployment = &DeploymentService{client: want}
Expand Down