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

add share tag feature #1087

Closed
wants to merge 15 commits into from
24 changes: 24 additions & 0 deletions file/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ import (
"context"
"errors"
"fmt"
"regexp"

"github.com/blang/semver/v4"
"github.com/kong/deck/dump"
"github.com/kong/deck/konnect"
"github.com/kong/deck/state"
"github.com/kong/deck/utils"
Expand Down Expand Up @@ -944,9 +946,31 @@ func (b *stateBuilder) plugins() {
}

var plugins []FPlugin
var SharedUser, SharedTag string
sharedEntities := make(map[string]bool)
for _, p := range b.targetContent.Plugins {
p := p
if p.Consumer != nil && !utils.Empty(p.Consumer.ID) {
shareTagRegex := regexp.MustCompile(`\/\/([^/]+)/(.+)$`)
matches := shareTagRegex.FindStringSubmatch(*p.Consumer.ID)
if len(matches) >= 2 {
SharedTag, SharedUser = matches[1], matches[2]
*p.Consumer.ID = SharedUser
}
if SharedTag != "" && !sharedEntities[SharedTag] {
consumersGlobal, err := dump.GetAllConsumers(b.ctx, b.client, []string{SharedTag})
if err != nil {
fmt.Printf("Error retrieving global consumers: %v\n", err)
}
for _, c := range consumersGlobal {
err = b.intermediate.Consumers.Add(state.Consumer{Consumer: *c})
if err != nil {
fmt.Printf("Error adding global consumer %v: %v\n", *c.Username, err)
}
}
// add future logic for global entities
sharedEntities[SharedTag] = true
}
c, err := b.intermediate.Consumers.GetByIDOrUsername(*p.Consumer.ID)
if errors.Is(err, state.ErrNotFound) {
b.err = fmt.Errorf("consumer %v for plugin %v: %w",
Expand Down
Loading