mirror of https://code.forgejo.org/forgejo/runner
chore(runner): add runner uuid in http header.
Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>pull/2/head
parent
a503f7429f
commit
bf5e3dc302
|
@ -7,6 +7,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"gitea.com/gitea/act_runner/core"
|
||||||
"gitea.com/gitea/proto-go/ping/v1/pingv1connect"
|
"gitea.com/gitea/proto-go/ping/v1/pingv1connect"
|
||||||
"gitea.com/gitea/proto-go/runner/v1/runnerv1connect"
|
"gitea.com/gitea/proto-go/runner/v1/runnerv1connect"
|
||||||
|
|
||||||
|
@ -26,7 +27,7 @@ func New(endpoint, secret string, opts ...Option) *HTTPClient {
|
||||||
|
|
||||||
interceptor := connect.UnaryInterceptorFunc(func(next connect.UnaryFunc) connect.UnaryFunc {
|
interceptor := connect.UnaryInterceptorFunc(func(next connect.UnaryFunc) connect.UnaryFunc {
|
||||||
return func(ctx context.Context, req connect.AnyRequest) (connect.AnyResponse, error) {
|
return func(ctx context.Context, req connect.AnyRequest) (connect.AnyResponse, error) {
|
||||||
req.Header().Set("X-Runner-Token", secret)
|
req.Header().Set(core.UUIDHeader, secret)
|
||||||
return next(ctx, req)
|
return next(ctx, req)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,10 +1,14 @@
|
||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
|
||||||
|
"gitea.com/gitea/act_runner/core"
|
||||||
|
"github.com/appleboy/com/file"
|
||||||
"github.com/joho/godotenv"
|
"github.com/joho/godotenv"
|
||||||
"github.com/kelseyhightower/envconfig"
|
"github.com/kelseyhightower/envconfig"
|
||||||
)
|
)
|
||||||
|
@ -52,7 +56,19 @@ func FromEnviron() (Config, error) {
|
||||||
return cfg, err
|
return cfg, err
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg.Client.Secret = cfg.Runner.Token
|
// check runner config exist
|
||||||
|
if file.IsFile(cfg.Runner.File) {
|
||||||
|
jsonFile, _ := os.Open(cfg.Runner.File)
|
||||||
|
defer jsonFile.Close()
|
||||||
|
byteValue, _ := io.ReadAll(jsonFile)
|
||||||
|
var runner core.Runner
|
||||||
|
if err := json.Unmarshal(byteValue, &runner); err != nil {
|
||||||
|
return cfg, err
|
||||||
|
}
|
||||||
|
if runner.UUID != "" {
|
||||||
|
cfg.Client.Secret = runner.UUID
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// runner config
|
// runner config
|
||||||
if cfg.Runner.Environ == nil {
|
if cfg.Runner.Environ == nil {
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package core
|
package core
|
||||||
|
|
||||||
|
const UUIDHeader = "x-runner-uuid"
|
||||||
|
|
||||||
// Runner struct
|
// Runner struct
|
||||||
type Runner struct {
|
type Runner struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
|
|
Loading…
Reference in New Issue