From 2428d5f1c2821af94ca68d7cc3c94ec1ccbc55c5 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Fri, 10 Sep 2021 12:18:19 +0200 Subject: [PATCH] outpost: update global outpost config on refresh Signed-off-by: Jens Langhammer --- internal/outpost/ak/api.go | 18 +++++++++++++++++- internal/outpost/ak/api_ws.go | 4 ++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/internal/outpost/ak/api.go b/internal/outpost/ak/api.go index e12492c62..6054761b3 100644 --- a/internal/outpost/ak/api.go +++ b/internal/outpost/ak/api.go @@ -114,8 +114,24 @@ func (a *APIController) Start() error { return nil } +func (a *APIController) OnRefresh() error { + // 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 := a.Client.OutpostsApi.OutpostsInstancesList(context.Background()).Execute() + + if err != nil { + log.WithError(err).Error("Failed to fetch outpost configuration") + return err + } + outpost := outposts.Results[0] + doGlobalSetup(outpost.Config) + + log.WithField("name", outpost.Name).Debug("Fetched outpost configuration") + return a.Server.Refresh() +} + func (a *APIController) StartBackgorundTasks() error { - err := a.Server.Refresh() + err := a.OnRefresh() if err != nil { return errors.Wrap(err, "failed to run initial refresh") } else { diff --git a/internal/outpost/ak/api_ws.go b/internal/outpost/ak/api_ws.go index 4ba1e53b8..1a48dfc6f 100644 --- a/internal/outpost/ak/api_ws.go +++ b/internal/outpost/ak/api_ws.go @@ -91,7 +91,7 @@ func (ac *APIController) startWSHandler() { if wsMsg.Instruction == WebsocketInstructionTriggerUpdate { time.Sleep(ac.reloadOffset) logger.Debug("Got update trigger...") - err := ac.Server.Refresh() + err := ac.OnRefresh() if err != nil { logger.WithError(err).Debug("Failed to update") } else { @@ -139,7 +139,7 @@ func (ac *APIController) startIntervalUpdater() { logger := ac.logger.WithField("loop", "interval-updater") ticker := time.NewTicker(5 * time.Minute) for ; true; <-ticker.C { - err := ac.Server.Refresh() + err := ac.OnRefresh() if err != nil { logger.WithError(err).Debug("Failed to update") } else {