From 3e67dd28c2c64fc36bee83659519e8b1f422ab2f Mon Sep 17 00:00:00 2001 From: chuntaojun Date: Mon, 18 Sep 2023 01:15:37 +0800 Subject: [PATCH] fix:when change file encrypt datakey will panic --- pkg/config/location_provider.go | 8 ++++---- pkg/flow/configuration/config_flow.go | 4 +--- pkg/flow/configuration/local_cache.go | 3 ++- pkg/plugin/configconnector/config_file.go | 1 + 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/config/location_provider.go b/pkg/config/location_provider.go index 0ce66743..725ad73f 100644 --- a/pkg/config/location_provider.go +++ b/pkg/config/location_provider.go @@ -26,22 +26,22 @@ type LocationProviderConfigImpl struct { Options map[string]interface{} `yaml:"options" json:"options"` } -func (l LocationProviderConfigImpl) GetType() string { +func (l *LocationProviderConfigImpl) GetType() string { return l.Type } -func (l LocationProviderConfigImpl) GetOptions() map[string]interface{} { +func (l *LocationProviderConfigImpl) GetOptions() map[string]interface{} { return l.Options } -func (l LocationProviderConfigImpl) Verify() error { +func (l *LocationProviderConfigImpl) Verify() error { if l.Type == "" { return errors.New("type is empty") } return nil } -func (l LocationProviderConfigImpl) SetDefault() { +func (l *LocationProviderConfigImpl) SetDefault() { if len(l.Options) == 0 { l.Options = map[string]interface{}{} } diff --git a/pkg/flow/configuration/config_flow.go b/pkg/flow/configuration/config_flow.go index 3803dbb3..f1a05def 100644 --- a/pkg/flow/configuration/config_flow.go +++ b/pkg/flow/configuration/config_flow.go @@ -52,10 +52,8 @@ type ConfigFileFlow struct { } // NewConfigFileFlow 创建配置中心服务 -func NewConfigFileFlow(connector configconnector.ConfigConnector, - chain configfilter.Chain, +func NewConfigFileFlow(connector configconnector.ConfigConnector, chain configfilter.Chain, configuration config.Configuration) (*ConfigFileFlow, error) { - persistHandler, err := NewCachePersistHandler( configuration.GetConfigFile().GetLocalCache().GetPersistDir(), configuration.GetConfigFile().GetLocalCache().GetPersistMaxWriteRetry(), diff --git a/pkg/flow/configuration/local_cache.go b/pkg/flow/configuration/local_cache.go index 6014a98e..d187bfe4 100644 --- a/pkg/flow/configuration/local_cache.go +++ b/pkg/flow/configuration/local_cache.go @@ -20,6 +20,7 @@ package configuration import ( "encoding/json" "fmt" + "io/ioutil" "os" "path/filepath" "time" @@ -89,7 +90,7 @@ func (cph *CachePersistHandler) loadMessageFromAbsoluteFile(cacheFile string, me var lastErr error var retryTimes int for retryTimes = 0; retryTimes <= maxRetry; retryTimes++ { - cacheJson, err := os.ReadFile(cacheFile) + cacheJson, err := ioutil.ReadFile(cacheFile) if err != nil { lastErr = model.NewSDKError(model.ErrCodeDiskError, err, "fail to read file cache") // 文件打开失败的话,重试没有意义,直接失败 diff --git a/pkg/plugin/configconnector/config_file.go b/pkg/plugin/configconnector/config_file.go index dc70d57b..e2d7ca66 100644 --- a/pkg/plugin/configconnector/config_file.go +++ b/pkg/plugin/configconnector/config_file.go @@ -56,6 +56,7 @@ func (c *ConfigFile) String() string { _, _ = bf.WriteString("file_name=" + c.FileName) _, _ = bf.WriteString("version=" + strconv.FormatUint(c.Version, 10)) _, _ = bf.WriteString("encrypt=" + strconv.FormatBool(c.Encrypted)) + //nolint: errchkjson data, _ := json.Marshal(c.Tags) _, _ = bf.WriteString("tags=" + string(data)) return bf.String()