outpost: update global outpost config on refresh

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-09-10 12:18:19 +02:00
parent f1dc2b4d2a
commit 2428d5f1c2
2 changed files with 19 additions and 3 deletions

View File

@ -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 {

View File

@ -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 {