Path: blob/main/component/loki/source/cloudflare/internal/cloudflaretarget/client.go
4097 views
package cloudflaretarget12// This code is copied from Promtail. The cloudflaretarget package is used to3// configure and run a target that can read from the Cloudflare Logpull API and4// forward entries to other loki components.56import (7"context"8"time"910"github.com/grafana/cloudflare-go"11)1213// Client is a wrapper around the Cloudflare API that allow for testing and being zone/fields aware.14type Client interface {15LogpullReceived(ctx context.Context, start, end time.Time) (cloudflare.LogpullReceivedIterator, error)16}1718type wrappedClient struct {19client *cloudflare.API20zoneID string21fields []string22}2324func (w *wrappedClient) LogpullReceived(ctx context.Context, start, end time.Time) (cloudflare.LogpullReceivedIterator, error) {25return w.client.LogpullReceived(ctx, w.zoneID, start, end, cloudflare.LogpullReceivedOption{26Fields: w.fields,27})28}2930var getClient = func(apiKey, zoneID string, fields []string) (Client, error) {31c, err := cloudflare.NewWithAPIToken(apiKey)32if err != nil {33return nil, err34}35return &wrappedClient{36client: c,37zoneID: zoneID,38fields: fields,39}, nil40}414243