(apic *apic, dbClient *database.Client, consoleConfig *csconfig.ConsoleConfig, logger logging.ExtLogger)
| 86 | } |
| 87 | |
| 88 | func 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 | |
| 129 | func (p *Papi) handleEvent(ctx context.Context, event longpollclient.Event, sync bool) error { |
| 130 | logger := p.Logger.WithField("request-id", event.RequestId) |
no test coverage detected
searching dependent graphs…