2021-01-16 20:41:39 +00:00
|
|
|
package ak
|
|
|
|
|
|
|
|
import (
|
2021-12-23 18:01:32 +00:00
|
|
|
"fmt"
|
2021-01-16 20:41:39 +00:00
|
|
|
"net/http"
|
|
|
|
"os"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/getsentry/sentry-go"
|
|
|
|
httptransport "github.com/go-openapi/runtime/client"
|
|
|
|
log "github.com/sirupsen/logrus"
|
2021-11-29 13:42:19 +00:00
|
|
|
"goauthentik.io/api"
|
2021-06-16 11:35:17 +01:00
|
|
|
"goauthentik.io/internal/constants"
|
2021-01-16 20:41:39 +00:00
|
|
|
)
|
|
|
|
|
2021-11-29 13:42:19 +00:00
|
|
|
func doGlobalSetup(outpost api.Outpost, globalConfig api.Config) {
|
2021-12-20 20:23:19 +00:00
|
|
|
l := log.WithField("logger", "authentik.outpost")
|
2021-12-20 20:46:01 +00:00
|
|
|
m := outpost.Managed.Get()
|
|
|
|
if m == nil || *m == "" {
|
2021-12-20 20:23:19 +00:00
|
|
|
switch outpost.Config[ConfigLogLevel].(string) {
|
|
|
|
case "trace":
|
|
|
|
log.SetLevel(log.TraceLevel)
|
|
|
|
case "debug":
|
|
|
|
log.SetLevel(log.DebugLevel)
|
|
|
|
case "info":
|
|
|
|
log.SetLevel(log.InfoLevel)
|
|
|
|
case "warning":
|
|
|
|
log.SetLevel(log.WarnLevel)
|
|
|
|
case "error":
|
|
|
|
log.SetLevel(log.ErrorLevel)
|
|
|
|
default:
|
|
|
|
log.SetLevel(log.DebugLevel)
|
|
|
|
}
|
|
|
|
} else {
|
2021-12-20 21:43:58 +00:00
|
|
|
l.Debug("Managed outpost, not setting global log level")
|
2021-01-16 20:41:39 +00:00
|
|
|
}
|
2022-01-14 09:45:37 +00:00
|
|
|
l.WithField("hash", constants.BUILD("tagged")).WithField("version", constants.VERSION).Info("Starting authentik outpost")
|
2021-01-16 20:41:39 +00:00
|
|
|
|
2021-11-29 13:42:19 +00:00
|
|
|
if globalConfig.ErrorReporting.Enabled {
|
|
|
|
dsn := "https://a579bb09306d4f8b8d8847c052d3a1d3@sentry.beryju.org/8"
|
2021-12-20 20:23:19 +00:00
|
|
|
l.WithField("env", globalConfig.ErrorReporting.Environment).Debug("Error reporting enabled")
|
2021-09-14 16:40:31 +01:00
|
|
|
err := sentry.Init(sentry.ClientOptions{
|
|
|
|
Dsn: dsn,
|
2021-12-16 18:12:05 +00:00
|
|
|
Environment: globalConfig.ErrorReporting.Environment,
|
2021-11-29 13:42:19 +00:00
|
|
|
TracesSampleRate: float64(globalConfig.ErrorReporting.TracesSampleRate),
|
2021-12-23 18:01:32 +00:00
|
|
|
Release: fmt.Sprintf("authentik@%s", constants.VERSION),
|
2021-12-20 18:42:45 +00:00
|
|
|
IgnoreErrors: []string{
|
|
|
|
http.ErrAbortHandler.Error(),
|
|
|
|
},
|
2021-09-14 16:40:31 +01:00
|
|
|
})
|
|
|
|
if err != nil {
|
2021-12-20 20:23:19 +00:00
|
|
|
l.WithField("env", globalConfig.ErrorReporting.Environment).WithError(err).Warning("Failed to initialise sentry")
|
2021-09-14 16:40:31 +01:00
|
|
|
}
|
2021-01-16 20:41:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-15 23:01:16 +01:00
|
|
|
// GetTLSTransport Get a TLS transport instance, that skips verification if configured via environment variables.
|
|
|
|
func GetTLSTransport() http.RoundTripper {
|
2021-01-16 20:41:39 +00:00
|
|
|
value, set := os.LookupEnv("AUTHENTIK_INSECURE")
|
|
|
|
if !set {
|
|
|
|
value = "false"
|
|
|
|
}
|
|
|
|
tlsTransport, err := httptransport.TLSTransport(httptransport.TLSClientOptions{
|
|
|
|
InsecureSkipVerify: strings.ToLower(value) == "true",
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return tlsTransport
|
|
|
|
}
|