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

pkg/replication:Fix tag validation #1406

Merged
merged 1 commit into from
Nov 9, 2020
Merged
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
20 changes: 15 additions & 5 deletions pkg/replication/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,23 @@ type Options struct {
}

// Tags returns a slice of tags for a rule
func (opts Options) Tags() []Tag {
func (opts Options) Tags() ([]Tag, error) {
var tagList []Tag
tagTokens := strings.Split(opts.TagString, "&")
for _, tok := range tagTokens {
if tok == "" {
break
}
kv := strings.SplitN(tok, "=", 2)
if len(kv) != 2 {
return []Tag{}, fmt.Errorf("Tags should be entered as comma separated k=v pairs")
}
tagList = append(tagList, Tag{
Key: kv[0],
Value: kv[1],
})
}
return tagList
return tagList, nil
}

// Config - replication configuration specified in
Expand Down Expand Up @@ -112,9 +115,12 @@ func (c *Config) AddRule(opts Options) error {
return fmt.Errorf("Rule state should be either [enable|disable]")
}

tags := opts.Tags()
tags, err := opts.Tags()
if err != nil {
return err
}
andVal := And{
Tags: opts.Tags(),
Tags: tags,
}
filter := Filter{Prefix: opts.Prefix}
// only a single tag is set.
Expand Down Expand Up @@ -238,8 +244,12 @@ func (c *Config) EditRule(opts Options) error {
if len(newRule.Filter.And.Tags) != 0 {
tags = newRule.Filter.And.Tags
}
var err error
if opts.IsTagSet {
tags = opts.Tags()
tags, err = opts.Tags()
if err != nil {
return err
}
}
andVal := And{
Tags: tags,
Expand Down