46 lines
1.6 KiB
Go
46 lines
1.6 KiB
Go
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)
|
|
|
|
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.WithIssuer(string(conf.Admin.Auth.Issuer)),
|
|
kubernetes.WithPrivateKey(string(conf.Admin.Auth.PrivateKey)),
|
|
kubernetes.WithLocker(locker),
|
|
kubernetes.WithLockTimeout(time.Duration(conf.Integrations.Kubernetes.LockTimeout)),
|
|
)
|
|
|
|
return integration, nil
|
|
}
|