cloudflare

package module
v0.0.0-...-84c7a09 Latest Latest
Warning

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

Go to latest
Published: May 3, 2016 License: BSD-3-Clause Imports: 7 Imported by: 19

README

GoDoc

cloudflare

A Go library for interacting with CloudFlare's API v4.

Installation

You need a working Go environment.

go get github.com/cloudflare/cloudflare-go

Getting Started

package main

import (
	"fmt"

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

var api *cloudflare.API

func main() {
	// Construct a new API object
	api = cloudflare.New(os.Getenv("CF_API_KEY"), os.Getenv("CF_API_EMAIL"))

	// Fetch the list of zones on the account
	zones, err := api.ListZones()
	if err != nil {
		fmt.Println(err)
	}
	// Print the zone names
	for _, z := range zones {
		fmt.Println(z.Name)
	}
}

An example application, flarectl, is in this repository.

Documentation

Overview

Package cloudflare implements the CloudFlare v4 API.

New API requests created like:

api := cloudflare.New(apikey, apiemail)

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_security":    "Disable Security",
	"edge_cache_ttl":      "Edge Cache TTL",
	"email_obfuscation":   "Email Obfuscation",
	"forwarding_url":      "Forwarding URL",
	"ip_geolocation":      "IP Geolocation Header",
	"mirage":              "Mirage",
	"railgun":             "Railgun",
	"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

func DeleteZone

func DeleteZone()

https://api.cloudflare.com/#zone-delete-a-zone DELETE /zones/:id

func EditZone

func EditZone()

https://api.cloudflare.com/#zone-edit-zone-properties PATCH /zones/:id

Types

type API

type API struct {
	APIKey   string
	APIEmail string
}

func New

func New(key, email string) *API

Initializes the API configuration.

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) CreateDNSRecord

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

Create a DNS record.

API reference:

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

func (*API) CreateKeyless

func (c *API) CreateKeyless()

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 (c *API) CreateRailgun()

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

func (*API) CreateSSL

func (c *API) CreateSSL()

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

func (*API) CreateZone

func (api *API) CreateZone(z Zone)

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)

Fetches a single DNS record.

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)

Fetches DNS records for a zone.

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

Delete a DNS record.

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 (c *API) DeleteKeyless()

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) DeleteSSL

func (c *API) DeleteSSL()

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

func (*API) Keyless

func (c *API) Keyless()

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

func (*API) ListKeyless

func (c *API) ListKeyless()

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) ListSSL

func (c *API) ListSSL()

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

func (*API) ListWAFPackages

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

func (*API) ListWAFRules

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

func (*API) ListZones

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

List zones on an account. Optionally takes a list of zones to filter results.

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) PurgeEverything

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

https://api.cloudflare.com/#zone-purge-all-files DELETE /zones/:id/purge_cache

func (*API) Railgun

func (c *API) Railgun()

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

func (*API) Railguns

func (c *API) Railguns()

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

func (*API) ReprioSSL

func (c *API) ReprioSSL()

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

func (*API) SSLDetails

func (c *API) SSLDetails()

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

func (*API) UpdateDNSRecord

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

Change a DNS record.

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 (c *API) UpdateKeyless()

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 (c *API) UpdateSSL()

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)

Update user properties.

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

func (API) UserDetails

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

Information about the logged-in user.

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

func (*API) ZoneDetails

func (api *API) ZoneDetails(z Zone)

Fetches information about a zone.

https://api.cloudflare.com/#zone-zone-details
GET /zones/:id

func (*API) ZoneIDByName

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

ZoneIDByName retrieves a zone's ID from the name.

func (*API) ZoneRailgun

func (c *API) ZoneRailgun(connected bool)

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

type CustomPage

type CustomPage struct {
	CreatedOn      string   `json:"created_on"`
	ModifiedOn     string   `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"`
}

Custom error pages.

type CustomPageResponse

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

type DNSListResponse

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

The response for listing DNS records.

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  string      `json:"created_on,omitempty"`
	ModifiedOn string      `json:"modified_on,omitempty"`
	Data       interface{} `json:"data,omitempty"` // data returned by: SRV, LOC
	Meta       interface{} `json:"meta,omitempty"`
	Priority   int         `json:"priority,omitempty"`
}

Describes a DNS record for a zone.

type DNSRecordResponse

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

The response for creating or updating a DNS record.

type IPRanges

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

IPs contains a list 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 {
	Success  bool     `json:"success"`
	Errors   []string `json:"errors"`
	Messages []string `json:"messages"`
	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   string   `json:"created_on"`
	ModifiedOn  string   `json:"modifed_on"`
}

type KeylessSSLResponse

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

type Organization

type Organization struct {
	ID          string
	Name        string
	Status      string
	Permissions []string
	Roles       []string
}

An Organization describes a multi-user organization. (Enterprise only.)

type Owner

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

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 string           `json:"modified_on,omitempty"`
	CreatedOn  string           `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_security
edge_cache_ttl
email_obfuscation
forwarding_url
ip_geolocation
mirage
railgun
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"`
}

type PurgeCacheResponse

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

type Railgun

type Railgun struct {
	ID             string `json:"id"`
	Name           string `json:"name"`
	Status         string `json:"success"`
	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    string `json:"activated_on"`
	CreatedOn      string `json:"created_on"`
	ModifiedOn     string `json:"modified_on"`
}

type RailgunResponse

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

type Response

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

The Response struct 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 ResultInfo

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

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     string         `json:"created_on"` // Should this be a time.Date?
	ModifiedOn    string         `json:"modified_on"`
	APIKey        string         `json:"api_key"`
	TwoFA         bool           `json:"two_factor_authentication_enabled"`
	Betas         []string       `json:"betas"`
	Organizations []Organization `json:"organizations"`
}

A User describes a user account.

type UserResponse

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

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"`
}

WAF packages

type WAFPackagesResponse

type WAFPackagesResponse struct {
	Result     []WAFPackage `json:"result"`
	Success    bool         `json:"success"`
	ResultInfo struct {
		Page       uint `json:"page"`
		PerPage    uint `json:"per_page"`
		Count      uint `json:"count"`
		TotalCount uint `json:"total_count"`
	} `json:"result_info"`
}

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"`
}

type WAFRulesResponse

type WAFRulesResponse struct {
	Result     []WAFRule `json:"result"`
	Success    bool      `json:"success"`
	ResultInfo struct {
		Page       uint `json:"page"`
		PerPage    uint `json:"per_page"`
		Count      uint `json:"count"`
		TotalCount uint `json:"total_count"`
	} `json:"result_info"`
}

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"`
	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"`
}

A Zone describes a CloudFlare zone.

func NewZone

func NewZone() *Zone

Initializes a new zone.

type ZoneCustomSSL

type ZoneCustomSSL struct {
	ID            string     `json:"id"`
	Hosts         []string   `json:"hosts"`
	Issuer        string     `json:"issuer"`
	Priority      int        `json:"priority"`
	Status        string     `json:"success"`
	BundleMethod  string     `json:"bundle_method"`
	ZoneID        string     `json:"zone_id"`
	Permissions   []string   `json:"permissions"`
	UploadedOn    string     `json:"uploaded_on"`
	ModifiedOn    string     `json:"modified_on"`
	ExpiresOn     string     `json:"expires_on"`
	KeylessServer KeylessSSL `json:"keyless_server"`
}

Custom SSL certificates for a zone.

type ZoneCustomSSLResponse

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

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"`
}

Contains metadata about a zone.

type ZonePlan

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

Contains the plan information for a zone.

type ZonePlanResponse

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

type ZoneRailgun

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

Railgun status for a zone.

type ZoneRailgunResponse

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

type ZoneResponse

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

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"`
}

type ZoneSettingResponse

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

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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