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

@ -24,12 +24,14 @@ const ConfigErrorReportingEnvironment = "error_reporting_environment"
// APIController main controller which connects to the authentik api via http and ws // APIController main controller which connects to the authentik api via http and ws
type APIController struct { type APIController struct {
Client *api.APIClient Client *api.APIClient
Outpost api.Outpost Outpost api.Outpost
token string GlobalConfig api.Config
Server Outpost Server Outpost
token string
logger *log.Entry logger *log.Entry
reloadOffset time.Duration reloadOffset time.Duration
@ -54,21 +56,28 @@ func NewAPIController(akURL url.URL, token string) *APIController {
log := log.WithField("logger", "authentik.outpost.ak-api-controller") 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 // 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 // The service account this token belongs to should only have access to a single outpost
outposts, _, err := apiClient.OutpostsApi.OutpostsInstancesList(context.Background()).Execute() outposts, _, err := apiClient.OutpostsApi.OutpostsInstancesList(context.Background()).Execute()
if err != nil { if err != nil {
log.WithError(err).Error("Failed to fetch configuration") log.WithError(err).Error("Failed to fetch outpost configuration")
return nil return nil
} }
outpost := outposts.Results[0] outpost := outposts.Results[0]
doGlobalSetup(outpost.Config) doGlobalSetup(outpost.Config)
ac := &APIController{ ac := &APIController{
Client: apiClient, Client: apiClient,
token: token, GlobalConfig: akConfig,
token: token,
logger: log, logger: log,
reloadOffset: time.Duration(rand.Intn(10)) * time.Second, reloadOffset: time.Duration(rand.Intn(10)) * time.Second,