cloudflare

package module
Version: v0.55.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2022 License: BSD-3-Clause Imports: 28 Imported by: 590

README

cloudflare-go

Go Reference Test Go Report Card

Note: This library is under active development as we expand it to cover our (expanding!) API. Consider the public API of this package a little unstable as we work towards a v1.0.

A Go library for interacting with Cloudflare's API v4. This library allows you to:

  • Manage and automate changes to your DNS records within Cloudflare
  • Manage and automate changes to your zones (domains) on Cloudflare, including adding new zones to your account
  • List and modify the status of WAF (Web Application Firewall) rules for your zones
  • Fetch Cloudflare's IP ranges for automating your firewall whitelisting

A command-line client, flarectl, is also available as part of this project.

Features

The current feature list includes:

  • Cache purging
  • Cloudflare IPs
  • Custom hostnames
  • DNS Firewall
  • DNS Records
  • Firewall (partial)
  • Gateway Locations
  • Keyless SSL
  • Load Balancing
  • Logpush Jobs
  • Magic Transit / Magic WAN
  • Notifications
  • Organization Administration
  • Origin CA
  • Railgun administration
  • Rate Limiting
  • User Administration (partial)
  • Web Application Firewall (WAF)
  • Workers KV
  • Zone cache settings
  • Zone Lockdown and User-Agent Block rules
  • Zones
  • Managed Headers

Pull Requests are welcome, but please open an issue (or comment in an existing issue) to discuss any non-trivial changes before submitting code.

Installation

You need a working Go environment. We officially support only currently supported Go versions according to Go project's release policy.

go get github.com/cloudflare/cloudflare-go

Getting Started

package main

import (
	"context"
	"fmt"
	"log"
	"os"

	"github.com/cloudflare/cloudflare-go"
)

func main() {
	// Construct a new API object using a global API key
	api, err := cloudflare.New(os.Getenv("CLOUDFLARE_API_KEY"), os.Getenv("CLOUDFLARE_API_EMAIL"))
	// alternatively, you can use a scoped API token
	// api, err := cloudflare.NewWithAPIToken(os.Getenv("CLOUDFLARE_API_TOKEN"))
	if err != nil {
		log.Fatal(err)
	}

	// Most API calls require a Context
	ctx := context.Background()

	// Fetch user details on the account
	u, err := api.UserDetails(ctx)
	if err != nil {
		log.Fatal(err)
	}
	// Print user details
	fmt.Println(u)

	// Fetch the zone ID
	id, err := api.ZoneIDByName("example.com") // Assuming example.com exists in your Cloudflare account already
	if err != nil {
		log.Fatal(err)
	}

	// Fetch zone details
	zone, err := api.ZoneDetails(ctx, id)
	if err != nil {
		log.Fatal(err)
	}
	// Print zone details
	fmt.Println(zone)
}

Also refer to the API documentation for how to use this package in-depth.

Experimental improvements

This library is starting to ship with experimental improvements that are not yet ready for production but will be introduced before the next major version. See experimental README for full details.

License

BSD licensed. See the LICENSE file for details.

Documentation

Overview

Package cloudflare implements the Cloudflare v4 API.

File contains helper methods for accepting variants (pointers, values, slices, etc) of a particular type and returning them in another. A common use is pointer to values and back.

_Most_ follow the convention of (where <type> is a Golang type such as Bool):

<type>Ptr: Accepts a value and returns a pointer. <type>: Accepts a pointer and returns a value. <type>PtrSlice: Accepts a slice of values and returns a slice of pointers. <type>Slice: Accepts a slice of pointers and returns a slice of values. <type>PtrMap: Accepts a string map of values into a string map of pointers. <type>Map: Accepts a string map of pointers into a string map of values.

Not all Golang types are covered here, only those that are commonly used.

Example
package main

import (
	"context"
	"fmt"

	cloudflare "github.com/cloudflare/cloudflare-go"
)

const (
	user   = "cloudflare@example.org"
	domain = "example.com"
	apiKey = "deadbeef"
)

func main() {
	api, err := cloudflare.New("deadbeef", "cloudflare@example.org")
	if err != nil {
		fmt.Println(err)
		return
	}

	// Fetch the zone ID for zone example.org
	zoneID, err := api.ZoneIDByName("example.org")
	if err != nil {
		fmt.Println(err)
		return
	}

	// Fetch all DNS records for example.org
	records, err := api.DNSRecords(context.Background(), zoneID, cloudflare.DNSRecord{})
	if err != nil {
		fmt.Println(err)
		return
	}

	for _, r := range records {
		fmt.Printf("%s: %s\n", r.Name, r.Content)
	}
}
Output:

Index

Examples

Constants

View Source
const (
	// AuthKeyEmail specifies that we should authenticate with API key and email address.
	AuthKeyEmail = 1 << iota
	// AuthUserService specifies that we should authenticate with a User-Service key.
	AuthUserService
	// AuthToken specifies that we should authenticate with an API Token.
	AuthToken
)
View Source
const (
	// ListTypeIP specifies a list containing IP addresses.
	ListTypeIP = "ip"
	// ListTypeRedirect specifies a list containing redirects.
	ListTypeRedirect = "redirect"
)
View Source
const (
	// MagicFirewallRulesetKindRoot specifies a root Ruleset.
	MagicFirewallRulesetKindRoot = "root"

	// MagicFirewallRulesetPhaseMagicTransit specifies the Magic Transit Ruleset phase.
	MagicFirewallRulesetPhaseMagicTransit = "magic_transit"

	// MagicFirewallRulesetRuleActionSkip specifies a skip (allow) action.
	MagicFirewallRulesetRuleActionSkip MagicFirewallRulesetRuleAction = "skip"

	// MagicFirewallRulesetRuleActionBlock specifies a block action.
	MagicFirewallRulesetRuleActionBlock MagicFirewallRulesetRuleAction = "block"
)
View Source
const (
	RulesetKindCustom  RulesetKind = "custom"
	RulesetKindManaged RulesetKind = "managed"
	RulesetKindRoot    RulesetKind = "root"
	RulesetKindSchema  RulesetKind = "schema"
	RulesetKindZone    RulesetKind = "zone"

	RulesetPhaseDDoSL4                              RulesetPhase = "ddos_l4"
	RulesetPhaseDDoSL7                              RulesetPhase = "ddos_l7"
	RulesetPhaseHTTPCustomErrors                    RulesetPhase = "http_custom_errors"
	RulesetPhaseHTTPLogCustomFields                 RulesetPhase = "http_log_custom_fields"
	RulesetPhaseHTTPRequestCacheSettings            RulesetPhase = "http_request_cache_settings"
	RulesetPhaseHTTPRequestFirewallCustom           RulesetPhase = "http_request_firewall_custom"
	RulesetPhaseHTTPRequestFirewallManaged          RulesetPhase = "http_request_firewall_managed"
	RulesetPhaseHTTPRequestLateTransform            RulesetPhase = "http_request_late_transform"
	RulesetPhaseHTTPRequestLateTransformManaged     RulesetPhase = "http_request_late_transform_managed"
	RulesetPhaseHTTPRequestMain                     RulesetPhase = "http_request_main"
	RulesetPhaseHTTPRequestOrigin                   RulesetPhase = "http_request_origin"
	RulesetPhaseHTTPRequestDynamicRedirect          RulesetPhase = "http_request_dynamic_redirect" //nolint:gosec
	RulesetPhaseHTTPRequestRedirect                 RulesetPhase = "http_request_redirect"
	RulesetPhaseHTTPRequestSanitize                 RulesetPhase = "http_request_sanitize"
	RulesetPhaseHTTPRequestTransform                RulesetPhase = "http_request_transform"
	RulesetPhaseHTTPResponseFirewallManaged         RulesetPhase = "http_response_firewall_managed"
	RulesetPhaseHTTPResponseHeadersTransform        RulesetPhase = "http_response_headers_transform"
	RulesetPhaseHTTPResponseHeadersTransformManaged RulesetPhase = "http_response_headers_transform_managed"
	RulesetPhaseMagicTransit                        RulesetPhase = "magic_transit"
	RulesetPhaseRateLimit                           RulesetPhase = "http_ratelimit"
	RulesetPhaseSuperBotFightMode                   RulesetPhase = "http_request_sbfm"
	RulesetPhaseHTTPConfigSettings                  RulesetPhase = "http_config_settings"

	RulesetRuleActionBlock                RulesetRuleAction = "block"
	RulesetRuleActionChallenge            RulesetRuleAction = "challenge"
	RulesetRuleActionDDoSDynamic          RulesetRuleAction = "ddos_dynamic"
	RulesetRuleActionExecute              RulesetRuleAction = "execute"
	RulesetRuleActionForceConnectionClose RulesetRuleAction = "force_connection_close"
	RulesetRuleActionJSChallenge          RulesetRuleAction = "js_challenge"
	RulesetRuleActionLog                  RulesetRuleAction = "log"
	RulesetRuleActionLogCustomField       RulesetRuleAction = "log_custom_field"
	RulesetRuleActionManagedChallenge     RulesetRuleAction = "managed_challenge"
	RulesetRuleActionRedirect             RulesetRuleAction = "redirect"
	RulesetRuleActionRewrite              RulesetRuleAction = "rewrite"
	RulesetRuleActionRoute                RulesetRuleAction = "route"
	RulesetRuleActionScore                RulesetRuleAction = "score"
	RulesetRuleActionSetCacheSettings     RulesetRuleAction = "set_cache_settings"
	RulesetRuleActionSetConfig            RulesetRuleAction = "set_config"
	RulesetRuleActionServeError           RulesetRuleAction = "serve_error"
	RulesetRuleActionSkip                 RulesetRuleAction = "skip"

	RulesetActionParameterProductBIC           RulesetActionParameterProduct = "bic"
	RulesetActionParameterProductHOT           RulesetActionParameterProduct = "hot"
	RulesetActionParameterProductRateLimit     RulesetActionParameterProduct = "ratelimit"
	RulesetActionParameterProductSecurityLevel RulesetActionParameterProduct = "securityLevel"
	RulesetActionParameterProductUABlock       RulesetActionParameterProduct = "uablock"
	RulesetActionParameterProductWAF           RulesetActionParameterProduct = "waf"
	RulesetActionParameterProductZoneLockdown  RulesetActionParameterProduct = "zonelockdown"

	RulesetRuleActionParametersHTTPHeaderOperationRemove RulesetRuleActionParametersHTTPHeaderOperation = "remove"
	RulesetRuleActionParametersHTTPHeaderOperationSet    RulesetRuleActionParametersHTTPHeaderOperation = "set"
)
View Source
const (
	// IPListTypeIP specifies a list containing IP addresses.
	IPListTypeIP = "ip"
)

Variables

View Source
var (
	ErrAPIKeysAndTokensAreMutuallyExclusive   = errors.New(errAPIKeysAndTokensAreMutuallyExclusive)
	ErrMissingCredentials                     = errors.New(errMissingCredentials)
	ErrMissingAccountID                       = errors.New(errMissingAccountID)
	ErrMissingZoneID                          = errors.New(errMissingZoneID)
	ErrAccountIDOrZoneIDAreRequired           = errors.New(errMissingAccountOrZoneID)
	ErrAccountIDAndZoneIDAreMutuallyExclusive = errors.New(errAccountIDAndZoneIDAreMutuallyExclusive)
	ErrMissingResourceIdentifier              = errors.New(errMissingResourceIdentifier)
)
View Source
var (
	ErrMissingPoolID         = errors.New("missing required pool ID")
	ErrMissingMonitorID      = errors.New("missing required monitor ID")
	ErrMissingLoadBalancerID = errors.New("missing required load balancer ID")
)
View Source
var (
	// ErrMissingIP is for when ipv4 or ipv6 indicator was given but ip is missing.
	ErrMissingIP = errors.New("ip is required when using 'ipv4' or 'ipv6' indicator type and is missing")
	// ErrMissingURL is for when url or domain indicator was given but url is missing.
	ErrMissingURL = errors.New("url is required when using 'domain' or 'url' indicator type and is missing")
)
View Source
var (
	ErrMissingProjectName  = errors.New("required missing project name")
	ErrMissingDeploymentID = errors.New("required missing deployment ID")
	ErrMissingStageName    = errors.New("required missing stage name")
)
View Source
var (
	ErrMissingQueueName         = errors.New("required queue name is missing")
	ErrMissingQueueConsumerName = errors.New("required queue consumer name is missing")
)
View Source
var (
	// ErrMissingUploadURL is for when a URL is required but missing.
	ErrMissingUploadURL = errors.New("required url missing")
	// ErrMissingMaxDuration is for when MaxDuration is required but missing.
	ErrMissingMaxDuration = errors.New("required max duration missing")
	// ErrMissingVideoID is for when VideoID is required but missing.
	ErrMissingVideoID = errors.New("required video id missing")
	// ErrMissingFilePath is for when FilePath is required but missing.
	ErrMissingFilePath = errors.New("required file path missing")
)
View Source
var (
	ErrSTSFailure               = errors.New("failed to fetch security token")
	ErrSTSHTTPFailure           = errors.New("failed making securtiy token issuer call")
	ErrSTSHTTPResponseError     = errors.New("security token request returned a failure")
	ErrSTSMissingServiceSecret  = errors.New("service secret missing but is required")
	ErrSTSMissingServiceTag     = errors.New("service tag missing but is required")
	ErrSTSMissingIssuerHostname = errors.New("issuer hostname missing but is required")
	ErrSTSMissingServicePath    = errors.New("issuer path missing but is required")
)
View Source
var (
	ErrMissingNetwork      = errors.New("missing required network parameter")
	ErrInvalidNetworkValue = errors.New("invalid IP parameter. Cannot use CIDR ranges for this endpoint.")
)
View Source
var (
	ErrMissingWaitingRoomID     = errors.New("missing required waiting room ID")
	ErrMissingWaitingRoomRuleID = errors.New("missing required waiting room rule ID")
)
View Source
var (
	// ErrMissingIdentifier is for when identifier is required but missing.
	ErrMissingIdentifier = errors.New("identifier required but missing")
	// ErrMissingName is for when name is required but missing.
	ErrMissingName = errors.New("name required but missing")
	// ErrMissingTarget is for when target is required but missing.
	ErrMissingTarget = errors.New("target required but missing")
)
View Source
var (
	ErrMissingHostname    = errors.New("required hostname missing")
	ErrMissingService     = errors.New("required service missing")
	ErrMissingEnvironment = errors.New("required environment missing")
)
View Source
var (
	ErrMissingScriptName = errors.New("required script name missing")
	ErrMissingTailID     = errors.New("required tail id missing")
)
View Source
var ErrMissingASN = errors.New("required asn missing")

ErrMissingASN is for when ASN is required but not set.

View Source
var (
	ErrMissingBucketName = errors.New("require bucket name missing")
)
View Source
var ErrMissingDomain = errors.New("required domain missing")

ErrMissingDomain is for when domain is needed but not given.

View Source
var ErrMissingListID = errors.New("required missing list ID")
View Source
var ErrMissingMemberRolesOrPolicies = errors.New(errMissingMemberRolesOrPolicies)
View Source
var ErrMissingPermissionGroupID = errors.New(errMissingPermissionGroupID)
View Source
var (
	ErrMissingProfileID = errors.New("missing required profile ID")
)
View Source
var ErrMissingRuleID = errors.New("required rule id missing")
View Source
var ErrMissingTunnelID = errors.New("required missing tunnel ID")

ErrMissingTunnelID is for when a required tunnel ID is missing from the parameters.

View Source
var ErrMissingVnetName = errors.New("required missing virtual network name")
View Source
var ErrNotEnoughFilterIDsProvided = errors.New("at least one filter ID must be provided.")
View Source
var ErrOriginPortInvalid = errors.New("invalid origin port")

ErrOriginPortInvalid is a common error for failing to parse a single port or port range.

View Source
var PageRuleActions = map[string]string{
	"always_online":               "Always Online",
	"always_use_https":            "Always Use HTTPS",
	"automatic_https_rewrites":    "Automatic HTTPS Rewrites",
	"browser_cache_ttl":           "Browser Cache TTL",
	"browser_check":               "Browser Integrity Check",
	"bypass_cache_on_cookie":      "Bypass Cache on Cookie",
	"cache_by_device_type":        "Cache By Device Type",
	"cache_deception_armor":       "Cache Deception Armor",
	"cache_level":                 "Cache Level",
	"cache_key_fields":            "Custom Cache Key",
	"cache_on_cookie":             "Cache On Cookie",
	"disable_apps":                "Disable Apps",
	"disable_performance":         "Disable Performance",
	"disable_railgun":             "Disable Railgun",
	"disable_security":            "Disable Security",
	"edge_cache_ttl":              "Edge Cache TTL",
	"email_obfuscation":           "Email Obfuscation",
	"explicit_cache_control":      "Origin Cache Control",
	"forwarding_url":              "Forwarding URL",
	"host_header_override":        "Host Header Override",
	"ip_geolocation":              "IP Geolocation Header",
	"minify":                      "Minify",
	"mirage":                      "Mirage",
	"opportunistic_encryption":    "Opportunistic Encryption",
	"origin_error_page_pass_thru": "Origin Error Page Pass-thru",
	"polish":                      "Polish",
	"resolve_override":            "Resolve Override",
	"respect_strong_etag":         "Respect Strong ETags",
	"response_buffering":          "Response Buffering",
	"rocket_loader":               "Rocker Loader",
	"security_level":              "Security Level",
	"server_side_exclude":         "Server Side Excludes",
	"sort_query_string_for_cache": "Query String Sort",
	"ssl":                         "SSL",
	"true_client_ip_header":       "True Client IP Header",
	"waf":                         "Web Application Firewall",
}

PageRuleActions maps API action IDs to human-readable strings.

View Source
var (
	Version string = "v4"
)

Functions

func AnyPtr added in v0.35.0

func AnyPtr(v interface{}) interface{}

AnyPtr is a helper routine that allocates a new interface value to store v and returns a pointer to it.

Usage: var _ *Type = AnyPtr(Type(value) | value).(*Type)

var _ *bool = AnyPtr(true).(*bool)
var _ *byte = AnyPtr(byte(1)).(*byte)
var _ *complex64 = AnyPtr(complex64(1.1)).(*complex64)
var _ *complex128 = AnyPtr(complex128(1.1)).(*complex128)
var _ *float32 = AnyPtr(float32(1.1)).(*float32)
var _ *float64 = AnyPtr(float64(1.1)).(*float64)
var _ *int = AnyPtr(int(1)).(*int)
var _ *int8 = AnyPtr(int8(8)).(*int8)
var _ *int16 = AnyPtr(int16(16)).(*int16)
var _ *int32 = AnyPtr(int32(32)).(*int32)
var _ *int64 = AnyPtr(int64(64)).(*int64)
var _ *rune = AnyPtr(rune(1)).(*rune)
var _ *string = AnyPtr("ptr").(*string)
var _ *uint = AnyPtr(uint(1)).(*uint)
var _ *uint8 = AnyPtr(uint8(8)).(*uint8)
var _ *uint16 = AnyPtr(uint16(16)).(*uint16)
var _ *uint32 = AnyPtr(uint32(32)).(*uint32)
var _ *uint64 = AnyPtr(uint64(64)).(*uint64)

func Bool added in v0.36.0

func Bool(v *bool) bool

Bool is a helper routine that accepts a bool pointer and returns a value to it.

func BoolMap added in v0.36.0

func BoolMap(src map[string]*bool) map[string]bool

BoolMap converts a string map of bool pointers into a string map of bool values.

func BoolPtr added in v0.35.0

func BoolPtr(v bool) *bool

BoolPtr is a helper routine that allocates a new bool value to store v and returns a pointer to it.

func BoolPtrMap added in v0.35.0

func BoolPtrMap(src map[string]bool) map[string]*bool

BoolPtrMap converts a string map of bool values into a string map of bool pointers.

func BoolPtrSlice added in v0.35.0

func BoolPtrSlice(src []bool) []*bool

BoolPtrSlice converts a slice of bool values into a slice of bool pointers.

func BoolSlice added in v0.36.0

func BoolSlice(src []*bool) []bool

BoolSlice converts a slice of bool pointers into a slice of bool values.

func Byte added in v0.36.0

func Byte(v *byte) byte

Byte is a helper routine that accepts a byte pointer and returns a value to it.

func BytePtr added in v0.35.0

func BytePtr(v byte) *byte

BytePtr is a helper routine that allocates a new byte value to store v and returns a pointer to it.

func Complex128 added in v0.36.0

func Complex128(v *complex128) complex128

Complex128 is a helper routine that accepts a complex128 pointer and returns a value to it.

func Complex128Ptr added in v0.35.0

func Complex128Ptr(v complex128) *complex128

Complex128Ptr is a helper routine that allocates a new complex128 value to store v and returns a pointer to it.

func Complex64 added in v0.36.0

func Complex64(v *complex64) complex64

Complex64 is a helper routine that accepts a complex64 pointer and returns a value to it.

func Complex64Ptr added in v0.35.0

func Complex64Ptr(v complex64) *complex64

Complex64Ptr is a helper routine that allocates a new complex64 value to store v and returns a pointer to it.

func DurationPtr added in v0.35.0

func DurationPtr(v time.Duration) *time.Duration

DurationPtr is a helper routine that allocates a new time.Duration value to store v and returns a pointer to it.

func Float32 added in v0.36.0

func Float32(v *float32) float32

Float32 is a helper routine that accepts a float32 pointer and returns a value to it.

func Float32Map added in v0.36.0

func Float32Map(src map[string]*float32) map[string]float32

Float32Map converts a string map of float32 pointers into a string map of float32 values.

func Float32Ptr added in v0.35.0

func Float32Ptr(v float32) *float32

Float32Ptr is a helper routine that allocates a new float32 value to store v and returns a pointer to it.

func Float32PtrMap added in v0.35.0

func Float32PtrMap(src map[string]float32) map[string]*float32

Float32PtrMap converts a string map of float32 values into a string map of float32 pointers.

func Float32PtrSlice added in v0.35.0

func Float32PtrSlice(src []float32) []*float32

Float32PtrSlice converts a slice of float32 values into a slice of float32 pointers.

func Float32Slice added in v0.36.0

func Float32Slice(src []*float32) []float32

Float32Slice converts a slice of float32 pointers into a slice of float32 values.

func Float64 added in v0.36.0

func Float64(v *float64) float64

Float64 is a helper routine that accepts a float64 pointer and returns a value to it.

func Float64Map added in v0.36.0

func Float64Map(src map[string]*float64) map[string]float64

Float64Map converts a string map of float64 pointers into a string map of float64 values.

func Float64Ptr added in v0.35.0

func Float64Ptr(v float64) *float64

Float64Ptr is a helper routine that allocates a new float64 value to store v and returns a pointer to it.

func Float64PtrMap added in v0.35.0

func Float64PtrMap(src map[string]float64) map[string]*float64

Float64PtrMap converts a string map of float64 values into a string map of float64 pointers.

func Float64PtrSlice added in v0.35.0

func Float64PtrSlice(src []float64) []*float64

Float64PtrSlice converts a slice of float64 values into a slice of float64 pointers.

func Float64Slice added in v0.36.0

func Float64Slice(src []*float64) []float64

Float64Slice converts a slice of float64 pointers into a slice of float64 values.

func Int added in v0.36.0

func Int(v *int) int

Int is a helper routine that accepts a int pointer and returns a value to it.

func Int16 added in v0.36.0

func Int16(v *int16) int16

Int16 is a helper routine that accepts a int16 pointer and returns a value to it.

func Int16Map added in v0.36.0

func Int16Map(src map[string]*int16) map[string]int16

Int16Map converts a string map of int16 pointers into a string map of int16 values.

func Int16Ptr added in v0.35.0

func Int16Ptr(v int16) *int16

Int16Ptr is a helper routine that allocates a new int16 value to store v and returns a pointer to it.

func Int16PtrMap added in v0.35.0

func Int16PtrMap(src map[string]int16) map[string]*int16

Int16PtrMap converts a string map of int16 values into a string map of int16 pointers.

func Int16PtrSlice added in v0.35.0

func Int16PtrSlice(src []int16) []*int16

Int16PtrSlice converts a slice of int16 values into a slice of int16 pointers.

func Int16Slice added in v0.36.0

func Int16Slice(src []*int16) []int16

Int16Slice converts a slice of int16 pointers into a slice of int16 values.

func Int32 added in v0.36.0

func Int32(v *int32) int32

Int32 is a helper routine that accepts a int32 pointer and returns a value to it.

func Int32Map added in v0.36.0

func Int32Map(src map[string]*int32) map[string]int32

Int32Map converts a string map of int32 pointers into a string map of int32 values.

func Int32Ptr added in v0.35.0

func Int32Ptr(v int32) *int32

Int32Ptr is a helper routine that allocates a new int32 value to store v and returns a pointer to it.

func Int32PtrMap added in v0.35.0

func Int32PtrMap(src map[string]int32) map[string]*int32

Int32PtrMap converts a string map of int32 values into a string map of int32 pointers.

func Int32PtrSlice added in v0.35.0

func Int32PtrSlice(src []int32) []*int32

Int32PtrSlice converts a slice of int32 values into a slice of int32 pointers.

func Int32Slice added in v0.36.0

func Int32Slice(src []*int32) []int32

Int32Slice converts a slice of int32 pointers into a slice of int32 values.

func Int64 added in v0.36.0

func Int64(v *int64) int64

Int64 is a helper routine that accepts a int64 pointer and returns a value to it.

func Int64Map added in v0.36.0

func Int64Map(src map[string]*int64) map[string]int64

Int64Map converts a string map of int64 pointers into a string map of int64 values.

func Int64Ptr added in v0.35.0

func Int64Ptr(v int64) *int64

Int64Ptr is a helper routine that allocates a new int64 value to store v and returns a pointer to it.

func Int64PtrMap added in v0.35.0

func Int64PtrMap(src map[string]int64) map[string]*int64

Int64PtrMap converts a string map of int64 values into a string map of int64 pointers.

func Int64PtrSlice added in v0.35.0

func Int64PtrSlice(src []int64) []*int64

Int64PtrSlice converts a slice of int64 values into a slice of int64 pointers.

func Int64Slice added in v0.36.0

func Int64Slice(src []*int64) []int64

Int64Slice converts a slice of int64 pointers into a slice of int64 values.

func Int8 added in v0.36.0

func Int8(v *int8) int8

Int8 is a helper routine that accepts a int8 pointer and returns a value to it.

func Int8Map added in v0.36.0

func Int8Map(src map[string]*int8) map[string]int8

Int8Map converts a string map of int8 pointers into a string map of int8 values.

func Int8Ptr added in v0.35.0

func Int8Ptr(v int8) *int8

Int8Ptr is a helper routine that allocates a new int8 value to store v and returns a pointer to it.

func Int8PtrMap added in v0.35.0

func Int8PtrMap(src map[string]int8) map[string]*int8

Int8PtrMap converts a string map of int8 values into a string map of int8 pointers.

func Int8PtrSlice added in v0.35.0

func Int8PtrSlice(src []int8) []*int8

Int8PtrSlice converts a slice of int8 values into a slice of int8 pointers.

func Int8Slice added in v0.36.0

func Int8Slice(src []*int8) []int8

Int8Slice converts a slice of int8 pointers into a slice of int8 values.

func IntMap added in v0.36.0

func IntMap(src map[string]*int) map[string]int

IntMap converts a string map of int pointers into a string map of int values.

func IntPtr added in v0.35.0

func IntPtr(v int) *int

IntPtr is a helper routine that allocates a new int value to store v and returns a pointer to it.

func IntPtrMap added in v0.35.0

func IntPtrMap(src map[string]int) map[string]*int

IntPtrMap converts a string map of int values into a string map of int pointers.

func IntPtrSlice added in v0.35.0

func IntPtrSlice(src []int) []*int

IntPtrSlice converts a slice of int values into a slice of int pointers.

func IntSlice added in v0.36.0

func IntSlice(src []*int) []int

IntSlice converts a slice of int pointers into a slice of int values.

func OriginCARootCertificate added in v0.20.0

func OriginCARootCertificate(algorithm string) ([]byte, error)

Gets the Cloudflare Origin CA Root Certificate for a given algorithm in PEM format. Algorithm must be one of ['ecc', 'rsa'].

func RulesetActionParameterProductValues added in v0.19.0

func RulesetActionParameterProductValues() []string

RulesetActionParameterProductValues exposes all the available `RulesetActionParameterProduct` values as a slice of strings.

func RulesetKindValues added in v0.19.0

func RulesetKindValues() []string

RulesetKindValues exposes all the available `RulesetKind` values as a slice of strings.

func RulesetPhaseValues added in v0.19.0

func RulesetPhaseValues() []string

RulesetPhaseValues exposes all the available `RulesetPhase` values as a slice of strings.

func RulesetRuleActionParametersHTTPHeaderOperationValues added in v0.19.0

func RulesetRuleActionParametersHTTPHeaderOperationValues() []string

func RulesetRuleActionValues added in v0.19.0

func RulesetRuleActionValues() []string

RulesetRuleActionValues exposes all the available `RulesetRuleAction` values as a slice of strings.

func Rune added in v0.36.0

func Rune(v *rune) rune

Rune is a helper routine that accepts a rune pointer and returns a value to it.

func RunePtr added in v0.35.0

func RunePtr(v rune) *rune

RunePtr is a helper routine that allocates a new rune value to store v and returns a pointer to it.

func String added in v0.36.0

func String(v *string) string

String is a helper routine that accepts a string pointer and returns a value to it.

func StringMap added in v0.36.0

func StringMap(src map[string]*string) map[string]string

StringMap converts a string map of string pointers into a string map of string values.

func StringPtr added in v0.35.0

func StringPtr(v string) *string

StringPtr is a helper routine that allocates a new string value to store v and returns a pointer to it.

func StringPtrMap added in v0.35.0

func StringPtrMap(src map[string]string) map[string]*string

StringPtrMap converts a string map of string values into a string map of string pointers.

func StringPtrSlice added in v0.35.0

func StringPtrSlice(src []string) []*string

StringPtrSlice converts a slice of string values into a slice of string pointers.

func StringSlice added in v0.36.0

func StringSlice(src []*string) []string

StringSlice converts a slice of string pointers into a slice of string values.

func TeamsRulesActionValues added in v0.22.0

func TeamsRulesActionValues() []string

func Time added in v0.36.0

func Time(v *time.Time) time.Time

Time is a helper routine that accepts a time pointer value and returns a value to it.

func TimePtr added in v0.35.0

func TimePtr(v time.Time) *time.Time

TimePtr is a helper routine that allocates a new time.Time value to store v and returns a pointer to it.

func Uint added in v0.36.0

func Uint(v *uint) uint

Uint is a helper routine that accepts a uint pointer and returns a value to it.

func Uint16 added in v0.36.0

func Uint16(v *uint16) uint16

Uint16 is a helper routine that accepts a uint16 pointer and returns a value to it.

func Uint16Map added in v0.36.0

func Uint16Map(src map[string]*uint16) map[string]uint16

Uint16Map converts a string map of uint16 pointers into a string map of uint16 values.

func Uint16Ptr added in v0.35.0

func Uint16Ptr(v uint16) *uint16

Uint16Ptr is a helper routine that allocates a new uint16 value to store v and returns a pointer to it.

func Uint16PtrMap added in v0.35.0

func Uint16PtrMap(src map[string]uint16) map[string]*uint16

Uint16PtrMap converts a string map of uint16 values into a string map of uint16 pointers.

func Uint16PtrSlice added in v0.35.0

func Uint16PtrSlice(src []uint16) []*uint16

Uint16PtrSlice converts a slice of uint16 values into a slice of uint16 pointers.

func Uint16Slice added in v0.36.0

func Uint16Slice(src []*uint16) []uint16

Uint16Slice converts a slice of uint16 pointers into a slice of uint16 values.

func Uint32 added in v0.36.0

func Uint32(v *uint32) uint32

Uint32 is a helper routine that accepts a uint32 pointer and returns a value to it.

func Uint32Map added in v0.36.0

func Uint32Map(src map[string]*uint32) map[string]uint32

Uint32Map converts a string map of uint32 pointers into a string map of uint32 values.

func Uint32Ptr added in v0.35.0

func Uint32Ptr(v uint32) *uint32

Uint32Ptr is a helper routine that allocates a new uint32 value to store v and returns a pointer to it.

func Uint32PtrMap added in v0.35.0

func Uint32PtrMap(src map[string]uint32) map[string]*uint32

Uint32PtrMap converts a string map of uint32 values into a string map of uint32 pointers.

func Uint32PtrSlice added in v0.35.0

func Uint32PtrSlice(src []uint32) []*uint32

Uint32PtrSlice converts a slice of uint32 values into a slice of uint32 pointers.

func Uint32Slice added in v0.36.0

func Uint32Slice(src []*uint32) []uint32

Uint32Slice converts a slice of uint32 pointers into a slice of uint32 values.

func Uint64 added in v0.36.0

func Uint64(v *uint64) uint64

Uint64 is a helper routine that accepts a uint64 pointer and returns a value to it.

func Uint64Map added in v0.36.0

func Uint64Map(src map[string]*uint64) map[string]uint64

Uint64Map converts a string map of uint64 pointers into a string map of uint64 values.

func Uint64Ptr added in v0.35.0

func Uint64Ptr(v uint64) *uint64

Uint64Ptr is a helper routine that allocates a new uint64 value to store v and returns a pointer to it.

func Uint64PtrMap added in v0.35.0

func Uint64PtrMap(src map[string]uint64) map[string]*uint64

Uint64PtrMap converts a string map of uint64 values into a string map of uint64 pointers.

func Uint64PtrSlice added in v0.35.0

func Uint64PtrSlice(src []uint64) []*uint64

Uint64PtrSlice converts a slice of uint64 values into a slice of uint64 pointers.

func Uint64Slice added in v0.36.0

func Uint64Slice(src []*uint64) []uint64

Uint64Slice converts a slice of uint64 pointers into a slice of uint64 values.

func Uint8 added in v0.36.0

func Uint8(v *uint8) uint8

Uint8 is a helper routine that accepts a uint8 pointer and returns a value to it.

func Uint8Map added in v0.36.0

func Uint8Map(src map[string]*uint8) map[string]uint8

Uint8Map converts a string map of uint8 pointers into a string map of uint8 values.

func Uint8Ptr added in v0.35.0

func Uint8Ptr(v uint8) *uint8

Uint8Ptr is a helper routine that allocates a new uint8 value to store v and returns a pointer to it.

func Uint8PtrMap added in v0.35.0

func Uint8PtrMap(src map[string]uint8) map[string]*uint8

Uint8PtrMap converts a string map of uint8 values into a string map of uint8 pointers.

func Uint8PtrSlice added in v0.35.0

func Uint8PtrSlice(src []uint8) []*uint8

Uint8PtrSlice converts a slice of uint8 values into a slice of uint8 pointers.

func Uint8Slice added in v0.36.0

func Uint8Slice(src []*uint8) []uint8

Uint8Slice converts a slice of uint8 pointers into a slice of uint8 values.

func UintMap added in v0.36.0

func UintMap(src map[string]*uint) map[string]uint

UintMap converts a string map of uint pointers uinto a string map of uint values.

func UintPtr added in v0.35.0

func UintPtr(v uint) *uint

UintPtr is a helper routine that allocates a new uint value to store v and returns a pointer to it.

func UintPtrMap added in v0.35.0

func UintPtrMap(src map[string]uint) map[string]*uint

UintPtrMap converts a string map of uint values uinto a string map of uint pointers.

func UintPtrSlice added in v0.35.0

func UintPtrSlice(src []uint) []*uint

UintPtrSlice converts a slice of uint values uinto a slice of uint pointers.

func UintSlice added in v0.36.0

func UintSlice(src []*uint) []uint

UintSlice converts a slice of uint pointers uinto a slice of uint values.

Types

type API

type API struct {
	APIKey            string
	APIEmail          string
	APIUserServiceKey string
	APIToken          string
	BaseURL           string
	AccountID         string
	UserAgent         string

	Debug bool
	// contains filtered or unexported fields
}

API holds the configuration for the current API client. A client should not be modified concurrently.

func New

func New(key, email string, opts ...Option) (*API, error)

New creates a new Cloudflare v4 API client.

func NewWithAPIToken added in v0.9.3

func NewWithAPIToken(token string, opts ...Option) (*API, error)

NewWithAPIToken creates a new Cloudflare v4 API client using API Tokens.

func NewWithUserServiceKey added in v0.9.0

func NewWithUserServiceKey(key string, opts ...Option) (*API, error)

NewWithUserServiceKey creates a new Cloudflare v4 API client using service key authentication.

func (*API) APITokens added in v0.13.5

func (api *API) APITokens(ctx context.Context) ([]APIToken, error)

APITokens returns all available API tokens.

API reference: https://api.cloudflare.com/#user-api-tokens-list-tokens

func (*API) AccessApplication added in v0.9.0

func (api *API) AccessApplication(ctx context.Context, accountID, applicationID string) (AccessApplication, error)

AccessApplication returns a single application based on the application ID.

API reference: https://api.cloudflare.com/#access-applications-access-applications-details

func (*API) AccessApplications added in v0.9.0

func (api *API) AccessApplications(ctx context.Context, accountID string, pageOpts PaginationOptions) ([]AccessApplication, ResultInfo, error)

AccessApplications returns all applications within an account.

API reference: https://api.cloudflare.com/#access-applications-list-access-applications

func (*API) AccessAuditLogs added in v0.12.1

func (api *API) AccessAuditLogs(ctx context.Context, accountID string, opts AccessAuditLogFilterOptions) ([]AccessAuditLogRecord, error)

AccessAuditLogs retrieves all audit logs for the Access service.

API reference: https://api.cloudflare.com/#access-requests-access-requests-audit

Example
package main

import (
	"context"
	"encoding/json"
	"fmt"
	"log"

	cloudflare "github.com/cloudflare/cloudflare-go"
)

func main() {
	api, err := cloudflare.New("deadbeef", "test@example.org")
	if err != nil {
		log.Fatal(err)
	}

	filterOpts := cloudflare.AccessAuditLogFilterOptions{}
	results, _ := api.AccessAuditLogs(context.Background(), "someaccountid", filterOpts)

	for _, record := range results {
		b, _ := json.Marshal(record)
		fmt.Println(string(b))
	}
}
Output:

func (*API) AccessBookmark added in v0.36.0

func (api *API) AccessBookmark(ctx context.Context, accountID, bookmarkID string) (AccessBookmark, error)

AccessBookmark returns a single bookmark based on the bookmark ID.

API reference: https://api.cloudflare.com/#access-bookmarks-access-bookmarks-details

func (*API) AccessBookmarks added in v0.36.0

func (api *API) AccessBookmarks(ctx context.Context, accountID string, pageOpts PaginationOptions) ([]AccessBookmark, ResultInfo, error)

AccessBookmarks returns all bookmarks within an account.

API reference: https://api.cloudflare.com/#access-bookmarks-list-access-bookmarks

func (*API) AccessCACertificate added in v0.12.1

func (api *API) AccessCACertificate(ctx context.Context, accountID, applicationID string) (AccessCACertificate, error)

AccessCACertificate returns a single CA certificate associated with an Access Application.

API reference: https://api.cloudflare.com/#access-short-lived-certificates-short-lived-certificate-details

func (*API) AccessCACertificates added in v0.12.1

func (api *API) AccessCACertificates(ctx context.Context, accountID string) ([]AccessCACertificate, error)

AccessCACertificates returns all CA certificates within Access.

API reference: https://api.cloudflare.com/#access-short-lived-certificates-list-short-lived-certificates

func (*API) AccessGroup added in v0.10.5

func (api *API) AccessGroup(ctx context.Context, accountID, groupID string) (AccessGroup, error)

AccessGroup returns a single group based on the group ID.

API reference: https://api.cloudflare.com/#access-groups-access-group-details

func (*API) AccessGroups added in v0.10.5

func (api *API) AccessGroups(ctx context.Context, accountID string, pageOpts PaginationOptions) ([]AccessGroup, ResultInfo, error)

AccessGroups returns all access groups for an access application.

API reference: https://api.cloudflare.com/#access-groups-list-access-groups

func (*API) AccessIdentityProviderDetails added in v0.10.1

func (api *API) AccessIdentityProviderDetails(ctx context.Context, accountID, identityProviderID string) (AccessIdentityProvider, error)

AccessIdentityProviderDetails returns a single Access Identity Provider for an account.

API reference: https://api.cloudflare.com/#access-identity-providers-access-identity-providers-details

func (*API) AccessIdentityProviders added in v0.10.1

func (api *API) AccessIdentityProviders(ctx context.Context, accountID string) ([]AccessIdentityProvider, error)

AccessIdentityProviders returns all Access Identity Providers for an account.

API reference: https://api.cloudflare.com/#access-identity-providers-list-access-identity-providers

func (*API) AccessKeysConfig added in v0.23.0

func (api *API) AccessKeysConfig(ctx context.Context, accountID string) (AccessKeysConfig, error)

AccessKeysConfig returns the Access Keys Configuration for an account.

API reference: https://api.cloudflare.com/#access-keys-configuration-get-access-keys-configuration

func (*API) AccessMutualTLSCertificate added in v0.13.8

func (api *API) AccessMutualTLSCertificate(ctx context.Context, accountID, certificateID string) (AccessMutualTLSCertificate, error)

AccessMutualTLSCertificate returns a single account level Access Mutual TLS certificate.

API reference: https://api.cloudflare.com/#access-mutual-tls-authentication-access-certificate-details

func (*API) AccessMutualTLSCertificates added in v0.13.8

func (api *API) AccessMutualTLSCertificates(ctx context.Context, accountID string) ([]AccessMutualTLSCertificate, error)

AccessMutualTLSCertificates returns all Access TLS certificates for the account level.

API reference: https://api.cloudflare.com/#access-mutual-tls-authentication-properties

func (*API) AccessOrganization added in v0.10.1

func (api *API) AccessOrganization(ctx context.Context, accountID string) (AccessOrganization, ResultInfo, error)

AccessOrganization returns the Access organisation details.

API reference: https://api.cloudflare.com/#access-organizations-access-organization-details

func (*API) AccessPolicies added in v0.9.0

func (api *API) AccessPolicies(ctx context.Context, accountID, applicationID string, pageOpts PaginationOptions) ([]AccessPolicy, ResultInfo, error)

AccessPolicies returns all access policies for an access application.

API reference: https://api.cloudflare.com/#access-policy-list-access-policies

func (*API) AccessPolicy added in v0.9.0

func (api *API) AccessPolicy(ctx context.Context, accountID, applicationID, policyID string) (AccessPolicy, error)

AccessPolicy returns a single policy based on the policy ID.

API reference: https://api.cloudflare.com/#access-policy-access-policy-details

func (*API) AccessServiceTokens added in v0.10.1

func (api *API) AccessServiceTokens(ctx context.Context, accountID string) ([]AccessServiceToken, ResultInfo, error)

AccessServiceTokens returns all Access Service Tokens for an account.

API reference: https://api.cloudflare.com/#access-service-tokens-list-access-service-tokens

func (*API) Account added in v0.9.0

func (api *API) Account(ctx context.Context, accountID string) (Account, ResultInfo, error)

Account returns a single account based on the ID.

API reference: https://api.cloudflare.com/#accounts-account-details

func (*API) AccountAccessRule added in v0.10.0

func (api *API) AccountAccessRule(ctx context.Context, accountID string, accessRuleID string) (*AccessRuleResponse, error)

AccountAccessRule returns the details of an account's access rule.

API reference: https://api.cloudflare.com/#account-level-firewall-access-rule-access-rule-details

func (*API) AccountMember added in v0.9.0

func (api *API) AccountMember(ctx context.Context, accountID string, memberID string) (AccountMember, error)

AccountMember returns details of a single account member.

API reference: https://api.cloudflare.com/#account-members-member-details

func (*API) AccountMembers added in v0.9.0

func (api *API) AccountMembers(ctx context.Context, accountID string, pageOpts PaginationOptions) ([]AccountMember, ResultInfo, error)

AccountMembers returns all members of an account.

API reference: https://api.cloudflare.com/#accounts-list-accounts

func (*API) AccountRole added in v0.9.0

func (api *API) AccountRole(ctx context.Context, accountID string, roleID string) (AccountRole, error)

AccountRole returns the details of a single account role.

API reference: https://api.cloudflare.com/#account-roles-role-details

func (*API) AccountRoles added in v0.9.0

func (api *API) AccountRoles(ctx context.Context, accountID string) ([]AccountRole, error)

AccountRoles returns all roles of an account.

API reference: https://api.cloudflare.com/#account-roles-list-roles

func (*API) Accounts added in v0.9.0

func (api *API) Accounts(ctx context.Context, params AccountsListParams) ([]Account, ResultInfo, error)

Accounts returns all accounts the logged in user has access to.

API reference: https://api.cloudflare.com/#accounts-list-accounts

func (*API) ArgoSmartRouting added in v0.9.0

func (api *API) ArgoSmartRouting(ctx context.Context, zoneID string) (ArgoFeatureSetting, error)

ArgoSmartRouting returns the current settings for smart routing.

API reference: https://api.cloudflare.com/#argo-smart-routing-get-argo-smart-routing-setting

Example
package main

import (
	"context"
	"fmt"
	"log"

	cloudflare "github.com/cloudflare/cloudflare-go"
)

func main() {
	api, err := cloudflare.New("deadbeef", "test@example.org")
	if err != nil {
		log.Fatal(err)
	}

	smartRoutingSettings, err := api.ArgoSmartRouting(context.Background(), "01a7362d577a6c3019a474fd6f485823")
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("smart routing is %s", smartRoutingSettings.Value)
}
Output:

func (*API) ArgoTieredCaching added in v0.9.0

func (api *API) ArgoTieredCaching(ctx context.Context, zoneID string) (ArgoFeatureSetting, error)

ArgoTieredCaching returns the current settings for tiered caching.

API reference: TBA.

Example
package main

import (
	"context"
	"fmt"
	"log"

	cloudflare "github.com/cloudflare/cloudflare-go"
)

func main() {
	api, err := cloudflare.New("deadbeef", "test@example.org")
	if err != nil {
		log.Fatal(err)
	}

	tieredCachingSettings, err := api.ArgoTieredCaching(context.Background(), "01a7362d577a6c3019a474fd6f485823")
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("tiered caching is %s", tieredCachingSettings.Value)
}
Output:

func (*API) ArgoTunnel deprecated added in v0.13.7

func (api *API) ArgoTunnel(ctx context.Context, accountID, tunnelUUID string) (ArgoTunnel, error)

ArgoTunnel returns a single Argo tunnel.

API reference: https://api.cloudflare.com/#argo-tunnel-get-argo-tunnel

Deprecated: Use `Tunnel` instead.

func (*API) ArgoTunnels deprecated added in v0.13.7

func (api *API) ArgoTunnels(ctx context.Context, accountID string) ([]ArgoTunnel, error)

ArgoTunnels lists all tunnels.

API reference: https://api.cloudflare.com/#argo-tunnel-list-argo-tunnels

Deprecated: Use `Tunnels` instead.

func (*API) AttachWorkerToDomain added in v0.47.0

func (api *API) AttachWorkerToDomain(ctx context.Context, rc *ResourceContainer, params *WorkerDomainParams) (WorkerDomainResponse, error)

AttachWorkerToDomain attaches a worker to a zone and hostname

API reference: https://api.cloudflare.com/#worker-domain-attach-to-domain

func (*API) AttachWorkersDomain added in v0.55.0

func (api *API) AttachWorkersDomain(ctx context.Context, rc *ResourceContainer, domain AttachWorkersDomainParams) (WorkersDomain, error)

AttachWorkersDomain attaches a worker to a zone and hostname.

API reference: https://api.cloudflare.com/#worker-domain-attach-to-domain

func (*API) AvailableZonePlans

func (api *API) AvailableZonePlans(ctx context.Context, zoneID string) ([]ZonePlan, error)

AvailableZonePlans returns information about all plans available to the specified zone.

API reference: https://api.cloudflare.com/#zone-rate-plan-list-available-plans

func (*API) AvailableZoneRatePlans added in v0.7.4

func (api *API) AvailableZoneRatePlans(ctx context.Context, zoneID string) ([]ZoneRatePlan, error)

AvailableZoneRatePlans returns information about all plans available to the specified zone.

API reference: https://api.cloudflare.com/#zone-plan-available-plans

func (*API) BaseImage added in v0.30.0

func (api *API) BaseImage(ctx context.Context, accountID string, id string) ([]byte, error)

BaseImage gets the base image used to derive variants.

API Reference: https://api.cloudflare.com/#cloudflare-images-base-image

func (*API) CancelRegistrarDomainTransfer added in v0.9.0

func (api *API) CancelRegistrarDomainTransfer(ctx context.Context, accountID, domainName string) ([]RegistrarDomain, error)

CancelRegistrarDomainTransfer cancels a pending domain transfer.

API reference: https://api.cloudflare.com/#registrar-domains-cancel-transfer

Example
api, err := cloudflare.New(apiKey, user)
if err != nil {
	log.Fatal(err)
}

domains, err := api.CancelRegistrarDomainTransfer(context.Background(), "01a7362d577a6c3019a474fd6f485823", "cloudflare.com")
if err != nil {
	log.Fatal(err)
}

fmt.Printf("%+v\n", domains)
Output:

func (*API) CertificatePack added in v0.13.0

func (api *API) CertificatePack(ctx context.Context, zoneID, certificatePackID string) (CertificatePack, error)

CertificatePack returns a single TLS certificate pack on a zone.

API Reference: https://api.cloudflare.com/#certificate-packs-get-certificate-pack

func (*API) ChangePageRule

func (api *API) ChangePageRule(ctx context.Context, zoneID, ruleID string, rule PageRule) error

ChangePageRule lets you change individual settings for a Page Rule. This is in contrast to UpdatePageRule which replaces the entire Page Rule.

API reference: https://api.cloudflare.com/#page-rules-for-a-zone-change-a-page-rule

func (*API) ChangeWaitingRoom added in v0.17.0

func (api *API) ChangeWaitingRoom(ctx context.Context, zoneID, waitingRoomID string, waitingRoom WaitingRoom) (WaitingRoom, error)

ChangeWaitingRoom lets you change individual settings for a Waiting room. This is in contrast to UpdateWaitingRoom which replaces the entire Waiting room.

API reference: https://api.cloudflare.com/#waiting-room-update-waiting-room

func (*API) ChangeWaitingRoomEvent added in v0.33.0

func (api *API) ChangeWaitingRoomEvent(ctx context.Context, zoneID, waitingRoomID string, waitingRoomEvent WaitingRoomEvent) (WaitingRoomEvent, error)

ChangeWaitingRoomEvent lets you change individual settings for a Waiting Room Event. This is in contrast to UpdateWaitingRoomEvent which replaces the entire Waiting Room Event.

API reference: https://api.cloudflare.com/#waiting-room-patch-event

func (*API) CheckAccountLogpushDestinationExists added in v0.29.0

func (api *API) CheckAccountLogpushDestinationExists(ctx context.Context, accountID, destinationConf string) (bool, error)

CheckAccountLogpushDestinationExists returns account-level destination exists check result.

API reference: https://api.cloudflare.com/#logpush-jobs-check-destination-exists

func (*API) CheckLogpushDestinationExists deprecated added in v0.9.0

func (api *API) CheckLogpushDestinationExists(ctx context.Context, zoneID, destinationConf string) (bool, error)

CheckLogpushDestinationExists returns zone-level destination exists check result.

API reference: https://api.cloudflare.com/#logpush-jobs-check-destination-exists

Deprecated: Use `CheckZoneLogpushDestinationExists` or `CheckAccountLogpushDestinationExists` depending on the desired resource to target.

func (*API) CheckZoneLogpushDestinationExists added in v0.29.0

func (api *API) CheckZoneLogpushDestinationExists(ctx context.Context, zoneID, destinationConf string) (bool, error)

CheckZoneLogpushDestinationExists returns zone-level destination exists check result.

API reference: https://api.cloudflare.com/#logpush-jobs-check-destination-exists

Example
api, err := cloudflare.New(apiKey, user)
if err != nil {
	log.Fatal(err)
}

zoneID, err := api.ZoneIDByName(domain)
if err != nil {
	log.Fatal(err)
}

exists, err := api.CheckZoneLogpushDestinationExists(context.Background(), zoneID, "destination_conf")
if err != nil {
	log.Fatal(err)
}

fmt.Printf("%+v\n", exists)
Output:

func (*API) CleanupArgoTunnelConnections deprecated added in v0.13.7

func (api *API) CleanupArgoTunnelConnections(ctx context.Context, accountID, tunnelUUID string) error

CleanupArgoTunnelConnections deletes any inactive connections on a tunnel.

API reference: https://api.cloudflare.com/#argo-tunnel-clean-up-argo-tunnel-connections

Deprecated: Use `CleanupTunnelConnections` instead.

func (*API) CleanupTunnelConnections added in v0.39.0

func (api *API) CleanupTunnelConnections(ctx context.Context, rc *ResourceContainer, tunnelID string) error

CleanupTunnelConnections deletes any inactive connections on a tunnel.

API reference: https://api.cloudflare.com/#cloudflare-tunnel-clean-up-cloudflare-tunnel-connections

func (*API) ConnectZoneRailgun

func (api *API) ConnectZoneRailgun(ctx context.Context, zoneID, railgunID string) (ZoneRailgun, error)

ConnectZoneRailgun connects a Railgun for a given zone.

API reference: https://api.cloudflare.com/#railguns-for-a-zone-connect-or-disconnect-a-railgun

func (*API) CreateAPIToken added in v0.13.5

func (api *API) CreateAPIToken(ctx context.Context, token APIToken) (APIToken, error)

CreateAPIToken creates a new token. Returns the API token that has been generated.

The token value itself is only shown once (post create) and will present as `Value` from this method. If you fail to capture it at this point, you will need to roll the token in order to get a new value.

API reference: https://api.cloudflare.com/#user-api-tokens-create-token

func (*API) CreateAccessApplication added in v0.9.0

func (api *API) CreateAccessApplication(ctx context.Context, accountID string, accessApplication AccessApplication) (AccessApplication, error)

CreateAccessApplication creates a new access application.

API reference: https://api.cloudflare.com/#access-applications-create-access-application

func (*API) CreateAccessBookmark added in v0.36.0

func (api *API) CreateAccessBookmark(ctx context.Context, accountID string, accessBookmark AccessBookmark) (AccessBookmark, error)

CreateAccessBookmark creates a new access bookmark.

API reference: https://api.cloudflare.com/#access-bookmarks-create-access-bookmark

func (*API) CreateAccessCACertificate added in v0.12.1

func (api *API) CreateAccessCACertificate(ctx context.Context, accountID, applicationID string) (AccessCACertificate, error)

CreateAccessCACertificate creates a new CA certificate for an Access Application.

API reference: https://api.cloudflare.com/#access-short-lived-certificates-create-short-lived-certificate

func (*API) CreateAccessGroup added in v0.10.5

func (api *API) CreateAccessGroup(ctx context.Context, accountID string, accessGroup AccessGroup) (AccessGroup, error)

CreateAccessGroup creates a new access group.

API reference: https://api.cloudflare.com/#access-groups-create-access-group

func (*API) CreateAccessIdentityProvider added in v0.10.1

func (api *API) CreateAccessIdentityProvider(ctx context.Context, accountID string, identityProviderConfiguration AccessIdentityProvider) (AccessIdentityProvider, error)

CreateAccessIdentityProvider creates a new Access Identity Provider.

API reference: https://api.cloudflare.com/#access-identity-providers-create-access-identity-provider

func (*API) CreateAccessMutualTLSCertificate added in v0.13.8

func (api *API) CreateAccessMutualTLSCertificate(ctx context.Context, accountID string, certificate AccessMutualTLSCertificate) (AccessMutualTLSCertificate, error)

CreateAccessMutualTLSCertificate creates an account level Access TLS Mutual certificate.

API reference: https://api.cloudflare.com/#access-mutual-tls-authentication-create-access-certificate

func (*API) CreateAccessOrganization added in v0.10.1

func (api *API) CreateAccessOrganization(ctx context.Context, accountID string, accessOrganization AccessOrganization) (AccessOrganization, error)

CreateAccessOrganization creates the Access organisation details.

API reference: https://api.cloudflare.com/#access-organizations-create-access-organization

func (*API) CreateAccessPolicy added in v0.9.0

func (api *API) CreateAccessPolicy(ctx context.Context, accountID, applicationID string, accessPolicy AccessPolicy) (AccessPolicy, error)

CreateAccessPolicy creates a new access policy.

API reference: https://api.cloudflare.com/#access-policy-create-access-policy

func (*API) CreateAccessServiceToken added in v0.10.1

func (api *API) CreateAccessServiceToken(ctx context.Context, accountID, name string) (AccessServiceTokenCreateResponse, error)

CreateAccessServiceToken creates a new Access Service Token for an account.

API reference: https://api.cloudflare.com/#access-service-tokens-create-access-service-token

func (*API) CreateAccount added in v0.13.8

func (api *API) CreateAccount(ctx context.Context, account Account) (Account, error)

CreateAccount creates a new account. Note: This requires the Tenant entitlement.

API reference: https://developers.cloudflare.com/tenant/tutorial/provisioning-resources#creating-an-account

func (*API) CreateAccountAccessRule added in v0.10.0

func (api *API) CreateAccountAccessRule(ctx context.Context, accountID string, accessRule AccessRule) (*AccessRuleResponse, error)

CreateAccountAccessRule creates a firewall access rule for the given account identifier.

API reference: https://api.cloudflare.com/#account-level-firewall-access-rule-create-access-rule

func (*API) CreateAccountLogpushJob added in v0.29.0

func (api *API) CreateAccountLogpushJob(ctx context.Context, accountID string, job LogpushJob) (*LogpushJob, error)

CreateAccountLogpushJob creates a new account-level Logpush Job.

API reference: https://api.cloudflare.com/#logpush-jobs-create-logpush-job

func (*API) CreateAccountMember added in v0.9.0

func (api *API) CreateAccountMember(ctx context.Context, rc *ResourceContainer, params CreateAccountMemberParams) (AccountMember, error)

CreateAccountMember invites a new member to join an account with roles. The member will be placed into "pending" status and receive an email confirmation. NOTE: If you are currently enrolled in Domain Scoped Roles, your roles will be converted to policies upon member invitation.

API reference: https://api.cloudflare.com/#account-members-add-member

func (*API) CreateAccountMemberWithStatus deprecated added in v0.25.0

func (api *API) CreateAccountMemberWithStatus(ctx context.Context, accountID string, emailAddress string, roles []string, status string) (AccountMember, error)

CreateAccountMemberWithStatus invites a new member to join an account, allowing setting the status.

Refer to the API reference for valid statuses.

Deprecated: Use `CreateAccountMember` with a `Status` field instead.

API reference: https://api.cloudflare.com/#account-members-add-member

func (*API) CreateAccountRuleset