2021-01-16 20:41:39 +00:00
|
|
|
package proxy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/url"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
2021-05-16 19:07:01 +00:00
|
|
|
"goauthentik.io/outpost/api"
|
2021-01-16 20:41:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func (s *Server) Refresh() error {
|
|
|
|
providers, err := s.ak.Update()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if providers == nil {
|
|
|
|
s.logger.Debug("Providers have not changed, not updating")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
bundles := s.bundleProviders(providers)
|
|
|
|
s.updateHTTPServer(bundles)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-05-16 19:07:01 +00:00
|
|
|
func (s *Server) bundleProviders(providers []api.ProxyOutpostConfig) []*providerBundle {
|
2021-01-16 20:41:39 +00:00
|
|
|
bundles := make([]*providerBundle, len(providers))
|
|
|
|
for idx, provider := range providers {
|
2021-05-16 19:07:01 +00:00
|
|
|
externalHost, err := url.Parse(provider.ExternalHost)
|
2021-01-16 20:41:39 +00:00
|
|
|
if err != nil {
|
|
|
|
log.WithError(err).Warning("Failed to parse URL, skipping provider")
|
|
|
|
}
|
|
|
|
bundles[idx] = &providerBundle{
|
2021-07-01 13:48:56 +00:00
|
|
|
s: s,
|
|
|
|
Host: externalHost.Host,
|
|
|
|
log: log.WithField("logger", "authentik.outpost.proxy-bundle").WithField("provider", provider.Name),
|
|
|
|
endSessionUrl: provider.OidcConfiguration.EndSessionEndpoint,
|
2021-01-16 20:41:39 +00:00
|
|
|
}
|
|
|
|
bundles[idx].Build(provider)
|
|
|
|
}
|
|
|
|
return bundles
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Server) updateHTTPServer(bundles []*providerBundle) {
|
|
|
|
newMap := make(map[string]*providerBundle)
|
|
|
|
for _, bundle := range bundles {
|
|
|
|
newMap[bundle.Host] = bundle
|
|
|
|
}
|
|
|
|
s.logger.Debug("Swapped maps")
|
|
|
|
s.Handlers = newMap
|
|
|
|
}
|