From 4c2d976629d1c5613e441f8f23f5ef83974c406b Mon Sep 17 00:00:00 2001 From: "Bo-Yi.Wu" Date: Sat, 15 Oct 2022 20:04:39 +0800 Subject: [PATCH] chore(runner): get runner by uuid from header Signed-off-by: Bo-Yi.Wu --- go.mod | 3 ++- go.sum | 6 ++++-- routers/api/bots/runner/unary.go | 5 +++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 1e2cd669a9..bf5f941363 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,8 @@ require ( code.gitea.io/gitea-vet v0.2.2-0.20220122151748-48ebc902541b code.gitea.io/sdk/gitea v0.15.1 codeberg.org/gusted/mcaptcha v0.0.0-20220723083913-4f3072e1d570 - gitea.com/gitea/proto-go v0.0.0-20221013073523-69d53451957a + gitea.com/gitea/act_runner v0.0.0-20221015084035-e63e22e8c81d + gitea.com/gitea/proto-go v0.0.0-20221014123629-9116865c883b gitea.com/go-chi/binding v0.0.0-20220309004920-114340dabecb gitea.com/go-chi/cache v0.2.0 gitea.com/go-chi/captcha v0.0.0-20211013065431-70641c1a35d5 diff --git a/go.sum b/go.sum index 8f79fe488c..b341c59a53 100644 --- a/go.sum +++ b/go.sum @@ -83,8 +83,10 @@ git.sr.ht/~mariusor/go-xsd-duration v0.0.0-20220703122237-02e73435a078 h1:cliQ4H git.sr.ht/~mariusor/go-xsd-duration v0.0.0-20220703122237-02e73435a078/go.mod h1:g/V2Hjas6Z1UHUp4yIx6bATpNzJ7DYtD0FG3+xARWxs= gitea.com/gitea/act v0.0.0-20221012054755-c2c76e19a725 h1:H5lZ5fqSXAZ082wBKfqaME070sw5DeNwT8Bwyfa5mcc= gitea.com/gitea/act v0.0.0-20221012054755-c2c76e19a725/go.mod h1:lpzib6X73FHLSaTqTakan1xcsCAVhlZvPSpLns7jkRo= -gitea.com/gitea/proto-go v0.0.0-20221013073523-69d53451957a h1:WHNPcbDR2vw2a17Ml06+n4MC0UwsyD/F3WeVteaXWMI= -gitea.com/gitea/proto-go v0.0.0-20221013073523-69d53451957a/go.mod h1:hD8YwSHusjwjEEgubW6XFvnZuNhMZTHz6lwjfltEt/Y= +gitea.com/gitea/act_runner v0.0.0-20221015084035-e63e22e8c81d h1:WdZqNKX1TB0vH1nOFZhoYdesEGFwvwpKGkwjGaGCmgo= +gitea.com/gitea/act_runner v0.0.0-20221015084035-e63e22e8c81d/go.mod h1:ZDTf3CZrtttQj0EzduNKPRUBPIrPOK6cdx/LFFVX+EE= +gitea.com/gitea/proto-go v0.0.0-20221014123629-9116865c883b h1:TSz7VRHfnM/5JwGPgIAjSlDIvcr4pTGfuRMtgMxttmg= +gitea.com/gitea/proto-go v0.0.0-20221014123629-9116865c883b/go.mod h1:hD8YwSHusjwjEEgubW6XFvnZuNhMZTHz6lwjfltEt/Y= gitea.com/go-chi/binding v0.0.0-20220309004920-114340dabecb h1:Yy0Bxzc8R2wxiwXoG/rECGplJUSpXqCsog9PuJFgiHs= gitea.com/go-chi/binding v0.0.0-20220309004920-114340dabecb/go.mod h1:77TZu701zMXWJFvB8gvTbQ92zQ3DQq/H7l5wAEjQRKc= gitea.com/go-chi/cache v0.0.0-20210110083709-82c4c9ce2d5e/go.mod h1:k2V/gPDEtXGjjMGuBJiapffAXTv76H4snSmlJRLUhH0= diff --git a/routers/api/bots/runner/unary.go b/routers/api/bots/runner/unary.go index 70e8de98b2..2836641c82 100644 --- a/routers/api/bots/runner/unary.go +++ b/routers/api/bots/runner/unary.go @@ -11,6 +11,7 @@ import ( bots_model "code.gitea.io/gitea/models/bots" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/timeutil" + "gitea.com/gitea/act_runner/core" runnerv1 "gitea.com/gitea/proto-go/runner/v1" "github.com/bufbuild/connect-go" @@ -25,8 +26,8 @@ var WithRunner = connect.WithInterceptors(connect.UnaryInterceptorFunc(func(unar if methodName(request) == "Register" { return unaryFunc(ctx, request) } - token := request.Header().Get("X-Runner-Token") // TODO: shouldn't be X-Runner-Token, maybe X-Runner-UUID - runner, err := bots_model.GetRunnerByToken(token) + uuid := request.Header().Get(core.UUIDHeader) + runner, err := bots_model.GetRunnerByUUID(uuid) if err != nil { if _, ok := err.(bots_model.ErrRunnerNotExist); ok { return nil, status.Error(codes.Unauthenticated, "unregistered runner")