mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2026-05-10 14:28:12 +00:00
4f7335ed73
* feat: add new logger * refactor: use one struct for context handling and cancellation * refactor: rework logging and config in controllers * refactor: rework logging and config in middlewares * refactor: rework logging and cancellation in services * refactor: rework cli logging * fix: improve logging in routines * feat: use sync groups for better cancellation * refactor: simplify middleware, controller and service init * tests: fix controller tests * tests: use require instead of assert where previous step is required * tests: fix middleware tests * tests: fix service tests * tests: fix context tests * fix: fix typos * feat: add option to enable or disable concurrent listeners * fix: assign public key correctly in oidc server * tests: fix don't try to test logger with char size * fix: coderabbit comments * tests: use filepath join instead of path join * fix: ensure unix socket shutdown doesn't run twice * chore: remove temp lint file
67 lines
2.0 KiB
Go
67 lines
2.0 KiB
Go
package bootstrap
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/tinyauthapp/tinyauth/internal/service"
|
|
)
|
|
|
|
func (app *BootstrapApp) setupServices() error {
|
|
ldapService, err := service.NewLdapService(app.log, app.config, app.ctx, &app.wg)
|
|
|
|
if err != nil {
|
|
app.log.App.Warn().Err(err).Msg("Failed to initialize LDAP connection, will continue without it")
|
|
}
|
|
|
|
app.services.ldapService = ldapService
|
|
|
|
useKubernetes := app.config.LabelProvider == "kubernetes" ||
|
|
(app.config.LabelProvider == "auto" && os.Getenv("KUBERNETES_SERVICE_HOST") != "")
|
|
|
|
var labelProvider service.LabelProvider
|
|
|
|
if useKubernetes {
|
|
app.log.App.Debug().Msg("Using Kubernetes label provider")
|
|
|
|
kubernetesService, err := service.NewKubernetesService(app.log, app.ctx, &app.wg)
|
|
|
|
if err != nil {
|
|
return fmt.Errorf("failed to initialize kubernetes service: %w", err)
|
|
}
|
|
|
|
app.services.kubernetesService = kubernetesService
|
|
labelProvider = kubernetesService
|
|
} else {
|
|
app.log.App.Debug().Msg("Using Docker label provider")
|
|
|
|
dockerService, err := service.NewDockerService(app.log, app.ctx, &app.wg)
|
|
|
|
if err != nil {
|
|
return fmt.Errorf("failed to initialize docker service: %w", err)
|
|
}
|
|
|
|
app.services.dockerService = dockerService
|
|
labelProvider = dockerService
|
|
}
|
|
|
|
accessControlsService := service.NewAccessControlsService(app.log, &labelProvider, app.config.Apps)
|
|
app.services.accessControlService = accessControlsService
|
|
|
|
oauthBrokerService := service.NewOAuthBrokerService(app.log, app.runtime.OAuthProviders, app.ctx)
|
|
app.services.oauthBrokerService = oauthBrokerService
|
|
|
|
authService := service.NewAuthService(app.log, app.config, app.runtime, app.ctx, &app.wg, app.services.ldapService, app.queries, app.services.oauthBrokerService)
|
|
app.services.authService = authService
|
|
|
|
oidcService, err := service.NewOIDCService(app.log, app.config, app.runtime, app.queries, app.ctx, &app.wg)
|
|
|
|
if err != nil {
|
|
return fmt.Errorf("failed to initialize oidc service: %w", err)
|
|
}
|
|
|
|
app.services.oidcService = oidcService
|
|
|
|
return nil
|
|
}
|