api

package
v1.16.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 2, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package api implements protocols to update DNS records and WAF lists.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompareWAFList added in v1.16.0

func CompareWAFList(l1, l2 WAFList) int

CompareWAFList compares two WAF lists first by account ID and then by list name.

func DescribeProxyStatus added in v1.16.0

func DescribeProxyStatus(proxied bool) string

DescribeProxyStatus returns a user-facing description of the Cloudflare proxy status.

Types

type Auth

type Auth interface {
	// New uses the authentication information to create a Handle.
	New(ppfmt pp.PP, options HandleOptions) (Handle, bool)

	// CheckUsability performs an early credential usability check.
	//
	// The check is warning-only and should not block startup.
	CheckUsability(ctx context.Context, ppfmt pp.PP)
}

An Auth contains authentication information.

type CloudflareAuth

type CloudflareAuth struct {
	Token   string
	BaseURL string
}

A CloudflareAuth implements the Auth interface, holding the authentication data to create a [cloudflareHandle].

func (CloudflareAuth) CheckUsability added in v1.16.0

func (t CloudflareAuth) CheckUsability(ctx context.Context, ppfmt pp.PP)

CheckUsability performs an early token check and emits warnings for suspicious results while allowing startup to continue.

func (CloudflareAuth) New

func (t CloudflareAuth) New(ppfmt pp.PP, options HandleOptions) (Handle, bool)

New creates a [cloudflareHandle] from the authentication data and handle options.

type DeletionMode added in v1.14.1

type DeletionMode bool

DeletionMode tells the deletion updater whether a careful re-reading of lists must be enforced if an error happens.

const (
	// RegularDeletionMode enables re-reading when an error occurs.
	RegularDeletionMode DeletionMode = false
	// FinalDeletionMode disables re-reading when an error occurs.
	FinalDeletionMode DeletionMode = true
)

type Handle

type Handle interface {
	// ListRecords lists managed DNS records matching the given domain/IP-family scope.
	// The managed-record selector is bound into the handle options because
	// implementations may cache filtered records by domain/IP-family scope.
	//
	// The second return value indicates whether the list was cached.
	ListRecords(ctx context.Context, ppfmt pp.PP, ipFamily ipnet.Family, domain domain.Domain,
		fallbackParams RecordParams,
	) ([]Record, bool, bool)

	// UpdateRecord reconciles one managed DNS record to the desired state.
	//
	// Implementations must apply the desired DNS content and metadata in
	// desiredParams for this record:
	// - content/IP: ip
	// - ttl/proxied/comment/tags: desiredParams
	UpdateRecord(ctx context.Context, ppfmt pp.PP, ipFamily ipnet.Family, domain domain.Domain,
		id ID, ip netip.Addr, desiredParams RecordParams,
	) bool

	// CreateRecord creates one managed DNS record with the given desired metadata.
	// It returns the ID of the new record.
	CreateRecord(ctx context.Context, ppfmt pp.PP, ipFamily ipnet.Family, domain domain.Domain,
		ip netip.Addr, desiredParams RecordParams) (ID, bool)

	// DeleteRecord deletes one managed DNS record by ID.
	//
	// mode controls cache invalidation behavior for failure handling.
	DeleteRecord(ctx context.Context, ppfmt pp.PP, ipFamily ipnet.Family,
		domain domain.Domain, id ID, mode DeletionMode,
	) bool

	// ListWAFListItems returns managed WAF list items with their IP ranges.
	// It does not create the list if it does not exist.
	//
	// The managed-item selector is bound into the handle options because
	// implementations may cache filtered items by WAF-list scope.
	// fallbackItemComment is the fallback comment target for newly created
	// managed list items; implementations may use it for advisory mismatch hints.
	//
	// The second return value indicates whether the list already exists.
	// The third return value indicates whether the list content was cached.
	ListWAFListItems(ctx context.Context, ppfmt pp.PP, list WAFList, fallbackDescription, fallbackItemComment string,
	) ([]WAFListItem, bool, bool, bool)

	// FinalCleanWAFList removes managed WAF content during shutdown.
	// Implementations choose whole-list or managed-item cleanup from the handle's
	// bound ownership policy and the in-scope family set for the run.
	//
	// The handle should not be reused for any further update operations after
	// calling this method.
	FinalCleanWAFList(ctx context.Context, ppfmt pp.PP, list WAFList,
		fallbackDescription string, managedFamilies map[ipnet.Family]bool,
	) WAFListCleanupCode

	// DeleteWAFListItems deletes managed WAF list items by item IDs.
	DeleteWAFListItems(ctx context.Context, ppfmt pp.PP, list WAFList, fallbackDescription string, ids []ID) bool

	// CreateWAFListItems creates managed WAF list items with the given prefixes
	// and per-item comments.
	CreateWAFListItems(ctx context.Context, ppfmt pp.PP, list WAFList, fallbackDescription string,
		items []WAFListCreateItem) bool
}

A Handle represents a generic API to update DNS records and WAF lists. Currently, the only implementation is Cloudflare.

type HandleOptions added in v1.16.0

type HandleOptions struct {
	HandleOwnershipPolicy

	CacheExpiration time.Duration
}

HandleOptions bundles handle-scoped settings that affect cache correctness and other per-handle behavior.

type HandleOwnershipPolicy added in v1.16.0

type HandleOwnershipPolicy struct {
	ManagedRecordsCommentRegex        *regexp.Regexp
	ManagedWAFListItemsCommentRegex   *regexp.Regexp
	AllowWholeWAFListDeleteOnShutdown bool
}

HandleOwnershipPolicy bundles the handle-bound ownership selectors and shutdown authority that affect cache correctness and WAF cleanup behavior.

func (HandleOwnershipPolicy) MatchManagedRecordComment added in v1.16.0

func (p HandleOwnershipPolicy) MatchManagedRecordComment(comment string) bool

MatchManagedRecordComment reports whether a DNS record comment is in scope.

func (HandleOwnershipPolicy) MatchManagedWAFListItemComment added in v1.16.0

func (p HandleOwnershipPolicy) MatchManagedWAFListItemComment(comment string) bool

MatchManagedWAFListItemComment reports whether a WAF item comment is in scope.

func (HandleOwnershipPolicy) Sanitize added in v1.16.0

Sanitize normalizes contradictory ownership settings and logs advisories.

type ID added in v1.14.0

type ID string

ID is a new type representing identifiers to avoid programming mistakes.

func (ID) String added in v1.14.1

func (id ID) String() string

type Record added in v1.14.0

type Record struct {
	ID           ID
	IP           netip.Addr
	RecordParams //nolint:embeddedstructfieldcheck // parameters go last
}

Record represents a DNS record.

type RecordParams added in v1.16.0

type RecordParams struct {
	TTL     TTL
	Proxied bool
	Comment string
	Tags    []string
}

RecordParams bundles parameters of a DNS record.

type TTL

type TTL int

A TTL represents a time-to-live value of a DNS record.

const TTLAuto TTL = 1

TTLAuto represents Cloudflare's "automatic" TTL sentinel value.

func (TTL) Describe

func (t TTL) Describe() string

Describe converts a TTL into a human-readable, user-friendly description that is suitable for printing.

func (TTL) Int

func (t TTL) Int() int

Int converts a TTL into its raw integer value.

func (TTL) String

func (t TTL) String() string

String converts a TTL into the string representation of its raw integer value.

type WAFList added in v1.14.0

type WAFList struct {
	AccountID ID
	Name      string
}

WAFList represents a WAF list to update.

func (WAFList) Describe added in v1.14.0

func (l WAFList) Describe() string

Describe formats WAFList as a string.

type WAFListCleanupCode added in v1.16.0

type WAFListCleanupCode int

WAFListCleanupCode summarizes final shutdown cleanup for one WAF list.

const (
	// WAFListCleanupNoop means the managed WAF content was already gone.
	WAFListCleanupNoop WAFListCleanupCode = iota

	// WAFListCleanupUpdated means the managed WAF content was removed synchronously.
	WAFListCleanupUpdated

	// WAFListCleanupUpdating means WAF cleanup was started asynchronously.
	WAFListCleanupUpdating

	// WAFListCleanupFailed means shutdown cleanup did not finish successfully.
	WAFListCleanupFailed
)

type WAFListCreateItem added in v1.16.0

type WAFListCreateItem struct {
	Prefix  netip.Prefix
	Comment string
}

WAFListCreateItem represents one WAF list item to create.

type WAFListItem added in v1.14.0

type WAFListItem struct {
	ID      ID
	Prefix  netip.Prefix
	Comment string
}

WAFListItem represents one WAF list item: ID, IP range, and original comment.

Directories

Path Synopsis
Package tags provides helpers for Cloudflare DNS record tags.
Package tags provides helpers for Cloudflare DNS record tags.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL