add token for plugin
This commit is contained in:
parent
32c8188351
commit
73b563f0c1
@ -110,8 +110,9 @@ 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 {
|
||||||
|
@ -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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user