Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:配置文件支持获取标签信息 #192

Merged
merged 5 commits into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
}

// 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 Expand Up @@ -108,7 +113,7 @@
}, nil
}

// NewConfigAPIByConfig 通过配置对象获取配置中心 API

Check warning on line 116 in api_config.go

View workflow job for this annotation

GitHub Actions / Run Revive Action (1.15.x)

comment on exported function NewConfigGroupAPIByConfig should be of the form "NewConfigGroupAPIByConfig ..."
func NewConfigGroupAPIByConfig(cfg config.Configuration) (ConfigGroupAPI, error) {
rawAPI, err := api.NewConfigGroupAPIByConfig(cfg)
if err != nil {
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
Loading