add token for plugin

This commit is contained in:
ginuerzh 2023-04-20 19:05:59 +08:00
parent 32c8188351
commit 73b563f0c1
2 changed files with 21 additions and 2 deletions

View File

@ -111,7 +111,8 @@ type TLSConfig struct {
type PluginConfig struct { type PluginConfig struct {
Addr string `json:"addr"` Addr string `json:"addr"`
TLS *TLSConfig `json:"tls"` TLS *TLSConfig `yaml:",omitempty" json:"tls,omitempty"`
Token string `yaml:",omitempty" json:"token,omitempty"`
} }
type AutherConfig struct { type AutherConfig struct {

View File

@ -1,6 +1,7 @@
package parsing package parsing
import ( import (
"context"
"crypto/tls" "crypto/tls"
"net" "net"
"net/url" "net/url"
@ -691,5 +692,22 @@ func newPluginConn(cfg *config.PluginConfig) (*grpc.ClientConn, error) {
} else { } else {
grpcOpts = append(grpcOpts, grpc.WithTransportCredentials(insecure.NewCredentials())) grpcOpts = append(grpcOpts, grpc.WithTransportCredentials(insecure.NewCredentials()))
} }
if cfg.Token != "" {
grpcOpts = append(grpcOpts, grpc.WithPerRPCCredentials(&rpcCredentials{token: cfg.Token}))
}
return grpc.Dial(cfg.Addr, grpcOpts...) return grpc.Dial(cfg.Addr, grpcOpts...)
} }
type rpcCredentials struct {
token string
}
func (c *rpcCredentials) GetRequestMetadata(ctx context.Context, uri ...string) (map[string]string, error) {
return map[string]string{
"token": c.token,
}, nil
}
func (c *rpcCredentials) RequireTransportSecurity() bool {
return false
}