Skip to content

Commit

Permalink
add logic to exclude tags
Browse files Browse the repository at this point in the history
  • Loading branch information
flarco committed Oct 10, 2024
1 parent 58ba6e6 commit 32c3bfa
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions core/sling/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,15 +387,23 @@ func (rd *ReplicationConfig) Compile(cfgOverwrite *Config, selectStreams ...stri

// clean up selectStreams
matchedStreams := map[string]*ReplicationStreamConfig{}
selectTags := []string{}
includeTags := []string{}
excludeTags := []string{}
for _, selectStream := range selectStreams {
for key, val := range rd.MatchStreams(selectStream) {
key = rd.Normalize(key)
matchedStreams[key] = val
}
if strings.HasPrefix(selectStream, "tag:") {
selectTags = append(selectTags, strings.TrimPrefix(selectStream, "tag:"))
includeTags = append(includeTags, strings.TrimPrefix(selectStream, "tag:"))
}
if strings.HasPrefix(selectStream, "-tag:") {
excludeTags = append(excludeTags, strings.TrimPrefix(selectStream, "-tag:"))
}
}

if len(includeTags) > 0 && len(excludeTags) > 0 {
return g.Error("cannot include and exclude tags. Either include or exclude.")
}

for _, name := range rd.StreamsOrdered() {
Expand All @@ -412,7 +420,7 @@ func (rd *ReplicationConfig) Compile(cfgOverwrite *Config, selectStreams ...stri

// match on tag, need stream defined to do so
matchedTag := false
for _, tag := range selectTags {
for _, tag := range includeTags {
if g.In(tag, stream.Tags...) {
matchedTag = true
}
Expand All @@ -421,6 +429,13 @@ func (rd *ReplicationConfig) Compile(cfgOverwrite *Config, selectStreams ...stri
matchedStreams[rd.Normalize(name)] = &stream
}

// exclude tags
for _, tag := range excludeTags {
if g.In(tag, stream.Tags...) {
delete(matchedStreams, rd.Normalize(name))
}
}

_, matched := matchedStreams[rd.Normalize(name)]
if len(selectStreams) > 0 && !matched {
g.Trace("skipping stream %s since it is not selected", name)
Expand Down

0 comments on commit 32c3bfa

Please sign in to comment.