cloudflare

package module
v0.7.1-beta Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2016 License: BSD-3-Clause Imports: 9 Imported by: 0

README

cloudflare-go

GoDoc Build Status 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:

  • DNS Records
  • Zones
  • Web Application Firewall (WAF)
  • CloudFlare IPs
  • User Administration (partial)
  • Virtual DNS Management
  • Organization Administration
  • Railgun administration
  • Keyless SSL
  • Origin CA

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.

go get github.com/cloudflare/cloudflare-go

Getting Started

package main

import (
	"fmt"
	"log"
	"os"

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

func main() {
	// Construct a new API object
	api, err := cloudflare.New(os.Getenv("CF_API_KEY"), os.Getenv("CF_API_EMAIL"))
	if err != nil {
		log.Fatal(err)
	}

	// Fetch user details on the account
	u, err := api.UserDetails()
	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(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.

License

BSD licensed. See the LICENSE file for details.

Documentation

Overview

Package cloudflare implements the CloudFlare v4 API.

Index

Constants

This section is empty.

Variables

View Source
var PageRuleActions = map[string]string{
	"always_online":       "Always Online",
	"always_use_https":    "Always Use HTTPS",
	"browser_cache_ttl":   "Browser Cache TTL",
	"browser_check":       "Browser Integrity Check",
	"cache_level":         "Cache Level",
	"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",
	"forwarding_url":      "Forwarding URL",
	"ip_geolocation":      "IP Geolocation Header",
	"mirage":              "Mirage",
	"rocket_loader":       "Rocker Loader",
	"security_level":      "Security Level",
	"server_side_exclude": "Server Side Excludes",
	"smart_errors":        "Smart Errors",
	"ssl":                 "SSL",
	"waf":                 "Web Application Firewall",
}

PageRuleActions maps API action IDs to human-readable strings

Functions

This section is empty.

Types

type API

type API struct {
	APIKey   string
	APIEmail string
	BaseURL  string
	// 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 (*API) AvailableZonePlans

func (api *API) AvailableZonePlans(zoneID string) ([]ZonePlan, error)

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

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

func (*API) ChangePageRule

func (api *API) ChangePageRule(zoneID, ruleID string, rule PageRule) error

ChangePageRule lets 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
PATCH /zones/:zone_identifier/pagerules/:identifier

func (*API) ConnectZoneRailgun

func (api *API) ConnectZoneRailgun(zoneID, railgunID string) (ZoneRailgun, error)

ZoneRailgun connects a Railgun for a given zone. API reference:

https://api.cloudflare.com/#railguns-for-a-zone-connect-or-disconnect-a-railgun
PATCH /zones/:zone_identifier/railguns/:identifier

func (*API) CreateDNSRecord

func (api *API) CreateDNSRecord(zoneID string, rr DNSRecord) (*DNSRecordResponse, error)

CreateDNSRecord creates a DNS record for the zone identifier. API reference:

https://api.cloudflare.com/#dns-records-for-a-zone-create-dns-record
POST /zones/:zone_identifier/dns_records

func (*API) CreateKeyless

func (api *API) CreateKeyless()

CreateKeyless creates a new Keyless SSL configuration for the zone. API reference:

https://api.cloudflare.com/#keyless-ssl-for-a-zone-create-a-keyless-ssl-configuration
POST /zones/:zone_identifier/keyless_certificates

func (*API) CreatePageRule

func (api *API) CreatePageRule(zoneID string, rule PageRule) error

CreatePageRule creates a new Page Rule for a zone.

API reference:

https://api.cloudflare.com/#page-rules-for-a-zone-create-a-page-rule
POST /zones/:zone_identifier/pagerules

func (*API) CreateRailgun

func (api *API) CreateRailgun(name string) (Railgun, error)

CreateRailgun creates a new Railgun. API reference:

https://api.cloudflare.com/#railgun-create-railgun
POST /railguns

func (*API) CreateSSL

func (api *API) CreateSSL(zoneID string, options ZoneCustomSSLOptions) (ZoneCustomSSL, error)

CreateSSL allows you to add a custom SSL certificate to the given zone. API reference:

https://api.cloudflare.com/#custom-ssl-for-a-zone-create-ssl-configuration
POST /zones/:zone_identifier/custom_certificates

func (*API) CreateVirtualDNS

func (api *API) CreateVirtualDNS(v *VirtualDNS) (*VirtualDNS, error)

CreateVirtualDNS creates a new Virtual DNS cluster. API reference:

https://api.cloudflare.com/#virtual-dns-users--create-a-virtual-dns-cluster
POST /user/virtual_dns

func (*API) CreateZone

func (api *API) CreateZone(name string, jumpstart bool, org Organization) (Zone, error)

CreateZone creates a zone on an account.

API reference: https://api.cloudflare.com/#zone-create-a-zone

func (*API) DNSRecord

func (api *API) DNSRecord(zoneID, recordID string) (DNSRecord, error)

DNSRecord returns a single DNS record for the given zone & record identifiers. API reference:

https://api.cloudflare.com/#dns-records-for-a-zone-dns-record-details
GET /zones/:zone_identifier/dns_records/:identifier

func (*API) DNSRecords

func (api *API) DNSRecords(zoneID string, rr DNSRecord) ([]DNSRecord, error)

DNSRecords returns a slice of DNS records for the given zone identifier. API reference:

https://api.cloudflare.com/#dns-records-for-a-zone-list-dns-records
GET /zones/:zone_identifier/dns_records

func (*API) DeleteDNSRecord

func (api *API) DeleteDNSRecord(zoneID, recordID string) error

DeleteDNSRecord deletes a single DNS record for the given zone & record identifiers. API reference:

https://api.cloudflare.com/#dns-records-for-a-zone-delete-dns-record
DELETE /zones/:zone_identifier/dns_records/:identifier

func (*API) DeleteKeyless

func (api *API) DeleteKeyless()

DeleteKeyless deletes an existing Keyless SSL configuration. API reference:

https://api.cloudflare.com/#keyless-ssl-for-a-zone-delete-keyless-configuration
DELETE /zones/:zone_identifier/keyless_certificates/:identifier

func (*API) DeletePageRule

func (api *API) DeletePageRule(zoneID, ruleID string) error

DeletePageRule deletes a Page Rule for a zone.

API reference:

https://api.cloudflare.com/#page-rules-for-a-zone-delete-a-page-rule
DELETE /zones/:zone_identifier/pagerules/:identifier

func (*API) DeleteRailgun

func (api *API) DeleteRailgun(railgunID string) error

DeleteRailgun disables and deletes a Railgun. API reference:

https://api.cloudflare.com/#railgun-delete-railgun
DELETE /railguns/:identifier

func (*API) DeleteSSL

func (api *API) DeleteSSL(zoneID, certificateID string) error

DeleteSSL deletes a custom SSL certificate from the given zone. API reference:

https://api.cloudflare.com/#custom-ssl-for-a-zone-delete-an-ssl-certificate
DELETE /zones/:zone_identifier/custom_certificates/:identifier

func (*API) DeleteVirtualDNS

func (api *API) DeleteVirtualDNS(virtualDNSID string) error

DeleteVirtualDNS deletes a Virtual DNS cluster. Note that this cannot be undone, and will stop all traffic to that cluster. API reference:

https://api.cloudflare.com/#virtual-dns-users--delete-a-virtual-dns-cluster
DELETE /user/virtual_dns/:identifier

func (*API) DeleteZone

func (api *API) DeleteZone(zoneID string) (ZoneID, error)

DeleteZone deletes the given zone.

API reference: https://api.cloudflare.com/#zone-delete-a-zone

func (*API) DisableRailgun

func (api *API) DisableRailgun(railgunID string) (Railgun, error)

DisableRailgun enables a Railgun for all zones connected to it. API reference:

https://api.cloudflare.com/#railgun-enable-or-disable-a-railgun
PATCH /railguns/:identifier

func (*API) DisconnectZoneRailgun

func (api *API) DisconnectZoneRailgun(zoneID, railgunID string) (ZoneRailgun, error)

ZoneRailgun disconnects a Railgun for a given zone. API reference:

https://api.cloudflare.com/#railguns-for-a-zone-connect-or-disconnect-a-railgun
PATCH /zones/:zone_identifier/railguns/:identifier

func (*API) EditZone

func (api *API) EditZone(zoneID string, zoneOpts ZoneOptions) (Zone, error)

EditZone edits the given zone. This is usually called by ZoneSetPaused, ZoneSetVanityNS or ZoneSetPlan.

API reference: https://api.cloudflare.com/#zone-edit-zone-properties

func (*API) EnableRailgun

func (api *API) EnableRailgun(railgunID string) (Railgun, error)

EnableRailgun enables a Railgun for all zones connected to it. API reference:

https://api.cloudflare.com/#railgun-enable-or-disable-a-railgun
PATCH /railguns/:identifier

func (*API) Keyless

func (api *API) Keyless()

Keyless provides the configuration for a given Keyless SSL identifier. API reference:

https://api.cloudflare.com/#keyless-ssl-for-a-zone-keyless-ssl-details
GET /zones/:zone_identifier/keyless_certificates/:identifier

func (*API) ListKeyless

func (api *API) ListKeyless()

ListKeyless lists Keyless SSL configurations for a zone. API reference:

https://api.cloudflare.com/#keyless-ssl-for-a-zone-list-keyless-ssls
GET /zones/:zone_identifier/keyless_certificates

func (*API) ListPageRules

func (api *API) ListPageRules(zoneID string) ([]PageRule, error)

ListPageRules returns all Page Rules for a zone.

API reference:

https://api.cloudflare.com/#page-rules-for-a-zone-list-page-rules
GET /zones/:zone_identifier/pagerules

func (*API) ListRailguns

func (api *API) ListRailguns(options RailgunListOptions) ([]Railgun, error)

ListRailguns lists Railguns connected to an account. API reference:

https://api.cloudflare.com/#railgun-list-railguns
GET /railguns

func (*API) ListSSL

func (api *API) ListSSL(zoneID string) ([]ZoneCustomSSL, error)

ListSSL lists the custom certificates for the given zone. API reference:

https://api.cloudflare.com/#custom-ssl-for-a-zone-list-ssl-configurations
GET /zones/:zone_identifier/custom_certificates

func (*API) ListVirtualDNS

func (api *API) ListVirtualDNS() ([]*VirtualDNS, error)

ListVirtualDNS lists the virtual DNS clusters associated with an account. API reference:

https://api.cloudflare.com/#virtual-dns-users--get-virtual-dns-clusters
GET /user/virtual_dns

func (*API) ListWAFPackages

func (api *API) ListWAFPackages(zoneID string) ([]WAFPackage, error)

ListWAFPackages returns a slice of the WAF packages for the given zone.

func (*API) ListWAFRules

func (api *API) ListWAFRules(zoneID, packageID string) ([]WAFRule, error)

ListWAFRules returns a slice of the WAF rules for the given WAF package.

func (*API) ListZones

func (api *API) ListZones(z ...string) ([]Zone, error)

ListZones lists zones on an account. Optionally takes a list of zone names to filter against.

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

func (*API) PageRule

func (api *API) PageRule(zoneID, ruleID string) (PageRule, error)

PageRule fetches detail about one Page Rule for a zone.

API reference:

https://api.cloudflare.com/#page-rules-for-a-zone-page-rule-details
GET /zones/:zone_identifier/pagerules/:identifier

func (*API) PurgeCache

func (api *API) PurgeCache(zoneID string, pcr PurgeCacheRequest) (PurgeCacheResponse, error)

PurgeCache purges the cache using the given PurgeCacheRequest (zone/url/tag).

API reference: https://api.cloudflare.com/#zone-purge-individual-files-by-url-and-cache-tags

func (*API) PurgeEverything

func (api *API) PurgeEverything(zoneID string) (PurgeCacheResponse, error)

PurgeEverything purges the cache for the given zone. Note: this will substantially increase load on the origin server for that zone if there is a high cached vs. uncached request ratio.

API reference: https://api.cloudflare.com/#zone-purge-all-files

func (*API) RailgunDetails

func (api *API) RailgunDetails(railgunID string) (Railgun, error)

RailgunDetails returns the details for a Railgun. API reference:

https://api.cloudflare.com/#railgun-railgun-details
GET /railguns/:identifier

func (*API) RailgunZones

func (api *API) RailgunZones(railgunID string) ([]Zone, error)

RailgunZones returns the zones that are currently using a Railgun. API reference:

https://api.cloudflare.com/#railgun-get-zones-connected-to-a-railgun
GET /railguns/:identifier/zones

func (*API) ReprioritizeSSL

func (api *API) ReprioritizeSSL(zoneID string, p []ZoneCustomSSLPriority) ([]ZoneCustomSSL, error)

ReprioritizeSSL allows you to change the priority (which is served for a given request) of custom SSL certificates associated with the given zone. API reference:

https://api.cloudflare.com/#custom-ssl-for-a-zone-re-prioritize-ssl-certificates
PUT /zones/:zone_identifier/custom_certificates/prioritize

func (*API) SSLDetails

func (api *API) SSLDetails(zoneID, certificateID string) (ZoneCustomSSL, error)

SSLDetails returns the configuration details for a custom SSL certificate. API reference:

https://api.cloudflare.com/#custom-ssl-for-a-zone-ssl-configuration-details
GET /zones/:zone_identifier/custom_certificates/:identifier

func (*API) TestRailgunConnection

func (api *API) TestRailgunConnection(zoneID, railgunID string) (RailgunDiagnosis, error)

TestRailgunResponse tests a Railgun connection for a given zone. API reference:

https://api.cloudflare.com/#railgun-connections-for-a-zone-test-railgun-connection
GET /zones/:zone_identifier/railguns/:identifier/diagnose

func (*API) UpdateDNSRecord

func (api *API) UpdateDNSRecord(zoneID, recordID string, rr DNSRecord) error

UpdateDNSRecord updates a single DNS record for the given zone & record identifiers. API reference:

https://api.cloudflare.com/#dns-records-for-a-zone-update-dns-record
PUT /zones/:zone_identifier/dns_records/:identifier

func (*API) UpdateKeyless

func (api *API) UpdateKeyless()

UpdateKeyless updates an existing Keyless SSL configuration. API reference:

https://api.cloudflare.com/#keyless-ssl-for-a-zone-update-keyless-configuration
PATCH /zones/:zone_identifier/keyless_certificates/:identifier

func (*API) UpdatePageRule

func (api *API) UpdatePageRule(zoneID, ruleID string, rule PageRule) error

UpdatePageRule lets you replace a Page Rule. This is in contrast to ChangePageRule which lets you change individual settings.

API reference:

https://api.cloudflare.com/#page-rules-for-a-zone-update-a-page-rule
PUT /zones/:zone_identifier/pagerules/:identifier

func (*API) UpdateSSL

func (api *API) UpdateSSL(zoneID, certificateID string, options ZoneCustomSSLOptions) (ZoneCustomSSL, error)

UpdateSSL updates (replaces) a custom SSL certificate. API reference:

https://api.cloudflare.com/#custom-ssl-for-a-zone-update-ssl-configuration
PATCH /zones/:zone_identifier/custom_certificates/:identifier

func (*API) UpdateUser

func (api *API) UpdateUser() (User, error)

UpdateUser updates the properties of the given user. API reference:

https://api.cloudflare.com/#user-update-user
PATCH /user

func (*API) UpdateVirtualDNS

func (api *API) UpdateVirtualDNS(virtualDNSID string, vv VirtualDNS) error

UpdateVirtualDNS updates a Virtual DNS cluster. API reference:

https://api.cloudflare.com/#virtual-dns-users--modify-a-virtual-dns-cluster
PATCH /user/virtual_dns/:identifier

func (*API) UserDetails

func (api *API) UserDetails() (User, error)

UserDetails provides information about the logged-in user. API reference:

https://api.cloudflare.com/#user-user-details
GET /user

func (*API) VirtualDNS

func (api *API) VirtualDNS(virtualDNSID string) (*VirtualDNS, error)

VirtualDNS fetches a single virtual DNS cluster. API reference:

https://api.cloudflare.com/#virtual-dns-users--get-a-virtual-dns-cluster
GET /user/virtual_dns/:identifier

func (*API) ZoneActivationCheck

func (api *API) ZoneActivationCheck(zoneID string) (Response, error)

ZoneActivationCheck initiates another zone activation check for newly-created zones.

API reference: https://api.cloudflare.com/#zone-initiate-another-zone-activation-check

func (*API) ZoneAnalyticsByColocation

func (api *API) ZoneAnalyticsByColocation(zoneID string, options ZoneAnalyticsOptions) ([]ZoneAnalyticsColocation, error)

ZoneAnalyticsByColocation returns zone analytics information by datacenter.

API reference:

https://api.cloudflare.com/#zone-analytics-analytics-by-co-locations
GET /zones/:zone_identifier/analytics/colos

func (*API) ZoneAnalyticsDashboard

func (api *API) ZoneAnalyticsDashboard(zoneID string, options ZoneAnalyticsOptions) (ZoneAnalyticsData, error)

ZoneAnalyticsDashboard returns zone analytics information.

API reference:

https://api.cloudflare.com/#zone-analytics-dashboard
GET /zones/:zone_identifier/analytics/dashboard

func (*API) ZoneDetails

func (api *API) ZoneDetails(zoneID string) (Zone, error)

ZoneDetails fetches information about a zone.

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

func (*API) ZoneIDByName

func (api *API) ZoneIDByName(zoneName string) (string, error)

ZoneIDByName retrieves a zone's ID from the name.

func (*API) ZonePlanDetails

func (api *API) ZonePlanDetails(zoneID, planID string) (ZonePlan, error)

ZonePlanDetails returns information about a zone plan.

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

func (*API) ZoneRailgunDetails

func (api *API) ZoneRailgunDetails(zoneID, railgunID string) (ZoneRailgun, error)

Railgun returns the configuration for a given Railgun. API reference:

https://api.cloudflare.com/#railguns-for-a-zone-get-railgun-details
GET /zones/:zone_identifier/railguns/:identifier

func (*API) ZoneRailguns

func (api *API) ZoneRailguns(zoneID string) ([]ZoneRailgun, error)

ZoneRailguns returns the available Railguns for a zone. API reference:

https://api.cloudflare.com/#railguns-for-a-zone-get-available-railguns
GET /zones/:zone_identifier/railguns

func (*API) ZoneSetPaused

func (api *API) ZoneSetPaused(zoneID string, paused bool) (Zone, error)

ZoneSetPaused pauses CloudFlare service for the entire zone, sending all traffic direct to the origin.

func (*API) ZoneSetPlan

func (api *API) ZoneSetPlan(zoneID string, plan ZonePlan) (Zone, error)

ZoneSetPlan changes the zone plan.

func (*API) ZoneSetVanityNS

func (api *API) ZoneSetVanityNS(zoneID string, ns []string) (Zone, error)

ZoneSetVanityNS sets custom nameservers for the zone. These names must be within the same zone.

type AvailableZonePlansResponse

type AvailableZonePlansResponse struct {
	Response
	Result []ZonePlan `json:"result"`
	ResultInfo
}

AvailableZonePlansResponse represents the response from the Available Plans endpoint.

type CustomPage

type CustomPage struct {
	CreatedOn      string    `json:"created_on"`
	ModifiedOn     time.Time `json:"modified_on"`
	URL            string    `json:"url"`
	State          string    `json:"state"`
	RequiredTokens []string  `json:"required_tokens"`
	PreviewTarget  string    `json:"preview_target"`
	Description    string    `json:"description"`
}

CustomPage represents a custom page configuration.

type CustomPageResponse

type CustomPageResponse struct {
	Response
	Result []CustomPage `json:"result"`
}

CustomPageResponse represents the response from the custom pages endpoint.

type DNSListResponse

type DNSListResponse struct {
	Response
	Result []DNSRecord `json:"result"`
}

DNSListResponse represents the response from the list DNS records endpoint.

type DNSRecord

type DNSRecord struct {
	ID         string      `json:"id,omitempty"`
	Type       string      `json:"type,omitempty"`
	Name       string      `json:"name,omitempty"`
	Content    string      `json:"content,omitempty"`
	Proxiable  bool        `json:"proxiable,omitempty"`
	Proxied    bool        `json:"proxied,omitempty"`
	TTL        int         `json:"ttl,omitempty"`
	Locked     bool        `json:"locked,omitempty"`
	ZoneID     string      `json:"zone_id,omitempty"`
	ZoneName   string      `json:"zone_name,omitempty"`
	CreatedOn  time.Time   `json:"created_on,omitempty"`
	ModifiedOn time.Time   `json:"modified_on,omitempty"`
	Data       interface{} `json:"data,omitempty"` // data returned by: SRV, LOC
	Meta       interface{} `json:"meta,omitempty"`
	Priority   int         `json:"priority,omitempty"`
}

DNSRecord represents a DNS record in a zone.

type DNSRecordResponse

type DNSRecordResponse struct {
	Response
	Result DNSRecord `json:"result"`
}

DNSRecordResponse represents the response from the DNS endpoint.

type Error

type Error interface {
	error
	// Raised when user credentials or configuration is invalid.
	User() bool
	// Raised when a parsing error (e.g. JSON) occurs.
	Parse() bool
	// Raised when a network error occurs.
	Network() bool
}

Error represents an error returned from this library.

type IPRanges

type IPRanges struct {
	IPv4CIDRs []string `json:"ipv4_cidrs"`
	IPv6CIDRs []string `json:"ipv6_cidrs"`
}

IPRanges contains lists of IPv4 and IPv6 CIDRs

func IPs

func IPs() (IPRanges, error)

IPs gets a list of CloudFlare's IP ranges

This does not require logging in to the API.

API reference:

https://api.cloudflare.com/#cloudflare-ips
GET /client/v4/ips

type IPsResponse

type IPsResponse struct {
	Response
	Result IPRanges `json:"result"`
}

IPsResponse is the API response containing a list of IPs

type KeylessSSL

type KeylessSSL struct {
	ID          string    `json:"id"`
	Name        string    `json:"name"`
	Host        string    `json:"host"`
	Port        int       `json:"port"`
	Status      string    `json:"success"`
	Enabled     bool      `json:"enabled"`
	Permissions []string  `json:"permissions"`
	CreatedOn   time.Time `json:"created_on"`
	ModifiedOn  time.Time `json:"modifed_on"`
}

KeylessSSL represents Keyless SSL configuration.

type KeylessSSLResponse

type KeylessSSLResponse struct {
	Response
	Result []KeylessSSL `json:"result"`
}

KeylessSSLResponse represents the response from the Keyless SSL endpoint.

type Option

type Option func(*API) error

Option is a functional option for configuring the API client.

func HTTPClient

func HTTPClient(client *http.Client) Option

HTTPClient accepts a custom *http.Client for making API calls.

func Headers

func Headers(headers http.Header) Option

Headers allows you to set custom HTTP headers when making API calls (e.g. for satisfying HTTP proxies, or for debugging).

type Organization

type Organization struct {
	ID          string   `json:"id,omitempty"`
	Name        string   `json:"name,omitempty"`
	Status      string   `json:"status,omitempty"`
	Permissions []string `json:"permissions,omitempty"`
	Roles       []string `json:"roles,omitempty"`
}

Organization represents a multi-user organization.

type OrganizationResponse

type OrganizationResponse struct {
	Response
	Result     []Organization `json:"result"`
	ResultInfo ResultInfo     `json:"result_info"`
}

OrganizationResponse represents the response from the Organization endpoint.

type Owner

type Owner struct {
	ID        string `json:"id"`
	Email     string `json:"email"`
	OwnerType string `json:"owner_type"`
}

Owner describes the resource owner.

type PageRule

type PageRule struct {
	ID         string           `json:"id,omitempty"`
	Targets    []PageRuleTarget `json:"targets"`
	Actions    []PageRuleAction `json:"actions"`
	Priority   int              `json:"priority"`
	Status     string           `json:"status"` // can be: active, paused
	ModifiedOn time.Time        `json:"modified_on,omitempty"`
	CreatedOn  time.Time        `json:"created_on,omitempty"`
}

PageRule describes a Page Rule.

type PageRuleAction

type PageRuleAction struct {
	ID    string      `json:"id"`
	Value interface{} `json:"value"`
}

PageRuleAction is the action to take when the target is matched.

Valid IDs are:

always_online
always_use_https
browser_cache_ttl
browser_check
cache_level
disable_apps
disable_performance
disable_railgun
disable_security
edge_cache_ttl
email_obfuscation
forwarding_url
ip_geolocation
mirage
rocket_loader
security_level
server_side_exclude
smart_errors
ssl
waf

type PageRuleDetailResponse

type PageRuleDetailResponse struct {
	Success  bool     `json:"success"`
	Errors   []string `json:"errors"`
	Messages []string `json:"messages"`
	Result   PageRule `json:"result"`
}

PageRuleDetailResponse is the API response, containing a single PageRule.

type PageRuleTarget

type PageRuleTarget struct {
	Target     string `json:"target"`
	Constraint struct {
		Operator string `json:"operator"`
		Value    string `json:"value"`
	} `json:"constraint"`
}

PageRuleTarget is the target to evaluate on a request.

Currently Target must always be "url" and Operator must be "matches". Value is the URL pattern to match against.

type PageRulesResponse

type PageRulesResponse struct {
	Success  bool       `json:"success"`
	Errors   []string   `json:"errors"`
	Messages []string   `json:"messages"`
	Result   []PageRule `json:"result"`
}

PageRulesResponse is the API response, containing an array of PageRules.

type PurgeCacheRequest

type PurgeCacheRequest struct {
	Everything bool     `json:"purge_everything,omitempty"`
	Files      []string `json:"files,omitempty"`
	Tags       []string `json:"tags,omitempty"`
}

PurgeCacheRequest represents the request format made to the purge endpoint.

type PurgeCacheResponse

type PurgeCacheResponse struct {
	Response
}

PurgeCacheResponse represents the response from the purge endpoint.

type Railgun

type Railgun struct {
	ID             string    `json:"id"`
	Name           string    `json:"name"`
	Status         string    `json:"status"`
	Enabled        bool      `json:"enabled"`
	ZonesConnected int       `json:"zones_connected"`
	Build          string    `json:"build"`
	Version        string    `json:"version"`
	Revision       string    `json:"revision"`
	ActivationKey  string    `json:"activation_key"`
	ActivatedOn    time.Time `json:"activated_on"`
	CreatedOn      time.Time `json:"created_on"`
	ModifiedOn     time.Time `json:"modified_on"`
	UpgradeInfo    struct {
		LatestVersion string `json:"latest_version"`
		DownloadLink  string `json:"download_link"`
	} `json:"upgrade_info"`
}

Railgun represents a Railgun's properties.

type RailgunDiagnosis

type RailgunDiagnosis struct {
	Method          string `json:"method"`
	HostName        string `json:"host_name"`
	HTTPStatus      int    `json:"http_status"`
	Railgun         string `json:"railgun"`
	URL             string `json:"url"`
	ResponseStatus  string `json:"response_status"`
	Protocol        string `json:"protocol"`
	ElapsedTime     string `json:"elapsed_time"`
	BodySize        string `json:"body_size"`
	BodyHash        string `json:"body_hash"`
	MissingHeaders  string `json:"missing_headers"`
	ConnectionClose bool   `json:"connection_close"`
	Cloudflare      string `json:"cloudflare"`
	CFRay           string `json:"cf-ray"`
	// NOTE: CloudFlare's online API documentation does not yet have definitions
	// for the following fields. See: https://api.cloudflare.com/#railgun-connections-for-a-zone-test-railgun-connection/
	CFWANError    string `json:"cf-wan-error"`
	CFCacheStatus string `json:"cf-cache-status"`
}

RailgunDiagnosis represents the test results from testing railgun connections to a zone.

type RailgunListOptions

type RailgunListOptions struct {
	Direction string
}

RailgunListOptions represents the parameters used to list railguns.

type Response

type Response struct {
	Success  bool           `json:"success"`
	Errors   []ResponseInfo `json:"errors"`
	Messages []ResponseInfo `json:"messages"`
}

Response is a template. There will also be a result struct. There will be a unique response type for each response, which will include this type.

type ResponseInfo

type ResponseInfo struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
}

ResponseInfo contains a code and message returned by the API as errors or informational messages inside the response.

type ResultInfo

type ResultInfo struct {
	Page    int `json:"page"`
	PerPage int `json:"per_page"`
	Count   int `json:"count"`
	Total   int `json:"total_count"`
}

ResultInfo contains metadata about the Response.

type User

type User struct {
	ID            string         `json:"id"`
	Email         string         `json:"email"`
	FirstName     string         `json:"first_name"`
	LastName      string         `json:"last_name"`
	Username      string         `json:"username"`
	Telephone     string         `json:"telephone"`
	Country       string         `json:"country"`
	Zipcode       string         `json:"zipcode"`
	CreatedOn     time.Time      `json:"created_on"`
	ModifiedOn    time.Time      `json:"modified_on"`
	APIKey        string         `json:"api_key"`
	TwoFA         bool           `json:"two_factor_authentication_enabled"`
	Betas         []string       `json:"betas"`
	Organizations []Organization `json:"organizations"`
}

User describes a user account.

type UserError

type UserError struct {
	Err error
}

UserError represents a user-generated error.

func (*UserError) Error

func (e *UserError) Error() string

Error wraps the underlying error.

func (*UserError) Network

func (e *UserError) Network() bool

Network error.

func (*UserError) Parse

func (e *UserError) Parse() bool

Parse error.

func (*UserError) User

func (e *UserError) User() bool

User is a user-caused error.

type UserResponse

type UserResponse struct {
	Response
	Result User `json:"result"`
}

UserResponse wraps a response containing User accounts.

type VirtualDNS

type VirtualDNS struct {
	ID                   string   `json:"id"`
	Name                 string   `json:"name"`
	OriginIPs            []string `json:"origin_ips"`
	VirtualDNSIPs        []string `json:"virtual_dns_ips"`
	MinimumCacheTTL      uint     `json:"minimum_cache_ttl"`
	MaximumCacheTTL      uint     `json:"maximum_cache_ttl"`
	DeprecateAnyRequests bool     `json:"deprecate_any_requests"`
	ModifiedOn           string   `json:"modified_on"`
}

VirtualDNS represents a Virtual DNS configuration.

type VirtualDNSListResponse

type VirtualDNSListResponse struct {
	Response
	Result []*VirtualDNS `json:"result"`
}

VirtualDNSListResponse represents an array of Virtual DNS responses.

type VirtualDNSResponse

type VirtualDNSResponse struct {
	Response
	Result *VirtualDNS `json:"result"`
}

VirtualDNSResponse represents a Virtual DNS response.

type WAFPackage

type WAFPackage struct {
	ID            string `json:"id"`
	Name          string `json:"name"`
	Description   string `json:"description"`
	ZoneID        string `json:"zone_id"`
	DetectionMode string `json:"detection_mode"`
	Sensitivity   string `json:"sensitivity"`
	ActionMode    string `json:"action_mode"`
}

WAFPackage represents a WAF package configuration.

type WAFPackagesResponse

type WAFPackagesResponse struct {
	Response
	Result     []WAFPackage `json:"result"`
	ResultInfo ResultInfo   `json:"result_info"`
}

WAFPackagesResponse represents the response from the WAF packages endpoint.

type WAFRule

type WAFRule struct {
	ID          string `json:"id"`
	Description string `json:"description"`
	Priority    string `json:"priority"`
	PackageID   string `json:"package_id"`
	Group       struct {
		ID   string `json:"id"`
		Name string `json:"name"`
	} `json:"group"`
	Mode         string   `json:"mode"`
	DefaultMode  string   `json:"default_mode"`
	AllowedModes []string `json:"allowed_modes"`
}

WAFRule represents a WAF rule.

type WAFRulesResponse

type WAFRulesResponse struct {
	Response
	Result     []WAFRule  `json:"result"`
	ResultInfo ResultInfo `json:"result_info"`
}

WAFRulesResponse represents the response from the WAF rule endpoint.

type Zone

type Zone struct {
	ID                string   `json:"id"`
	Name              string   `json:"name"`
	DevMode           int      `json:"development_mode"`
	OriginalNS        []string `json:"original_name_servers"`
	OriginalRegistrar string   `json:"original_registrar"`
	OriginalDNSHost   string   `json:"original_dnshost"`
	CreatedOn         string   `json:"created_on"`
	ModifiedOn        string   `json:"modified_on"`
	NameServers       []string `json:"name_servers"`
	Owner             Owner    `json:"owner"`
	Permissions       []string `json:"permissions"`
	Plan              ZonePlan `json:"plan"`
	PlanPending       ZonePlan `json:"plan_pending,omitempty"`
	Status            string   `json:"status"`
	Paused            bool     `json:"paused"`
	Type              string   `json:"type"`
	Host              struct {
		Name    string
		Website string
	} `json:"host"`
	VanityNS    []string `json:"vanity_name_servers"`
	Betas       []string `json:"betas"`
	DeactReason string   `json:"deactivation_reason"`
	Meta        ZoneMeta `json:"meta"`
}

Zone describes a CloudFlare zone.

type ZoneAnalytics

type ZoneAnalytics struct {
	Since    time.Time `json:"since"`
	Until    time.Time `json:"until"`
	Requests struct {
		All         int            `json:"all"`
		Cached      int            `json:"cached"`
		Uncached    int            `json:"uncached"`
		ContentType map[string]int `json:"content_type"`
		Country     map[string]int `json:"country"`
		SSL         struct {
			Encrypted   int `json:"encrypted"`
			Unencrypted int `json:"unencrypted"`
		} `json:"ssl"`
		HTTPStatus map[string]int `json:"http_status"`
	} `json:"requests"`
	Bandwidth struct {
		All         int            `json:"all"`
		Cached      int            `json:"cached"`
		Uncached    int            `json:"uncached"`
		ContentType map[string]int `json:"content_type"`
		Country     map[string]int `json:"country"`
		SSL         struct {
			Encrypted   int `json:"encrypted"`
			Unencrypted int `json:"unencrypted"`
		} `json:"ssl"`
	} `json:"bandwidth"`
	Threats struct {
		All     int            `json:"all"`
		Country map[string]int `json:"country"`
		Type    map[string]int `json:"type"`
	} `json:"threats"`
	Pageviews struct {
		All           int            `json:"all"`
		SearchEngines map[string]int `json:"search_engines"`
	} `json:"pageviews"`
	Uniques struct {
		All int `json:"all"`
	}
}

ZoneAnalytics contains analytics data for a zone.

type ZoneAnalyticsColocation

type ZoneAnalyticsColocation struct {
	ColocationID string          `json:"colo_id"`
	Timeseries   []ZoneAnalytics `json:"timeseries"`
}

ZoneAnalyticsColocation contains analytics data by datacenter.

type ZoneAnalyticsData

type ZoneAnalyticsData struct {
	Totals     ZoneAnalytics   `json:"totals"`
	Timeseries []ZoneAnalytics `json:"timeseries"`
}

ZoneAnalyticsData contains totals and timeseries analytics data for a zone.

type ZoneAnalyticsOptions

type ZoneAnalyticsOptions struct {
	Since      *time.Time
	Until      *time.Time
	Continuous *bool
}

ZoneAnalyticsOptions represents the optional parameters in Zone Analytics endpoint requests.

type ZoneCustomSSL

type ZoneCustomSSL struct {
	ID            string     `json:"id"`
	Hosts         []string   `json:"hosts"`
	Issuer        string     `json:"issuer"`
	Signature     string     `json:"signature"`
	Status        string     `json:"status"`
	BundleMethod  string     `json:"bundle_method"`
	ZoneID        string     `json:"zone_id"`
	UploadedOn    time.Time  `json:"uploaded_on"`
	ModifiedOn    time.Time  `json:"modified_on"`
	ExpiresOn     time.Time  `json:"expires_on"`
	Priority      int        `json:"priority"`
	KeylessServer KeylessSSL `json:"keyless_server"`
}

ZoneCustomSSL represents custom SSL certificate metadata.

type ZoneCustomSSLOptions

type ZoneCustomSSLOptions struct {
	Certificate  string `json:"certificate"`
	PrivateKey   string `json:"private_key"`
	BundleMethod string `json:"bundle_method,omitempty"`
}

ZoneCustomSSLOptions represents the parameters to create or update an existing custom SSL configuration.

type ZoneCustomSSLPriority

type ZoneCustomSSLPriority struct {
	ID       string `json:"ID"`
	Priority int    `json:"priority"`
}

ZoneCustomSSLPriority represents a certificate's ID and priority. It is a subset of ZoneCustomSSL used for patch requests.

type ZoneID

type ZoneID struct {
	ID string `json:"id"`
}

ZoneID contains only the zone ID.

type ZoneIDResponse

type ZoneIDResponse struct {
	Response
	Result ZoneID `json:"result"`
}

ZoneIDResponse represents the response from the Zone endpoint, containing only a zone ID.

type ZoneMeta

type ZoneMeta struct {
	// custom_certificate_quota is broken - sometimes it's a string, sometimes a number!
	// CustCertQuota     int    `json:"custom_certificate_quota"`
	PageRuleQuota     int  `json:"page_rule_quota"`
	WildcardProxiable bool `json:"wildcard_proxiable"`
	PhishingDetected  bool `json:"phishing_detected"`
}

ZoneMeta metadata about a zone.

type ZoneOptions

type ZoneOptions struct {
	// FIXME(jamesog): Using omitempty here means we can't disable Paused.
	// Currently unsure how to work around this.
	Paused   bool      `json:"paused,omitempty"`
	VanityNS []string  `json:"vanity_name_servers,omitempty"`
	Plan     *ZonePlan `json:"plan,omitempty"`
}

ZoneOptions is a subset of Zone, for editable options.

type ZonePlan

type ZonePlan struct {
	ID           string `json:"id"`
	Name         string `json:"name,omitempty"`
	Price        int    `json:"price,omitempty"`
	Currency     string `json:"currency,omitempty"`
	Frequency    string `json:"frequency,omitempty"`
	LegacyID     string `json:"legacy_id,omitempty"`
	IsSubscribed bool   `json:"is_subscribed,omitempty"`
	CanSubscribe bool   `json:"can_subscribe,omitempty"`
}

ZonePlan contains the plan information for a zone.

type ZonePlanResponse

type ZonePlanResponse struct {
	Response
	Result ZonePlan `json:"result"`
}

ZonePlanResponse represents the response from the Plan Details endpoint.

type ZoneRailgun

type ZoneRailgun struct {
	ID        string `json:"id"`
	Name      string `json:"name"`
	Enabled   bool   `json:"enabled"`
	Connected bool   `json:"connected"`
}

ZoneRailgun represents the status of a Railgun on a zone.

type ZoneResponse

type ZoneResponse struct {
	Response
	Result Zone `json:"result"`
}

ZoneResponse represents the response from the Zone endpoint containing a single zone.

type ZoneSetting

type ZoneSetting struct {
	ID            string      `json:"id"`
	Editable      bool        `json:"editable"`
	ModifiedOn    string      `json:"modified_on"`
	Value         interface{} `json:"value"`
	TimeRemaining int         `json:"time_remaining"`
}

ZoneSetting contains settings for a zone.

type ZoneSettingResponse

type ZoneSettingResponse struct {
	Response
	Result []ZoneSetting `json:"result"`
}

ZoneSettingResponse represents the response from the Zone Setting endpoint.

type ZonesResponse

type ZonesResponse struct {
	Response
	Result []Zone `json:"result"`
}

ZonesResponse represents the response from the Zone endpoint containing an array of zones.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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