outpost: load global config

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-08-21 14:13:46 +02:00
parent 6433b5982e
commit 2015d91484
1 changed files with 15 additions and 6 deletions

View File

@ -26,10 +26,12 @@ const ConfigErrorReportingEnvironment = "error_reporting_environment"
type APIController struct {
Client *api.APIClient
Outpost api.Outpost
token string
GlobalConfig api.Config
Server Outpost
token string
logger *log.Entry
reloadOffset time.Duration
@ -54,12 +56,18 @@ func NewAPIController(akURL url.URL, token string) *APIController {
log := log.WithField("logger", "authentik.outpost.ak-api-controller")
akConfig, _, err := apiClient.RootApi.RootConfigRetrieve(context.Background()).Execute()
if err != nil {
log.WithError(err).Error("Failed to fetch global configuration")
return nil
}
// Because we don't know the outpost UUID, we simply do a list and pick the first
// The service account this token belongs to should only have access to a single outpost
outposts, _, err := apiClient.OutpostsApi.OutpostsInstancesList(context.Background()).Execute()
if err != nil {
log.WithError(err).Error("Failed to fetch configuration")
log.WithError(err).Error("Failed to fetch outpost configuration")
return nil
}
outpost := outposts.Results[0]
@ -67,8 +75,9 @@ func NewAPIController(akURL url.URL, token string) *APIController {
ac := &APIController{
Client: apiClient,
token: token,
GlobalConfig: akConfig,
token: token,
logger: log,
reloadOffset: time.Duration(rand.Intn(10)) * time.Second,