2021-04-19 23:30:27 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/url"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
|
2021-06-16 16:29:01 +01:00
|
|
|
"goauthentik.io/internal/common"
|
2021-06-16 11:02:02 +01:00
|
|
|
"goauthentik.io/internal/outpost/ak"
|
|
|
|
"goauthentik.io/internal/outpost/ldap"
|
2021-04-19 23:30:27 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
const helpMessage = `authentik ldap
|
|
|
|
|
|
|
|
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)
|
2021-06-16 16:29:01 +01:00
|
|
|
akURL, found := os.LookupEnv("AUTHENTIK_HOST")
|
2021-04-19 23:30:27 +01:00
|
|
|
if !found {
|
|
|
|
fmt.Println("env AUTHENTIK_HOST not set!")
|
|
|
|
fmt.Println(helpMessage)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2021-06-16 16:29:01 +01:00
|
|
|
akToken, found := os.LookupEnv("AUTHENTIK_TOKEN")
|
2021-04-19 23:30:27 +01:00
|
|
|
if !found {
|
|
|
|
fmt.Println("env AUTHENTIK_TOKEN not set!")
|
|
|
|
fmt.Println(helpMessage)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2021-06-16 16:29:01 +01:00
|
|
|
akURLActual, err := url.Parse(akURL)
|
2021-04-19 23:30:27 +01:00
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
fmt.Println(helpMessage)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2021-06-16 16:29:01 +01:00
|
|
|
ex := common.Init()
|
|
|
|
defer common.Defer()
|
2021-04-19 23:30:27 +01:00
|
|
|
|
2021-06-16 16:29:01 +01:00
|
|
|
ac := ak.NewAPIController(*akURLActual, akToken)
|
2021-04-19 23:30:27 +01:00
|
|
|
|
|
|
|
ac.Server = ldap.NewServer(ac)
|
|
|
|
|
2021-04-26 11:24:46 +01:00
|
|
|
err = ac.Start()
|
|
|
|
if err != nil {
|
|
|
|
log.WithError(err).Panic("Failed to run server")
|
|
|
|
}
|
2021-04-19 23:30:27 +01:00
|
|
|
|
|
|
|
for {
|
2021-06-16 16:29:01 +01:00
|
|
|
<-ex
|
2021-04-26 11:24:46 +01:00
|
|
|
ac.Shutdown()
|
|
|
|
os.Exit(0)
|
2021-04-19 23:30:27 +01:00
|
|
|
}
|
|
|
|
}
|