mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-22 05:27:13 +02:00
cache: support databroker option changes (#1294)
This commit is contained in:
parent
31205c0c29
commit
a1378c81f8
16 changed files with 408 additions and 179 deletions
|
@ -4,8 +4,10 @@ package directory
|
|||
import (
|
||||
"context"
|
||||
"net/url"
|
||||
"sync"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
|
||||
"github.com/pomerium/pomerium/config"
|
||||
"github.com/pomerium/pomerium/internal/directory/azure"
|
||||
"github.com/pomerium/pomerium/internal/directory/github"
|
||||
"github.com/pomerium/pomerium/internal/directory/gitlab"
|
||||
|
@ -27,8 +29,34 @@ type Provider interface {
|
|||
UserGroups(ctx context.Context) ([]*Group, []*User, error)
|
||||
}
|
||||
|
||||
// Options are the options specific to the provider.
|
||||
type Options struct {
|
||||
ServiceAccount string
|
||||
Provider string
|
||||
ProviderURL string
|
||||
QPS float64
|
||||
}
|
||||
|
||||
var globalProvider = struct {
|
||||
sync.Mutex
|
||||
provider Provider
|
||||
options Options
|
||||
}{}
|
||||
|
||||
// GetProvider gets the provider for the given options.
|
||||
func GetProvider(options *config.Options) Provider {
|
||||
func GetProvider(options Options) (provider Provider) {
|
||||
globalProvider.Lock()
|
||||
defer globalProvider.Unlock()
|
||||
|
||||
if globalProvider.provider != nil && cmp.Equal(globalProvider.options, options) {
|
||||
log.Debug().Str("provider", options.Provider).Msg("directory: no change detected, reusing existing directory provider")
|
||||
return globalProvider.provider
|
||||
}
|
||||
defer func() {
|
||||
globalProvider.provider = provider
|
||||
globalProvider.options = options
|
||||
}()
|
||||
|
||||
switch options.Provider {
|
||||
case azure.Name:
|
||||
serviceAccount, err := azure.ParseServiceAccount(options.ServiceAccount)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue