mirror of https://code.forgejo.org/forgejo/runner
chore(runner): add new token in header
Signed-off-by: Bo-Yi.Wu <appleboy.tw@gmail.com>pull/2/head
parent
2f879c41c4
commit
d178051832
|
@ -77,3 +77,21 @@ func WithUUIDHeader(uuid string) Option {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithTokenHeader add runner token in header
|
||||||
|
func WithTokenHeader(token string) Option {
|
||||||
|
return OptionFunc(func(cfg *config) {
|
||||||
|
if token == "" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
cfg.opts = append(
|
||||||
|
cfg.opts,
|
||||||
|
connect.WithInterceptors(connect.UnaryInterceptorFunc(func(next connect.UnaryFunc) connect.UnaryFunc {
|
||||||
|
return func(ctx context.Context, req connect.AnyRequest) (connect.AnyResponse, error) {
|
||||||
|
req.Header().Set(core.TokenHeader, token)
|
||||||
|
return next(ctx, req)
|
||||||
|
}
|
||||||
|
})),
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
|
@ -82,6 +82,9 @@ func runDaemon(ctx context.Context, envFile string) func(cmd *cobra.Command, arg
|
||||||
if data.UUID != "" {
|
if data.UUID != "" {
|
||||||
cfg.Runner.UUID = data.UUID
|
cfg.Runner.UUID = data.UUID
|
||||||
}
|
}
|
||||||
|
if data.Token != "" {
|
||||||
|
cfg.Runner.Token = data.Token
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to connect to docker daemon
|
// try to connect to docker daemon
|
||||||
|
@ -98,6 +101,7 @@ func runDaemon(ctx context.Context, envFile string) func(cmd *cobra.Command, arg
|
||||||
client.WithGRPC(cfg.Client.GRPC),
|
client.WithGRPC(cfg.Client.GRPC),
|
||||||
client.WithGRPCWeb(cfg.Client.GRPCWeb),
|
client.WithGRPCWeb(cfg.Client.GRPCWeb),
|
||||||
client.WithUUIDHeader(cfg.Runner.UUID),
|
client.WithUUIDHeader(cfg.Runner.UUID),
|
||||||
|
client.WithTokenHeader(cfg.Runner.Token),
|
||||||
)
|
)
|
||||||
|
|
||||||
runner := &runtime.Runner{
|
runner := &runtime.Runner{
|
||||||
|
|
|
@ -69,6 +69,9 @@ func FromEnviron() (Config, error) {
|
||||||
if runner.UUID != "" {
|
if runner.UUID != "" {
|
||||||
cfg.Runner.UUID = runner.UUID
|
cfg.Runner.UUID = runner.UUID
|
||||||
}
|
}
|
||||||
|
if runner.Token != "" {
|
||||||
|
cfg.Runner.Token = runner.Token
|
||||||
|
}
|
||||||
cfg.ForgeInstance = runner.ForgeInstance
|
cfg.ForgeInstance = runner.ForgeInstance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package core
|
package core
|
||||||
|
|
||||||
const UUIDHeader = "x-runner-uuid"
|
const (
|
||||||
|
UUIDHeader = "x-runner-uuid"
|
||||||
|
TokenHeader = "x-runner-token"
|
||||||
|
)
|
||||||
|
|
||||||
// Runner struct
|
// Runner struct
|
||||||
type Runner struct {
|
type Runner struct {
|
||||||
|
|
Loading…
Reference in New Issue