package setup import ( "context" "time" "forge.cadoles.com/cadoles/bouncer/internal/config" "forge.cadoles.com/cadoles/bouncer/internal/integration" "forge.cadoles.com/cadoles/bouncer/internal/integration/kubernetes" "forge.cadoles.com/cadoles/bouncer/internal/lock/redis" "github.com/pkg/errors" ) func SetupIntegrations(ctx context.Context, conf *config.Config) ([]integration.Integration, error) { integrations := make([]integration.Integration, 0) if conf.Integrations.Kubernetes.Enabled { kubernetes, err := setupKubernetesIntegration(ctx, conf) if err != nil { return nil, errors.Wrap(err, "could not setup kubernetes integration") } integrations = append(integrations, kubernetes) } return integrations, nil } func setupKubernetesIntegration(ctx context.Context, conf *config.Config) (*kubernetes.Integration, error) { client := NewSharedClient(conf.Redis) locker := redis.NewLocker(client, 10) integration := kubernetes.NewIntegration( kubernetes.WithReaderTokenSecret(string(conf.Integrations.Kubernetes.ReaderTokenSecret)), kubernetes.WithReaderTokenSecretNamespace(string(conf.Integrations.Kubernetes.ReaderTokenSecretNamespace)), kubernetes.WithWriterTokenSecret(string(conf.Integrations.Kubernetes.WriterTokenSecret)), kubernetes.WithWriterTokenSecretNamespace(string(conf.Integrations.Kubernetes.WriterTokenSecretNamespace)), kubernetes.WithPrivateKeySecret(string(conf.Integrations.Kubernetes.PrivateKeySecret)), kubernetes.WithPrivateKeySecretNamespace(string(conf.Integrations.Kubernetes.PrivateKeySecretNamespace)), kubernetes.WithIssuer(string(conf.Admin.Auth.Issuer)), kubernetes.WithLocker(locker), kubernetes.WithLockTimeout(time.Duration(conf.Integrations.Kubernetes.LockTimeout)), ) return integration, nil }