cloudflare

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2025 License: MIT Imports: 10 Imported by: 56

README

Cloudflare for libdns

godoc reference

This package implements the libdns interfaces for Cloudflare.

Authenticating

[!IMPORTANT] This package supports API token authentication (as opposed to legacy API keys).

There are two approaches for token permissions supported by this package:

  1. Single token for everything
    • APIToken permissions required: Zone:Read, Zone.DNS:Write - All zones
  2. Dual token method
    • ZoneToken permissions required: Zone:Read - All zones
    • APIToken permissions required: Zone.DNS:Write - for the zone(s) you wish to manage

The dual token method allows users who have multiple DNS zones in their Cloudflare account to restrict which zones the token can access, whereas the first method will allow access to all DNS Zones. If you only have one domain/zone then this approach does not provide any benefit, and you might as well just have the single API token

To use the dual token approach simply ensure that the ZoneToken property is provided - otherwise the package will use APIToken for all API requests.

To clarify, do NOT use API keys, which are globally-scoped:

Don't use API keys

DO use scoped API tokens:

Don't use API keys

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider struct {
	// API tokens are used for authentication. Make sure to use
	// scoped API **tokens**, NOT a global API **key**.
	APIToken  string `json:"api_token,omitempty"`  // API token with Zone.DNS:Write (can be scoped to single Zone if ZoneToken is also provided)
	ZoneToken string `json:"zone_token,omitempty"` // Optional Zone:Read token (global scope)
	// contains filtered or unexported fields
}

Provider implements the libdns interfaces for Cloudflare. TODO: Support pagination and retries, handle rate limits.

func (*Provider) AppendRecords

func (p *Provider) AppendRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)

AppendRecords adds records to the zone. It returns the records that were added.

func (*Provider) DeleteRecords

func (p *Provider) DeleteRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)

DeleteRecords deletes the records from the zone. If a record does not have an ID, it will be looked up. It returns the records that were deleted.

func (*Provider) GetRecords

func (p *Provider) GetRecords(ctx context.Context, zone string) ([]libdns.Record, error)

GetRecords lists all the records in the zone.

func (*Provider) SetRecords

func (p *Provider) SetRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)

SetRecords sets the records in the zone, either by updating existing records or creating new ones. It returns the updated records.

Jump to

Keyboard shortcuts

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