Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
Logger zerolog.Logger
Spec Spec
IPGeo *ipgeolocation.Client
Backend state.Client
}
Client is the resolver-facing client. Every resolver receives it via meta.(*client.Client). It implements schema.ClientMeta.
func New ¶
func New(logger zerolog.Logger, spec Spec, ipgeo *ipgeolocation.Client, backend state.Client) *Client
New creates a new resolver-facing Client.
func TestClient ¶
TestClient creates a Client wired to a local httptest.Server for unit testing. The caller provides a handler that simulates the IPGeolocation.io API. It returns the Client and a cleanup function that must be called when done.
type Spec ¶
type Spec struct {
// APIKey is the IPGeolocation.io API key used for authentication.
APIKey string `json:"api_key"`
// Endpoint is the base URL for the IPGeolocation.io API.
// Defaults to "https://api.ipgeolocation.io".
Endpoint string `json:"endpoint"`
// Timeout is the HTTP client timeout as a duration string (e.g. "30s").
// Defaults to "30s".
Timeout string `json:"timeout"`
MaxResponseMB *int64 `json:"max_response_mb,omitempty"`
// RetryAttempts is the number of times to retry a failed API request.
// Defaults to 3.
RetryAttempts int `json:"retry_attempts"`
// Concurrency controls how many tables are synced in parallel.
// Defaults to 10.
Concurrency int `json:"concurrency"`
// RateLimit is the maximum number of API requests per second.
// Defaults to 15.
RateLimit int `json:"rate_limit"`
// UserAgent is the User-Agent header sent with every request.
// Defaults to "cq-source-ipgeolocation/1.0".
UserAgent string `json:"user_agent"`
// IPs is a list of IP addresses to look up using the IP Geolocation endpoint.
// If empty, the plugin looks up the caller's own public IP.
IPs []string `json:"ips"`
// UserAgents is a list of user-agent strings to parse via the User-Agent API.
UserAgents []string `json:"user_agents"`
// ASNs is a list of AS numbers (e.g. "24940", "15169") to look up via the dedicated ASN API.
ASNs []string `json:"asns"`
// IncludeSecurity adds IP security/threat data to geolocation results (paid plans).
IncludeSecurity bool `json:"include_security"`
// IncludeAbuse adds abuse contact data to geolocation results (paid plans).
IncludeAbuse bool `json:"include_abuse"`
// IncludeGeoAccuracy adds the location accuracy fields (locality,
// accuracy_radius, confidence) to geolocation results (paid plans).
IncludeGeoAccuracy bool `json:"include_geo_accuracy"`
// IncludeDMACode adds the DMA (Designated Market Area) code to geolocation
// results (paid plans). Only populated for US locations.
IncludeDMACode bool `json:"include_dma_code"`
// IncludeHostname adds the reverse-DNS hostname to geolocation results
// (paid plans). How it is resolved is controlled by HostnameLookup.
IncludeHostname bool `json:"include_hostname"`
// HostnameLookup selects how the hostname is resolved when IncludeHostname
// is true: "database" (fast, from IPGeolocation.io's hostname database, but
// experimental), "live" (accurate live lookup, adds latency) or
// "fallback_live" (database first, live lookup if not found).
// Defaults to "fallback_live".
HostnameLookup string `json:"hostname_lookup"`
// ASNInclude selects which optional modules the ipgeolocation_asn table
// requests from the /v3/asn endpoint. Allowed values: "peers", "upstreams",
// "downstreams", "routes", "whois_response", or "*" for all of them.
//
// Defaults to empty: only the base ASN fields are fetched. Peers, upstreams,
// downstreams, routes and WHOIS text can be very large for well-connected
// ASNs, so they are strictly opt-in.
ASNInclude []string `json:"asn_include"`
}
Spec holds the configuration for the IPGeolocation source plugin. It is parsed from the user's YAML configuration.
func (*Spec) ASNIncludeModules ¶
ASNIncludeModules returns the normalised list of optional /v3/asn modules selected through asn_include: lower-cased, de-duplicated, "*" expanded, and in canonical order. It returns nil when nothing is selected, and an error naming the valid options when an unknown value is configured.
func (*Spec) IPGeolocationIncludes ¶
IPGeolocationIncludes returns the optional /v3/ipgeo modules to request for the ipgeolocation_ip_geolocation table, in a stable order: security, abuse, geo_accuracy, dma_code, then the hostname mode. It returns nil when none is enabled.
func (*Spec) MaxResponseBytes ¶
func (*Spec) SetDefaults ¶
func (s *Spec) SetDefaults()
SetDefaults populates zero-valued fields with sensible defaults.
func (*Spec) TimeoutDuration ¶
TimeoutDuration parses and returns the configured timeout.