mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-18 09:08:16 +02:00
rm mutex
This commit is contained in:
parent
75284959e1
commit
a00de1cc95
2 changed files with 28 additions and 45 deletions
|
@ -21,7 +21,6 @@ import (
|
||||||
configpb "github.com/pomerium/pomerium/pkg/grpc/config"
|
configpb "github.com/pomerium/pomerium/pkg/grpc/config"
|
||||||
"github.com/pomerium/pomerium/pkg/grpc/databroker"
|
"github.com/pomerium/pomerium/pkg/grpc/databroker"
|
||||||
"github.com/pomerium/pomerium/pkg/grpcutil"
|
"github.com/pomerium/pomerium/pkg/grpcutil"
|
||||||
"github.com/pomerium/pomerium/pkg/slices"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ConfigSource provides a new Config source that decorates an underlying config with
|
// ConfigSource provides a new Config source that decorates an underlying config with
|
||||||
|
@ -125,27 +124,38 @@ func (src *ConfigSource) buildNewConfigLocked(ctx context.Context, cfg *config.C
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
policies := slices.NewSafeSlice[*config.Policy]()
|
|
||||||
for _, cfgpb := range src.dbConfigs {
|
var policies []*config.Policy
|
||||||
for _, routepb := range cfgpb.GetRoutes() {
|
var builders []func() error
|
||||||
routepb := routepb
|
buildPolicy := func(i int, routepb *configpb.Route) func() error {
|
||||||
eg.Go(func() error {
|
return func() error {
|
||||||
policy, err := src.buildPolicyFromProto(routepb)
|
policy, err := src.buildPolicyFromProto(routepb)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Ctx(ctx).Err(err).Msg("databroker: error building policy from protobuf")
|
log.Ctx(ctx).Err(err).Msg("databroker: error building policy from protobuf")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
policies.Append(policy)
|
policies[i] = policy
|
||||||
return nil
|
return nil
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, cfgpb := range src.dbConfigs {
|
||||||
|
for _, routepb := range cfgpb.GetRoutes() {
|
||||||
|
builders = append(builders, buildPolicy(len(builders), routepb))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
policies = make([]*config.Policy, len(builders))
|
||||||
|
for _, builder := range builders {
|
||||||
|
eg.Go(builder)
|
||||||
|
}
|
||||||
|
|
||||||
err := eg.Wait()
|
err := eg.Wait()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
src.addPolicies(ctx, cfg, policies.Get())
|
src.addPolicies(ctx, cfg, policies)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -198,6 +208,10 @@ func (src *ConfigSource) addPolicies(ctx context.Context, cfg *config.Config, po
|
||||||
|
|
||||||
var additionalPolicies []config.Policy
|
var additionalPolicies []config.Policy
|
||||||
for _, policy := range policies {
|
for _, policy := range policies {
|
||||||
|
if policy == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
id, err := policy.RouteID()
|
id, err := policy.RouteID()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Ctx(ctx).Err(err).Str("policy", policy.String()).Msg("databroker: error getting route id")
|
log.Ctx(ctx).Err(err).Str("policy", policy.String()).Msg("databroker: error getting route id")
|
||||||
|
|
|
@ -1,31 +0,0 @@
|
||||||
package slices
|
|
||||||
|
|
||||||
import "sync"
|
|
||||||
|
|
||||||
// SafeSlice is a thread safe slice.
|
|
||||||
type SafeSlice[E any] struct {
|
|
||||||
mu sync.RWMutex
|
|
||||||
slice []E
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewSafeSlice creates a new SafeSlice.
|
|
||||||
func NewSafeSlice[E any]() *SafeSlice[E] {
|
|
||||||
return &SafeSlice[E]{}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Append appends e to the slice.
|
|
||||||
func (s *SafeSlice[E]) Append(e E) {
|
|
||||||
s.mu.Lock()
|
|
||||||
s.slice = append(s.slice, e)
|
|
||||||
s.mu.Unlock()
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get gets the slice.
|
|
||||||
func (s *SafeSlice[E]) Get() []E {
|
|
||||||
s.mu.RLock()
|
|
||||||
defer s.mu.RUnlock()
|
|
||||||
|
|
||||||
c := make([]E, len(s.slice))
|
|
||||||
copy(c, s.slice)
|
|
||||||
return c
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue