diff --git a/cmd/vela-worker/client.go b/cmd/vela-worker/client.go index 677df2dc..1f225856 100644 --- a/cmd/vela-worker/client.go +++ b/cmd/vela-worker/client.go @@ -11,7 +11,7 @@ import ( ) // helper function to setup the queue from the CLI arguments. -func setupClient(s *Server) (*vela.Client, error) { +func setupClient(s *Server, token string) (*vela.Client, error) { logrus.Debug("creating vela client from worker configuration") // create a new Vela client from the server configuration @@ -21,11 +21,10 @@ func setupClient(s *Server) (*vela.Client, error) { if err != nil { return nil, err } - // set token for authentication with the server // // https://pkg.go.dev/github.com/go-vela/sdk-go/vela?tab=doc#AuthenticationService.SetTokenAuth - vela.Authentication.SetTokenAuth(s.Secret) + vela.Authentication.SetTokenAuth(token) return vela, nil } diff --git a/cmd/vela-worker/exec.go b/cmd/vela-worker/exec.go index 06a60ae8..f1a9cbc5 100644 --- a/cmd/vela-worker/exec.go +++ b/cmd/vela-worker/exec.go @@ -36,6 +36,18 @@ func (w *Worker) exec(index int) error { return nil } + // GET build token from server to setup execBuildClient + bt, _, err := w.VelaClient.Build.GetBuildToken(item.Repo.GetOrg(), item.Repo.GetName(), item.Build.GetNumber()) + if err != nil { + logrus.Errorf("Unable to GetBuildToken: %s", err) + return err + } + // set up build client with build token as auth + execBuildClient, err := setupClient(w.Config.Server, bt.GetToken()) + if err != nil { + return err + } + // create logger with extra metadata // // https://pkg.go.dev/github.com/sirupsen/logrus?tab=doc#WithFields @@ -79,7 +91,7 @@ func (w *Worker) exec(index int) error { LogStreamingTimeout: w.Config.Executor.LogStreamingTimeout, EnforceTrustedRepos: w.Config.Executor.EnforceTrustedRepos, PrivilegedImages: w.Config.Runtime.PrivilegedImages, - Client: w.VelaClient, + Client: execBuildClient, Hostname: w.Config.API.Address.Hostname(), Runtime: w.Runtime, Build: item.Build, diff --git a/cmd/vela-worker/operate.go b/cmd/vela-worker/operate.go index da223970..bbbe2e7a 100644 --- a/cmd/vela-worker/operate.go +++ b/cmd/vela-worker/operate.go @@ -22,8 +22,8 @@ import ( func (w *Worker) operate(ctx context.Context) error { var err error - // setup the client - w.VelaClient, err = setupClient(w.Config.Server) + // setup the vela client with the server + w.VelaClient, err = setupClient(w.Config.Server, w.Config.Server.Secret) if err != nil { return err } diff --git a/cmd/vela-worker/register.go b/cmd/vela-worker/register.go index 8c40d9b2..5de52721 100644 --- a/cmd/vela-worker/register.go +++ b/cmd/vela-worker/register.go @@ -12,7 +12,7 @@ import ( "github.com/sirupsen/logrus" ) -// checkIn is a helper function to to phone home to the server. +// checkIn is a helper function to phone home to the server. func (w *Worker) checkIn(config *library.Worker) error { // check to see if the worker already exists in the database logrus.Infof("retrieving worker %s from the server", config.GetHostname()) diff --git a/go.mod b/go.mod index f19ed253..014042c5 100644 --- a/go.mod +++ b/go.mod @@ -8,9 +8,9 @@ require ( github.com/docker/docker v20.10.22+incompatible github.com/docker/go-units v0.5.0 github.com/gin-gonic/gin v1.8.1 - github.com/go-vela/sdk-go v0.17.0 - github.com/go-vela/server v0.17.0 - github.com/go-vela/types v0.17.0 + github.com/go-vela/sdk-go v0.17.1-0.20230224164256-73b956037d5b + github.com/go-vela/server v0.17.1-0.20230224163114-c4283eb079e8 + github.com/go-vela/types v0.17.1-0.20230223155025-1c8a34f71425 github.com/google/go-cmp v0.5.9 github.com/joho/godotenv v1.4.0 github.com/opencontainers/image-spec v1.0.2 diff --git a/go.sum b/go.sum index cf8834b1..5ddbabaf 100644 --- a/go.sum +++ b/go.sum @@ -152,12 +152,12 @@ github.com/go-playground/validator/v10 v10.10.0/go.mod h1:74x4gJWsvQexRdW8Pn3dXS github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= -github.com/go-vela/sdk-go v0.17.0 h1:vVck8Xm5/co6zrDntG1mdjenT5N0vgDJ30ImFZTUEjY= -github.com/go-vela/sdk-go v0.17.0/go.mod h1:R7oHeYj1ThBREPzqsvevUEBxp8knmOviFbspvuGqZsU= -github.com/go-vela/server v0.17.0 h1:sEJ4a9mus43Qw4E431OYwN8qvYugoA0ZmaU0sFGgESk= -github.com/go-vela/server v0.17.0/go.mod h1:Z8YT/IFJTQ80a63GINRHCaFBTkkkHAL7mDohw4xLbEE= -github.com/go-vela/types v0.17.0 h1:nvKBbNO8BSiLtYPMScT0XWosGqEWX85UKSkkclb2DVA= -github.com/go-vela/types v0.17.0/go.mod h1:6KoRkvXMw9DkAcLdtI7PxPqMlT2Bl0DiigQamLGGjwo= +github.com/go-vela/sdk-go v0.17.1-0.20230224164256-73b956037d5b h1:N/g4kgUFlb36JZBlhuq3ifJE+DTIJTqO21nGXsf+76A= +github.com/go-vela/sdk-go v0.17.1-0.20230224164256-73b956037d5b/go.mod h1:RurQS+lXlmzv4I/QS/qMI1Rqb36tfA+NubekWVRIwXc= +github.com/go-vela/server v0.17.1-0.20230224163114-c4283eb079e8 h1:CUXtUYOu8Jz9IYuTMXivu4GXr8BdQXLAYjFYnDnkndE= +github.com/go-vela/server v0.17.1-0.20230224163114-c4283eb079e8/go.mod h1:WJZQJ2nwSSDuB56LskZ3gEoSWI0IwKRtxaFE8GdTLIc= +github.com/go-vela/types v0.17.1-0.20230223155025-1c8a34f71425 h1:tdjas7NJLWlU2vmETaU36wjbd+zvWPLtznE4uwtnFlw= +github.com/go-vela/types v0.17.1-0.20230223155025-1c8a34f71425/go.mod h1:6KoRkvXMw9DkAcLdtI7PxPqMlT2Bl0DiigQamLGGjwo= github.com/goccy/go-json v0.9.7 h1:IcB+Aqpx/iMHu5Yooh7jEzJk1JZ7Pjtmys2ukPr7EeM= github.com/goccy/go-json v0.9.7/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=