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

Function NewPAPI

pkg/apiserver/papi.go:88–127  ·  view source on GitHub ↗
(apic *apic, dbClient *database.Client, consoleConfig *csconfig.ConsoleConfig, logger logging.ExtLogger)

Source from the content-addressed store, hash-verified

86}
87
88func NewPAPI(apic *apic, dbClient *database.Client, consoleConfig *csconfig.ConsoleConfig, logger logging.ExtLogger) (*Papi, error) {
89 if logger == nil {
90 logger = log.StandardLogger()
91 }
92
93 papiURL := *apic.apiClient.PapiURL
94 papiURL.Path = fmt.Sprintf("%s%s", PAPIVersion, PAPIPollURL)
95
96 longPollClient, err := longpollclient.NewLongPollClient(longpollclient.LongPollClientConfig{
97 Url: papiURL,
98 Logger: logger,
99 HttpClient: apic.apiClient.GetClient(),
100 })
101 if err != nil {
102 return &Papi{}, fmt.Errorf("failed to create PAPI client: %w", err)
103 }
104
105 channels := &OperationChannels{
106 AddAlertChannel: apic.AlertsAddChan,
107 DeleteDecisionChannel: make(chan []*models.Decision),
108 }
109
110 papi := &Papi{
111 URL: apic.apiClient.PapiURL.String(),
112 Client: longPollClient,
113 DBClient: dbClient,
114 Channels: channels,
115 SyncInterval: SyncInterval,
116 mu: sync.Mutex{},
117 pullTomb: tomb.Tomb{},
118 syncTomb: tomb.Tomb{},
119 apiClient: apic.apiClient,
120 apic: apic,
121 consoleConfig: consoleConfig,
122 Logger: logger.WithFields(log.Fields{"interval": SyncInterval.Seconds(), "source": "papi"}),
123 stopChan: make(chan struct{}),
124 }
125
126 return papi, nil
127}
128
129func (p *Papi) handleEvent(ctx context.Context, event longpollclient.Event, sync bool) error {
130 logger := p.Logger.WithField("request-id", event.RequestId)

Callers 3

StatusMethod · 0.92
syncMethod · 0.92
NewServerFunction · 0.85

Calls 4

NewLongPollClientFunction · 0.92
StandardLoggerMethod · 0.80
GetClientMethod · 0.80
StringMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…