mirror of
https://github.com/pomerium/pomerium.git
synced 2025-04-28 18:06:34 +02:00
This also replaces instances where we manually write "return ctx.Err()" with "return context.Cause(ctx)" which is functionally identical, but will also correctly propagate cause errors if present.
48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
package healthcheck
|
|
|
|
import (
|
|
"context"
|
|
|
|
configpb "github.com/pomerium/pomerium/pkg/grpc/config"
|
|
"github.com/pomerium/pomerium/pkg/grpc/databroker"
|
|
"github.com/pomerium/pomerium/pkg/health"
|
|
"github.com/pomerium/pomerium/pkg/protoutil"
|
|
)
|
|
|
|
func (c *Checker) ConfigSyncer(ctx context.Context) error {
|
|
syncer := databroker.NewSyncer(ctx, "zero-health-check", c, databroker.WithTypeURL(protoutil.GetTypeURL(new(configpb.Config))))
|
|
return syncer.Run(ctx)
|
|
}
|
|
|
|
func (c *Checker) GetConfigs() []*configpb.Config {
|
|
configs := c.configs.Load()
|
|
if configs == nil {
|
|
return nil
|
|
}
|
|
return configs.([]*configpb.Config)
|
|
}
|
|
|
|
// ClearRecords implements databroker.Syncer interface
|
|
func (c *Checker) ClearRecords(_ context.Context) {
|
|
c.configs.Store([]*configpb.Config{})
|
|
}
|
|
|
|
// UpdateRecords implements databroker.Syncer interface
|
|
func (c *Checker) UpdateRecords(_ context.Context, _ uint64, records []*databroker.Record) {
|
|
if len(records) == 0 {
|
|
return
|
|
}
|
|
|
|
cfgs, err := getConfig(records)
|
|
if err != nil {
|
|
health.ReportInternalError(health.RoutesReachable, err)
|
|
return
|
|
}
|
|
c.configs.Store(cfgs)
|
|
c.ForceCheck()
|
|
}
|
|
|
|
// GetDataBrokerServiceClient implements databroker.Syncer interface
|
|
func (c *Checker) GetDataBrokerServiceClient() databroker.DataBrokerServiceClient {
|
|
return c.databrokerClient
|
|
}
|