From 644335a5dc06c2e7e3dddb05b64d70c993ba7af6 Mon Sep 17 00:00:00 2001 From: chuntaojun Date: Mon, 18 Dec 2023 22:19:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=8E=B7=E5=8F=96=E6=A0=87=E7=AD=BE=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api.go | 9 +++++++-- api_config.go | 7 ++++++- pkg/flow/configuration/model.go | 9 +++++++++ pkg/model/config.go | 2 ++ pkg/plugin/configconnector/config_file.go | 8 ++++++++ 5 files changed, 32 insertions(+), 3 deletions(-) diff --git a/api.go b/api.go index 5ca082b0..ed3fd98f 100644 --- a/api.go +++ b/api.go @@ -131,14 +131,19 @@ func NewQuotaRequest() QuotaRequest { return &model.QuotaRequestImpl{} } +type GetConfigFileRequest api.GetConfigFileRequest + // ConfigFile config type ConfigFile model.ConfigFile // ConfigAPI api for configuration files. type ConfigAPI interface { api.SDKOwner - // GetConfigFile obtaining the configuration file - GetConfigFile(namespace, fileGroup, fileName string) (ConfigFile, error) + // Deprecated: please use FetchConfigFile + // GetConfigFile 获取配置文件 + GetConfigFile(namespace, fileGroup, fileName string) (model.ConfigFile, error) + // FetchConfigFile 获取配置文件 + FetchConfigFile(*GetConfigFileRequest) (model.ConfigFile, error) // CreateConfigFile create configuration file CreateConfigFile(namespace, fileGroup, fileName, content string) error // UpdateConfigFile update configuration file diff --git a/api_config.go b/api_config.go index 101c8237..30d9383f 100644 --- a/api_config.go +++ b/api_config.go @@ -69,10 +69,15 @@ func NewConfigAPIByContext(context api.SDKContext) ConfigAPI { } // GetConfigFile 获取配置文件 -func (c *configAPI) GetConfigFile(namespace, fileGroup, fileName string) (ConfigFile, error) { +func (c *configAPI) GetConfigFile(namespace, fileGroup, fileName string) (model.ConfigFile, error) { return c.rawAPI.GetConfigFile(namespace, fileGroup, fileName) } +// FetchConfigFile . +func (c *configAPI) FetchConfigFile(req *GetConfigFileRequest) (model.ConfigFile, error) { + return c.rawAPI.FetchConfigFile((*api.GetConfigFileRequest)(req)) +} + // CreateConfigFile 创建配置文件 func (c *configAPI) CreateConfigFile(namespace, fileGroup, fileName, content string) error { return c.rawAPI.CreateConfigFile(namespace, fileGroup, fileName, content) diff --git a/pkg/flow/configuration/model.go b/pkg/flow/configuration/model.go index 32b3871d..66a8fc8c 100644 --- a/pkg/flow/configuration/model.go +++ b/pkg/flow/configuration/model.go @@ -49,6 +49,15 @@ func newDefaultConfigFile(metadata model.ConfigFileMetadata, repo *ConfigFileRep return configFile } +// GetLabels 获取标签 +func (c *defaultConfigFile) GetLabels() map[string]string { + remote := c.fileRepo.loadRemoteFile() + if remote == nil { + return map[string]string{} + } + return remote.GetLabels() +} + // GetContent 获取配置文件内容 func (c *defaultConfigFile) GetContent() string { if c.content == NotExistedFileContent { diff --git a/pkg/model/config.go b/pkg/model/config.go index 78f317e4..5faf5392 100644 --- a/pkg/model/config.go +++ b/pkg/model/config.go @@ -79,6 +79,8 @@ type ConfigFileMetadata interface { // ConfigFile 文本类型配置文件对象 type ConfigFile interface { ConfigFileMetadata + // GetLabels 获取配置文件标签 + GetLabels() map[string]string // GetContent 获取配置文件内容 GetContent() string // HasContent 是否有配置内容 diff --git a/pkg/plugin/configconnector/config_file.go b/pkg/plugin/configconnector/config_file.go index 0e726309..905df4fd 100644 --- a/pkg/plugin/configconnector/config_file.go +++ b/pkg/plugin/configconnector/config_file.go @@ -73,6 +73,14 @@ type ConfigFileTag struct { Value string } +func (c *ConfigFile) GetLabels() map[string]string { + ret := make(map[string]string, len(c.Tags)) + for i := range c.Tags { + ret[c.Tags[i].Key] = c.Tags[i].Value + } + return ret +} + // GetNamespace 获取配置文件命名空间 func (c *ConfigFile) GetNamespace() string { return c.Namespace