cloudflare

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

internal/cloudflare/interfaces.go

Index

Constants

View Source
const SecretKeyAPIToken = "apiToken"

SecretKeyAPIToken is the Secret data key where the Cloudflare API token is expected.

Variables

View Source
var ErrZoneNotFound = errors.New("zone not found")

ErrZoneNotFound is returned by GetZone when the Cloudflare API responds with 404. Callers can distinguish not-found from transient errors with errors.Is.

Functions

func NewCloudflareClient

func NewCloudflareClient(apiToken string) *cfgo.Client

NewCloudflareClient creates a new Cloudflare API client from an API token.

Types

type BotManagementConfig

type BotManagementConfig struct {
	EnableJS  *bool
	FightMode *bool
}

BotManagementConfig represents bot management settings. Pointer fields allow distinguishing between "unset" and "set to false".

type ClientFactory

type ClientFactory struct {
	// contains filtered or unexported fields
}

ClientFactory creates Cloudflare API clients from Kubernetes Secrets.

func NewClientFactory

func NewClientFactory(k8sClient client.Client) *ClientFactory

NewClientFactory creates a new ClientFactory.

func (*ClientFactory) GetAPIToken

func (f *ClientFactory) GetAPIToken(ctx context.Context, secretName, namespace string) (string, error)

GetAPIToken reads a Cloudflare API token from a Kubernetes Secret.

type DNSClient

type DNSClient interface {
	GetRecord(ctx context.Context, zoneID, recordID string) (*DNSRecord, error)
	ListRecordsByNameAndType(ctx context.Context, zoneID, name, recordType string) ([]DNSRecord, error)
	CreateRecord(ctx context.Context, zoneID string, params DNSRecordParams) (*DNSRecord, error)
	UpdateRecord(ctx context.Context, zoneID, recordID string, params DNSRecordParams) (*DNSRecord, error)
	DeleteRecord(ctx context.Context, zoneID, recordID string) error
}

DNSClient manages Cloudflare DNS records.

func NewDNSClientFromCF

func NewDNSClientFromCF(cf *cfgo.Client) DNSClient

NewDNSClientFromCF creates a DNSClient from a cloudflare-go Client.

type DNSRecord

type DNSRecord struct {
	ID      string
	Name    string
	Type    string
	Content string
	Proxied bool
	TTL     int
	Data    map[string]any
}

DNSRecord represents a Cloudflare DNS record.

type DNSRecordParams

type DNSRecordParams struct {
	Name     string
	Type     string
	Content  string
	Proxied  *bool
	TTL      int
	Priority *int
	Data     map[string]any
}

DNSRecordParams are parameters for creating/updating a DNS record.

type Ruleset

type Ruleset struct {
	ID          string
	Name        string
	Description string
	Phase       string
	Rules       []RulesetRule
}

Ruleset represents a Cloudflare Ruleset.

type RulesetClient

type RulesetClient interface {
	GetRuleset(ctx context.Context, zoneID, rulesetID string) (*Ruleset, error)
	ListRulesetsByPhase(ctx context.Context, zoneID, phase string) ([]Ruleset, error)
	CreateRuleset(ctx context.Context, zoneID string, params RulesetParams) (*Ruleset, error)
	UpdateRuleset(ctx context.Context, zoneID, rulesetID string, params RulesetParams) (*Ruleset, error)
	DeleteRuleset(ctx context.Context, zoneID, rulesetID string) error
}

RulesetClient manages Cloudflare Rulesets.

func NewRulesetClientFromCF

func NewRulesetClientFromCF(cf *cfgo.Client) RulesetClient

NewRulesetClientFromCF creates a RulesetClient from a cloudflare-go Client.

type RulesetParams

type RulesetParams struct {
	Name        string
	Description string
	Phase       string
	Rules       []RulesetRule
}

RulesetParams are parameters for creating/updating a ruleset.

type RulesetRule

type RulesetRule struct {
	ID               string
	Action           string
	Expression       string
	Description      string
	Enabled          bool
	ActionParameters map[string]any
}

RulesetRule is a single rule in a ruleset.

type Tunnel

type Tunnel struct {
	ID   string
	Name string
}

Tunnel represents a Cloudflare Tunnel.

type TunnelClient

type TunnelClient interface {
	GetTunnel(ctx context.Context, accountID, tunnelID string) (*Tunnel, error)
	ListTunnelsByName(ctx context.Context, accountID, name string) ([]Tunnel, error)
	CreateTunnel(ctx context.Context, accountID string, params TunnelParams) (*Tunnel, error)
	DeleteTunnel(ctx context.Context, accountID, tunnelID string) error
}

TunnelClient manages Cloudflare Tunnels.

func NewTunnelClientFromCF

func NewTunnelClientFromCF(cf *cfgo.Client) TunnelClient

NewTunnelClientFromCF creates a TunnelClient from a cloudflare-go Client.

type TunnelParams

type TunnelParams struct {
	Name         string
	TunnelSecret string
}

TunnelParams are parameters for creating a tunnel.

type Zone

type Zone struct {
	ID                  string
	Name                string
	Status              string // initializing, pending, active, moved
	Type                string // full, partial, secondary
	Paused              bool
	NameServers         []string
	OriginalNameServers []string
	OriginalRegistrar   string
	VerificationKey     string
	ActivatedOn         *time.Time
}

Zone represents a Cloudflare Zone (lifecycle information).

type ZoneClient

type ZoneClient interface {
	GetSettings(ctx context.Context, zoneID string) ([]ZoneSetting, error)
	UpdateSetting(ctx context.Context, zoneID, settingID string, value any) error
	GetBotManagement(ctx context.Context, zoneID string) (*BotManagementConfig, error)
	UpdateBotManagement(ctx context.Context, zoneID string, config BotManagementConfig) error
}

ZoneClient manages Cloudflare Zone settings and bot management.

func NewZoneClientFromCF

func NewZoneClientFromCF(cf *cfgo.Client) ZoneClient

NewZoneClientFromCF creates a ZoneClient from a cloudflare-go Client.

type ZoneLifecycleClient

type ZoneLifecycleClient interface {
	CreateZone(ctx context.Context, accountID string, params ZoneLifecycleParams) (*Zone, error)
	GetZone(ctx context.Context, zoneID string) (*Zone, error)
	ListZonesByName(ctx context.Context, accountID, name string) ([]Zone, error)
	EditZone(ctx context.Context, zoneID string, params ZoneLifecycleEditParams) (*Zone, error)
	DeleteZone(ctx context.Context, zoneID string) error
	TriggerActivationCheck(ctx context.Context, zoneID string) error
}

ZoneLifecycleClient manages Cloudflare Zone lifecycle (create/get/list/edit/delete).

func NewZoneLifecycleClientFromCF

func NewZoneLifecycleClientFromCF(cf *cfgo.Client) ZoneLifecycleClient

NewZoneLifecycleClientFromCF creates a ZoneLifecycleClient from a cloudflare-go Client.

type ZoneLifecycleEditParams

type ZoneLifecycleEditParams struct {
	Paused *bool
}

ZoneLifecycleEditParams are parameters for editing a zone.

type ZoneLifecycleParams

type ZoneLifecycleParams struct {
	Name string
	Type string // full, partial, secondary
}

ZoneLifecycleParams are parameters for creating a zone.

type ZoneSetting

type ZoneSetting struct {
	ID    string
	Value any
}

ZoneSetting is a key-value pair for a zone setting.

Jump to

Keyboard shortcuts

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