diff --git a/common/nacos_server/nacos_server.go b/common/nacos_server/nacos_server.go index 75e230c9..fcd3c995 100644 --- a/common/nacos_server/nacos_server.go +++ b/common/nacos_server/nacos_server.go @@ -92,13 +92,13 @@ func NewNacosServer(ctx context.Context, serverList []constant.ServerConfig, cli ns.initRefreshSrvIfNeed(ctx) } - _, err := securityLogin.Login() + _, err := ns.securityLogin.Login() if err != nil { logger.Errorf("login in err:%v", err) } - securityLogin.AutoRefresh(ctx) + ns.securityLogin.AutoRefresh(ctx) return &ns, nil } @@ -344,6 +344,7 @@ func (server *NacosServer) refreshServerSrvIfNeed(urlString string, header map[s server.ServerSrcChangeSignal <- struct{}{} } server.lastSrvRefTime = util.CurrentMillis() + server.securityLogin.UpdateServerList(servers) server.Unlock() } diff --git a/common/nacos_server/nacos_server_test.go b/common/nacos_server/nacos_server_test.go index f35f6b3a..9d541428 100644 --- a/common/nacos_server/nacos_server_test.go +++ b/common/nacos_server/nacos_server_test.go @@ -156,3 +156,27 @@ func TestNacosServer_InjectSignForNamingHttp_WithoutServiceNameAndGroup(t *testi _, has := param["signature"] assert.True(t, has) } + +func TestNacosServer_UpdateServerListForSecurityLogin(t *testing.T) { + endpoint := "console.nacos.io:80" + clientConfig := constant.ClientConfig{ + Username: "nacos", + Password: "nacos", + NamespaceId: "namespace_1", + Endpoint: endpoint, + EndpointContextPath: "nacos", + ClusterName: "serverlist", + AppendToStdout: true, + } + server, err := NewNacosServer(context.Background(), + nil, + clientConfig, + &http_agent.HttpAgent{}, + 1000, + endpoint, + nil) + if err != nil { + t.FailNow() + } + assert.Equal(t, server.GetServerList(), server.securityLogin.GetServerList()) +} diff --git a/common/security/security_proxy.go b/common/security/security_proxy.go index eb6d5793..c1755256 100644 --- a/common/security/security_proxy.go +++ b/common/security/security_proxy.go @@ -112,6 +112,14 @@ func (ac *AuthClient) Login() (bool, error) { return false, throwable } +func (ac *AuthClient) UpdateServerList(serverList []constant.ServerConfig) { + ac.serverCfgs = serverList +} + +func (ac *AuthClient) GetServerList() []constant.ServerConfig { + return ac.serverCfgs +} + func (ac *AuthClient) login(server constant.ServerConfig) (bool, error) { if ac.username != "" { contextPath := server.ContextPath