This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
authentik/cmd/proxy/server.go

62 lines
1.1 KiB
Go
Raw Permalink Normal View History

package main
2020-09-02 22:04:12 +00:00
import (
"fmt"
2020-09-02 22:04:12 +00:00
"net/url"
"os"
log "github.com/sirupsen/logrus"
"goauthentik.io/internal/common"
"goauthentik.io/internal/outpost/ak"
"goauthentik.io/internal/outpost/proxy"
2020-09-02 22:04:12 +00:00
)
2020-12-05 21:08:42 +00:00
const helpMessage = `authentik proxy
Required environment variables:
- AUTHENTIK_HOST: URL to connect to (format "http://authentik.company")
- AUTHENTIK_TOKEN: Token to authenticate with
- AUTHENTIK_INSECURE: Skip SSL Certificate verification`
func main() {
log.SetLevel(log.DebugLevel)
akURL, found := os.LookupEnv("AUTHENTIK_HOST")
2020-09-02 22:04:12 +00:00
if !found {
2020-12-05 21:08:42 +00:00
fmt.Println("env AUTHENTIK_HOST not set!")
fmt.Println(helpMessage)
os.Exit(1)
2020-09-02 22:04:12 +00:00
}
akToken, found := os.LookupEnv("AUTHENTIK_TOKEN")
2020-09-02 22:04:12 +00:00
if !found {
2020-12-05 21:08:42 +00:00
fmt.Println("env AUTHENTIK_TOKEN not set!")
fmt.Println(helpMessage)
os.Exit(1)
2020-09-02 22:04:12 +00:00
}
akURLActual, err := url.Parse(akURL)
2020-09-02 22:04:12 +00:00
if err != nil {
fmt.Println(err)
fmt.Println(helpMessage)
os.Exit(1)
2020-09-02 22:04:12 +00:00
}
ex := common.Init()
defer common.Defer()
2020-09-02 22:04:12 +00:00
ac := ak.NewAPIController(*akURLActual, akToken)
2020-09-02 22:04:12 +00:00
ac.Server = proxy.NewServer(ac)
err = ac.Start()
if err != nil {
log.WithError(err).Panic("Failed to run server")
}
2020-09-02 22:04:12 +00:00
for {
<-ex
ac.Shutdown()
os.Exit(0)
2020-09-02 22:04:12 +00:00
}
}