Skip to content

Commit

Permalink
fix:修复配置中心客户端鉴权接口设置 (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
chuntaojun authored Mar 27, 2024
1 parent 60ecfda commit d62971e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 10 deletions.
20 changes: 14 additions & 6 deletions plugin/configconnector/polaris/config_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type Connector struct {
valueCtx model.ValueContext
// 有没有打印过connManager ready的信息,用于避免重复打印
hasPrintedReady uint32
token string
}

// Type 插件类型.
Expand All @@ -77,6 +78,7 @@ func (c *Connector) Init(ctx *plugin.InitContext) error {
if cfgValue != nil {
c.cfg = cfgValue.(*networkConfig)
}
c.token = ctx.Config.GetConfigFile().GetConfigConnectorConfig().GetToken()
connManager, err := network.NewConfigConnectionManager(ctx.Config, ctx.ValueCtx)
if err != nil {
return model.NewSDKError(model.ErrCodeAPIInvalidConfig, err, "fail to create config connectionManager")
Expand Down Expand Up @@ -121,7 +123,8 @@ func (c *Connector) GetConfigFile(configFile *configconnector.ConfigFile) (*conf
defer conn.Release(opKey)
configClient := config_manage.NewPolarisConfigGRPCClient(network.ToGRPCConn(conn.Conn))
reqID := connector.NextRegisterInstanceReqID()
ctx, cancel := connector.CreateHeadersContext(0, connector.AppendHeaderWithReqId(reqID))
ctx, cancel := connector.CreateHeadersContext(0, connector.AppendAuthHeader(c.token),
connector.AppendHeaderWithReqId(reqID))
if cancel != nil {
defer cancel()
}
Expand Down Expand Up @@ -153,7 +156,8 @@ func (c *Connector) WatchConfigFiles(configFileList []*configconnector.ConfigFil
defer conn.Release(opKey)
configClient := config_manage.NewPolarisConfigGRPCClient(network.ToGRPCConn(conn.Conn))
reqID := connector.NextWatchConfigFilesReqID()
ctx, cancel := connector.CreateHeadersContext(0, connector.AppendHeaderWithReqId(reqID))
ctx, cancel := connector.CreateHeadersContext(0, connector.AppendAuthHeader(c.token),
connector.AppendHeaderWithReqId(reqID))
if cancel != nil {
defer cancel()
}
Expand Down Expand Up @@ -190,7 +194,8 @@ func (c *Connector) CreateConfigFile(configFile *configconnector.ConfigFile) (*c
defer conn.Release(opKey)
configClient := config_manage.NewPolarisConfigGRPCClient(network.ToGRPCConn(conn.Conn))
reqID := connector.NextCreateConfigFileReqID()
ctx, cancel := connector.CreateHeadersContext(0, connector.AppendHeaderWithReqId(reqID))
ctx, cancel := connector.CreateHeadersContext(0, connector.AppendAuthHeader(c.token),
connector.AppendHeaderWithReqId(reqID))
if cancel != nil {
defer cancel()
}
Expand Down Expand Up @@ -222,7 +227,8 @@ func (c *Connector) UpdateConfigFile(configFile *configconnector.ConfigFile) (*c
defer conn.Release(opKey)
configClient := config_manage.NewPolarisConfigGRPCClient(network.ToGRPCConn(conn.Conn))
reqID := connector.NextUpdateConfigFileReqID()
ctx, cancel := connector.CreateHeadersContext(0, connector.AppendHeaderWithReqId(reqID))
ctx, cancel := connector.CreateHeadersContext(0, connector.AppendAuthHeader(c.token),
connector.AppendHeaderWithReqId(reqID))
if cancel != nil {
defer cancel()
}
Expand Down Expand Up @@ -254,7 +260,8 @@ func (c *Connector) PublishConfigFile(configFile *configconnector.ConfigFile) (*
defer conn.Release(opKey)
configClient := config_manage.NewPolarisConfigGRPCClient(network.ToGRPCConn(conn.Conn))
reqID := connector.NextPublishConfigFileReqID()
ctx, cancel := connector.CreateHeadersContext(0, connector.AppendHeaderWithReqId(reqID))
ctx, cancel := connector.CreateHeadersContext(0, connector.AppendAuthHeader(c.token),
connector.AppendHeaderWithReqId(reqID))
if cancel != nil {
defer cancel()
}
Expand Down Expand Up @@ -283,7 +290,8 @@ func (c *Connector) GetConfigGroup(req *configconnector.ConfigGroup) (*configcon
}

reqID := connector.NextPublishConfigFileReqID()
ctx, cancel := connector.CreateHeadersContext(0, connector.AppendHeaderWithReqId(reqID))
ctx, cancel := connector.CreateHeadersContext(0, connector.AppendAuthHeader(c.token),
connector.AppendHeaderWithReqId(reqID))
if cancel != nil {
defer cancel()
}
Expand Down
2 changes: 2 additions & 0 deletions plugin/serverconnector/grpc/operation_async.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type Connector struct {
discoverConnector *connector.DiscoverConnector
// 有没有打印过connManager ready的信息,用于避免重复打印
hasPrintedReady uint32
token string
}

// Type 插件类型
Expand All @@ -72,6 +73,7 @@ func (g *Connector) Init(ctx *plugin.InitContext) error {
if cfgValue != nil {
g.cfg = cfgValue.(*networkConfig)
}
g.token = ctx.Config.GetGlobal().GetServerConnector().GetToken()
g.connManager = ctx.ConnManager
g.connectionIdleTimeout = ctx.Config.GetGlobal().GetServerConnector().GetConnectionIdleTimeout()
g.valueCtx = ctx.ValueCtx
Expand Down
16 changes: 12 additions & 4 deletions plugin/serverconnector/grpc/operation_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ func (g *Connector) RegisterInstance(req *model.InstanceRegisterRequest, header
var (
namingClient = apiservice.NewPolarisGRPCClient(network.ToGRPCConn(conn.Conn))
reqID = connector.NextRegisterInstanceReqID()
ctx, cancel = connector.CreateHeadersContext(*req.Timeout, connector.AppendHeaderWithReqId(reqID))
ctx, cancel = connector.CreateHeadersContext(*req.Timeout,
connector.AppendAuthHeader(g.token),
connector.AppendHeaderWithReqId(reqID))
)

if cancel != nil {
Expand Down Expand Up @@ -120,7 +122,9 @@ func (g *Connector) DeregisterInstance(req *model.InstanceDeRegisterRequest) err
var (
namingClient = apiservice.NewPolarisGRPCClient(network.ToGRPCConn(conn.Conn))
reqID = connector.NextDeRegisterInstanceReqID()
ctx, cancel = connector.CreateHeadersContext(*req.Timeout, connector.AppendHeaderWithReqId(reqID))
ctx, cancel = connector.CreateHeadersContext(*req.Timeout,
connector.AppendAuthHeader(g.token),
connector.AppendHeaderWithReqId(reqID))
)
if cancel != nil {
defer cancel()
Expand Down Expand Up @@ -181,7 +185,9 @@ func (g *Connector) Heartbeat(req *model.InstanceHeartbeatRequest) error {
var (
namingClient = apiservice.NewPolarisGRPCClient(network.ToGRPCConn(conn.Conn))
reqID = connector.NextHeartbeatReqID()
ctx, cancel = connector.CreateHeadersContext(*req.Timeout, connector.AppendHeaderWithReqId(reqID))
ctx, cancel = connector.CreateHeadersContext(*req.Timeout,
connector.AppendAuthHeader(g.token),
connector.AppendHeaderWithReqId(reqID))
)
if cancel != nil {
defer cancel()
Expand Down Expand Up @@ -269,7 +275,9 @@ func (g *Connector) ReportClient(req *model.ReportClientRequest) (*model.ReportC
var (
namingClient = apiservice.NewPolarisGRPCClient(network.ToGRPCConn(conn.Conn))
reqID = connector.NextReportClientReqID()
ctx, cancel = connector.CreateHeadersContext(req.Timeout, connector.AppendHeaderWithReqId(reqID))
ctx, cancel = connector.CreateHeadersContext(req.Timeout,
connector.AppendAuthHeader(g.token),
connector.AppendHeaderWithReqId(reqID))
)
if cancel != nil {
defer cancel()
Expand Down

0 comments on commit d62971e

Please sign in to comment.