@@ -22,11 +22,14 @@ import (
2222 "fmt"
2323
2424 apiconfig "github.com/polarismesh/specification/source/go/api/v1/config_manage"
25+ apimodel "github.com/polarismesh/specification/source/go/api/v1/model"
2526 "go.uber.org/zap"
2627
2728 "github.com/polarismesh/polaris/auth"
2829 "github.com/polarismesh/polaris/cache"
30+ api "github.com/polarismesh/polaris/common/api/v1"
2931 "github.com/polarismesh/polaris/common/model"
32+ "github.com/polarismesh/polaris/common/utils"
3033 "github.com/polarismesh/polaris/namespace"
3134 "github.com/polarismesh/polaris/plugin"
3235 "github.com/polarismesh/polaris/store"
@@ -67,11 +70,36 @@ func TestInitialize(ctx context.Context, config Config, s store.Store, cacheMgn
6770
6871func (s * Server ) TestCheckClientConfigFile (ctx context.Context , files []* apiconfig.ClientConfigFileInfo ,
6972 compartor CompareFunction ) (* apiconfig.ConfigClientResponse , bool ) {
70- return s .checkClientConfigFile (ctx , files , compartor )
73+ if len (files ) == 0 {
74+ return api .NewConfigClientResponse (apimodel .Code_InvalidWatchConfigFileFormat , nil ), false
75+ }
76+ for _ , configFile := range files {
77+ namespace := configFile .GetNamespace ().GetValue ()
78+ group := configFile .GetGroup ().GetValue ()
79+ fileName := configFile .GetFileName ().GetValue ()
80+
81+ if namespace == "" || group == "" || fileName == "" {
82+ return api .NewConfigClientResponseWithInfo (apimodel .Code_BadRequest ,
83+ "namespace & group & fileName can not be empty" ), false
84+ }
85+ // 从缓存中获取最新的配置文件信息
86+ release := s .fileCache .GetActiveRelease (namespace , group , fileName )
87+ if release != nil && compartor (configFile , release ) {
88+ ret := & apiconfig.ClientConfigFileInfo {
89+ Namespace : utils .NewStringValue (namespace ),
90+ Group : utils .NewStringValue (group ),
91+ FileName : utils .NewStringValue (fileName ),
92+ Version : utils .NewUInt64Value (release .Version ),
93+ Md5 : utils .NewStringValue (release .Md5 ),
94+ }
95+ return api .NewConfigClientResponse (apimodel .Code_ExecuteSuccess , ret ), false
96+ }
97+ }
98+ return api .NewConfigClientResponse (apimodel .Code_DataNoChange , nil ), true
7199}
72100
73101func TestCompareByVersion (clientInfo * apiconfig.ClientConfigFileInfo , file * model.ConfigFileRelease ) bool {
74- return CompareByVersion ( clientInfo , file )
102+ return clientInfo . GetVersion (). GetValue () < file . Version
75103}
76104
77105// TestDecryptConfigFile 解密配置文件
0 commit comments