outposts: always update bundles and swap maps
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
c1ab5c5556
commit
5b3941a425
|
@ -31,7 +31,6 @@ type APIController struct {
|
||||||
|
|
||||||
Server Outpost
|
Server Outpost
|
||||||
|
|
||||||
lastBundleHash string
|
|
||||||
logger *log.Entry
|
logger *log.Entry
|
||||||
|
|
||||||
reloadOffset time.Duration
|
reloadOffset time.Duration
|
||||||
|
@ -71,18 +70,12 @@ func NewAPIController(akURL url.URL, token string) *APIController {
|
||||||
logger: log,
|
logger: log,
|
||||||
|
|
||||||
reloadOffset: time.Duration(rand.Intn(10)) * time.Second,
|
reloadOffset: time.Duration(rand.Intn(10)) * time.Second,
|
||||||
|
|
||||||
lastBundleHash: "",
|
|
||||||
}
|
}
|
||||||
ac.logger.Debugf("HA Reload offset: %s", ac.reloadOffset)
|
ac.logger.Debugf("HA Reload offset: %s", ac.reloadOffset)
|
||||||
ac.initWS(akURL, outpost.Pk)
|
ac.initWS(akURL, outpost.Pk)
|
||||||
return ac
|
return ac
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *APIController) GetLastBundleHash() string {
|
|
||||||
return a.lastBundleHash
|
|
||||||
}
|
|
||||||
|
|
||||||
// Start Starts all handlers, non-blocking
|
// Start Starts all handlers, non-blocking
|
||||||
func (a *APIController) Start() error {
|
func (a *APIController) Start() error {
|
||||||
err := a.Server.Refresh()
|
err := a.Server.Refresh()
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
package ak
|
package ak
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/sha512"
|
|
||||||
"encoding/hex"
|
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"goauthentik.io/outpost/pkg/client/outposts"
|
"goauthentik.io/outpost/pkg/client/outposts"
|
||||||
"goauthentik.io/outpost/pkg/models"
|
"goauthentik.io/outpost/pkg/models"
|
||||||
)
|
)
|
||||||
|
@ -15,16 +11,5 @@ func (a *APIController) Update() ([]*models.ProxyOutpostConfig, error) {
|
||||||
a.logger.WithError(err).Error("Failed to fetch providers")
|
a.logger.WithError(err).Error("Failed to fetch providers")
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
// Check provider hash to see if anything is changed
|
|
||||||
hasher := sha512.New()
|
|
||||||
out, err := json.Marshal(providers.Payload.Results)
|
|
||||||
if err != nil {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
hash := hex.EncodeToString(hasher.Sum(out))
|
|
||||||
if hash == a.lastBundleHash {
|
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
a.lastBundleHash = hash
|
|
||||||
return providers.Payload.Results, nil
|
return providers.Payload.Results, nil
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue