MCPcopy
hub / github.com/crowdsecurity/crowdsec / sync

Method sync

cmd/crowdsec-cli/clipapi/papi.go:122–154  ·  view source on GitHub ↗
(ctx context.Context, db *database.Client)

Source from the content-addressed store, hash-verified

120}
121
122func (cli *cliPapi) sync(ctx context.Context, db *database.Client) error {
123 cfg := cli.cfg()
124
125 apic, err := apiserver.NewAPIC(ctx, cfg.API.Server.OnlineClient, db, cfg.API.Server.ConsoleConfig, cfg.API.Server.CapiWhitelists)
126 if err != nil {
127 return fmt.Errorf("unable to initialize API client: %w", err)
128 }
129
130 g, ctx := errgroup.WithContext(ctx)
131 g.Go(func() error { return apic.Push(ctx) })
132
133 papiLogger := cfg.API.Server.NewPAPILogger()
134 papi, err := apiserver.NewPAPI(apic, db, cfg.API.Server.ConsoleConfig, papiLogger)
135 if err != nil {
136 return fmt.Errorf("unable to initialize PAPI client: %w", err)
137 }
138
139 g.Go(func() error { return papi.SyncDecisions(ctx) })
140
141 err = papi.PullOnce(ctx, time.Time{}, true)
142 if err != nil {
143 return fmt.Errorf("unable to sync decisions: %w", err)
144 }
145
146 log.Infof("Sending acknowledgements to CAPI")
147
148 apic.Shutdown()
149 papi.Shutdown()
150 _ = g.Wait()
151 time.Sleep(5 * time.Second) // FIXME: the push done by apic.Push is run inside a sub goroutine, sleep to make sure it's done
152
153 return nil
154}
155
156func (cli *cliPapi) newSyncCmd() *cobra.Command {
157 cmd := &cobra.Command{

Callers 1

newSyncCmdMethod · 0.95

Calls 8

NewAPICFunction · 0.92
NewPAPIFunction · 0.92
cfgMethod · 0.80
PushMethod · 0.80
NewPAPILoggerMethod · 0.80
SyncDecisionsMethod · 0.80
PullOnceMethod · 0.45
ShutdownMethod · 0.45

Tested by

no test coverage detected