bouncer/internal/setup/integrations.go

47 lines
1.7 KiB
Go
Raw Normal View History

2024-03-27 17:47:39 +01:00
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 := newRedisClient(conf.Redis)
locker := redis.NewLocker(client, 10)
2024-03-27 17:47:39 +01:00
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)),
2024-03-27 17:47:39 +01:00
kubernetes.WithIssuer(string(conf.Admin.Auth.Issuer)),
kubernetes.WithLocker(locker),
kubernetes.WithLockTimeout(time.Duration(conf.Integrations.Kubernetes.LockTimeout)),
)
return integration, nil
}