Skip to content

Commit

Permalink
feat:配置文件支持获取标签信息 (#192)
Browse files Browse the repository at this point in the history
  • Loading branch information
chuntaojun authored Dec 18, 2023
1 parent 0bcd204 commit b7d2762
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 3 deletions.
9 changes: 7 additions & 2 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion api_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions pkg/flow/configuration/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions pkg/model/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ type ConfigFileMetadata interface {
// ConfigFile 文本类型配置文件对象
type ConfigFile interface {
ConfigFileMetadata
// GetLabels 获取配置文件标签
GetLabels() map[string]string
// GetContent 获取配置文件内容
GetContent() string
// HasContent 是否有配置内容
Expand Down
8 changes: 8 additions & 0 deletions pkg/plugin/configconnector/config_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b7d2762

Please sign in to comment.