authentik/internal/outpost/proxyv2/refresh.go

40 lines
1.1 KiB
Go

package proxyv2
import (
"context"
"fmt"
"net/http"
"github.com/getsentry/sentry-go"
"goauthentik.io/internal/constants"
"goauthentik.io/internal/outpost/ak"
"goauthentik.io/internal/outpost/proxyv2/application"
)
func (ps *ProxyServer) Refresh() error {
providers, _, err := ps.akAPI.Client.OutpostsApi.OutpostsProxyList(context.Background()).Execute()
if err != nil {
ps.log.WithError(err).Error("Failed to fetch providers")
}
if err != nil {
return err
}
apps := make(map[string]*application.Application)
for _, provider := range providers.Results {
rsp := sentry.StartSpan(context.Background(), "authentik.outposts.proxy.application_ss")
ua := fmt.Sprintf(" (provider=%s)", provider.Name)
hc := &http.Client{
Transport: ak.NewUserAgentTransport(constants.OutpostUserAgent()+ua, ak.NewTracingTransport(rsp.Context(), ak.GetTLSTransport())),
}
a, err := application.NewApplication(provider, hc, ps.cryptoStore, ps.akAPI)
if err != nil {
ps.log.WithError(err).Warning("failed to setup application")
} else {
apps[a.Host] = a
}
}
ps.apps = apps
ps.log.Debug("Swapped maps")
return nil
}