cloudflare

package module
v0.0.0-...-dc35819 Latest Latest
Warning

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

Go to latest
Published: May 3, 2016 License: Apache-2.0 Imports: 8 Imported by: 22

README

Golang CloudFlare® API v4 client

GoDoc Circle CI

Golang API Client for CloudFlare® API v4.

Command Line Tool

$ go install github.com/crackcomm/cloudflare/cf
$ cf
NAME:
   cf - CloudFlare command line tool

USAGE:
   cf [global options] command [command options] [arguments...]

VERSION:
   1.0.1

COMMANDS:
   zones	zones management
   records	zone records management
   help, h	Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --email 		CloudFlare user email [$CLOUDFLARE_EMAIL]
   --key 		CloudFlare user key [$CLOUDFLARE_KEY]
   --help, -h		show help
   --version, -v	print the version

Usage

package main

import (
	"log"
	"time"

	"golang.org/x/net/context"

	"github.com/crackcomm/cloudflare"
)

func main() {
	client := cloudflare.New(&cloudflare.Options{
		Email: "[email protected]",
		Key:   "example-key",
	})

	ctx := context.Background()
	ctx, _ = context.WithTimeout(ctx, time.Second*30)

	zones, err := client.Zones.List(ctx)
	if err != nil {
		log.Fatal(err)
	} else if len(zones) == 0 {
		log.Fatal("No zones were found")
	}

	records, err := client.Records.List(ctx, zones[0].ID)
	if err != nil {
		log.Fatal(err)
	}

	for _, record := range records {
		log.Printf("%#v", record)
	}
}

CloudFlare®

CloudFlare is a registered trademark of CloudFlare, Inc.

License

Apache 2.0 License.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// Zones - Zones API Client.
	*Zones
	// Records - Records API Client.
	*Records
	// Firewalls - Firewalls API Client.
	*Firewalls
	// Options - API Client options.
	*Options
}

Client - Cloudflare API Client.

func New

func New(opts *Options) *Client

New - Creates a new Cloudflare client.

type Firewall

type Firewall struct {
	ID string `json:"id,omitempty"`

	Notes        string   `json:"notes,omitempty"`
	AllowedModes []string `json:"allowed_modes,omitempty"`
	Mode         string   `json:"mode,omitempty"`

	Configuration *FirewallConfiguration `json:"configuration,omitempty"`
	Scope         *ZoneOwner             `json:"scope,omitempty"`

	CreatedOn  time.Time `json:"created_on,omitempty"`
	ModifiedOn time.Time `json:"modified_on,omitempty"`
}

Firewall - Firewall for zone.

type FirewallConfiguration

type FirewallConfiguration struct {
	Target string `json:"target,omitempty"`
	Value  string `json:"value,omitempty"`
}

FirewallConfiguration - Firewall configuration for the zone.

type Firewalls

type Firewalls struct {
	// Options - Client options.
	*Options
}

Firewalls - Cloudflare Fireall Zones API Client.

func (*Firewalls) Create

func (firewalls *Firewalls) Create(ctx context.Context, id string, firewall *Firewall) (fw *Firewall, err error)

Create - Creates a firewall rule for zone.

func (*Firewalls) Delete

func (firewalls *Firewalls) Delete(ctx context.Context, zone, id string) (err error)

Delete - Deletes firewall by id.

func (*Firewalls) List

func (firewalls *Firewalls) List(ctx context.Context, zone string) ([]*Firewall, error)

List - Lists all firewall rules for zone.

Example

ExampleFirewalls_List - Lists all firewall rules for a zone.

var client *Client
ctx := context.Background()

zones, err := client.Zones.List(ctx)
if err != nil {
	log.Fatal(err)
} else if len(zones) == 0 {
	log.Fatal("No zones were found")
}

rules, err := client.Firewalls.List(ctx, zones[0].ID)
if err != nil {
	log.Fatal(err)
}

for _, rule := range rules {
	log.Printf("%#v", rule)
}
Output:

type Options

type Options struct {
	Email, Key string
}

Options - Cloudflare API Client Options.

type Record

type Record 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"`
	Locked    bool `json:"locked,omitempty"`

	TTL      int `json:"ttl,omitempty"`
	Priority int `json:"priority,omitempty"`

	CreatedOn  time.Time `json:"created_on,omitempty"`
	ModifiedOn time.Time `json:"modified_on,omitempty"`

	ZoneID   string `json:"zone_id,omitempty"`
	ZoneName string `json:"zone_name,omitempty"`
}

Record - Cloudflare DNS Record.

type Records

type Records struct {
	// Options - Client options.
	*Options
}

Records - Cloudflare Records API Client.

func (*Records) Create

func (records *Records) Create(ctx context.Context, record *Record) (err error)

Create - Creates a zone DNS record. Required parameters of a record are - `type`, `name` and `content`. Optional parameters of a record are - `ttl`.

func (*Records) Delete

func (records *Records) Delete(ctx context.Context, zoneID, recordID string) (err error)

Delete - Deletes zone DNS record by zone ID and record ID.

func (*Records) Details

func (records *Records) Details(ctx context.Context, zoneID, recordID string) (record *Record, err error)

Details - Requests zone DNS record details by zone ID and record ID.

func (*Records) List

func (records *Records) List(ctx context.Context, zoneID string) ([]*Record, error)

List - Lists all zone DNS records.

Example

ExampleRecords_List - Lists all zone DNS records.

var client *Client
ctx := context.Background()

zones, err := client.Zones.List(ctx)
if err != nil {
	log.Fatal(err)
} else if len(zones) == 0 {
	log.Fatal("No zones were found")
}

records, err := client.Records.List(ctx, zones[0].ID)
if err != nil {
	log.Fatal(err)
}

for _, record := range records {
	log.Printf("%#v", record)
}
Output:

func (*Records) Patch

func (records *Records) Patch(ctx context.Context, record *Record) (err error)

Patch - Patches a zone DNS record.

type Response

type Response struct {
	Result     json.RawMessage `json:"result"`
	ResultInfo *ResultInfo     `json:"result_info"`

	Errors  []*ResponseError `json:"errors"`
	Success bool             `json:"success"`
}

Response - Cloudflare API Response.

func (*Response) Err

func (response *Response) Err() error

Err - Gets response error if any.

type ResponseError

type ResponseError struct {
	Code    int    `json:"code,omitempty"`
	Message string `json:"message,omitempty"`
}

ResponseError - Cloudflare API Response error.

func (*ResponseError) Error

func (err *ResponseError) Error() string

Error - Returns response error message.

type ResultInfo

type ResultInfo struct {
	Page       int `json:"page,omitempty"`
	PerPage    int `json:"per_page,omitempty"`
	TotalPages int `json:"total_pages,omitempty"`
	Count      int `json:"count,omitempty"`
	TotalCount int `json:"total_count,omitempty"`
}

ResultInfo - Cloudflare API Response Result Info.

type Zone

type Zone struct {
	ID              string `json:"id,omitempty"`
	Name            string `json:"name,omitempty"`
	Status          string `json:"status,omitempty"`
	Paused          bool   `json:"paused,omitempty"`
	Type            string `json:"type,omitempty"`
	DevelopmentMode int    `json:"development_mode,omitempty"`

	NameServers         []string `json:"name_servers,omitempty"`
	OriginalNameServers []string `json:"original_name_servers,omitempty"`

	ModifiedOn time.Time `json:"modified_on,omitempty"`
	CreatedOn  time.Time `json:"created_on,omitempty"`
	CheckedOn  time.Time `json:"checked_on,omitempty"`

	Meta  *ZoneMeta  `json:"meta,omitempty"`
	Owner *ZoneOwner `json:"owner,omitempty"`
	Plan  *ZonePlan  `json:"plan,omitempty"`

	Permissions []string `json:"permissions,omitempty"`
}

Zone - Cloudflare Zone.

type ZoneMeta

type ZoneMeta struct {
	Step                    int  `json:"step,omitempty"`
	PageRuleQuota           int  `json:"page_rule_quota,omitempty"`
	CustomCertificateQuota  int  `json:"custom_certificate_quota,omitempty"`
	WildcardProxiable       bool `json:"wildcard_proxiable,omitempty"`
	PhishingDetected        bool `json:"phishing_detected,omitempty"`
	MultipleRailgunsAllowed bool `json:"multiple_railguns_allowed,omitempty"`
}

ZoneMeta -

type ZoneOwner

type ZoneOwner struct {
	Type  string `json:"type,omitempty"`
	ID    string `json:"id,omitempty"`
	Email string `json:"email,omitempty"`
}

ZoneOwner -

type ZonePatch

type ZonePatch struct {
	Plan              *ZonePlan `json:"plan,omitempty"`
	Paused            bool      `json:"paused,omitempty"`
	VanityNameServers []string  `json:"vanity_name_servers,omitempty"`
}

ZonePatch -

type ZonePlan

type ZonePlan struct {
	ID                string `json:"id,omitempty"`
	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"`
	ExternallyManaged bool   `json:"externally_managed,omitempty"`
}

ZonePlan -

type Zones

type Zones struct {
	// Options - Client options.
	*Options
}

Zones - Cloudflare Zones API Client.

func (*Zones) Create

func (zones *Zones) Create(ctx context.Context, domain string) (zone *Zone, err error)

Create - Creates a zone.

func (*Zones) Delete

func (zones *Zones) Delete(ctx context.Context, id string) (err error)

Delete - Deletes zone by id.

Example

ExampleZones_Delete - Deletes zone by ID.

var client *Client
ctx := context.Background()

zones, err := client.Zones.List(ctx)
if err != nil {
	log.Fatal(err)
} else if len(zones) == 0 {
	log.Fatal("No zones were found")
}

err = client.Zones.Delete(ctx, zones[0].ID)
if err != nil {
	log.Fatal(err)
}

log.Printf("Deleted %s", zones[0].ID)
Output:

func (*Zones) Details

func (zones *Zones) Details(ctx context.Context, id string) (zone *Zone, err error)

Details - Requests Zone details by ID.

Example

ExampleZones_Details - Gets zone details by ID.

var client *Client
ctx := context.Background()

zones, err := client.Zones.List(ctx)
if err != nil {
	log.Fatal(err)
} else if len(zones) == 0 {
	log.Fatal("No zones were found")
}

zone, err := client.Zones.Details(ctx, zones[0].ID)
if err != nil {
	log.Fatal(err)
}

log.Printf("Got %s = %#v", zones[0].ID, zone)
Output:

func (*Zones) List

func (zones *Zones) List(ctx context.Context) ([]*Zone, error)

List - Lists all zones.

Example

ExampleZones_List - Lists all zones.

var client *Client
ctx := context.Background()

zones, err := client.Zones.List(ctx)
if err != nil {
	log.Fatal(err)
}

for _, zone := range zones {
	log.Printf("%s", zone.Name)
}
Output:

func (*Zones) Patch

func (zones *Zones) Patch(ctx context.Context, id string, patch *ZonePatch) (err error)

Patch - Patches a zone. It has a limited possibilities.

Directories

Path Synopsis
Godeps
_workspace/src/github.com/codegangsta/cli
Package cli provides a minimal framework for creating and organizing command line Go applications.
Package cli provides a minimal framework for creating and organizing command line Go applications.
_workspace/src/github.com/olekukonko/tablewriter
Create & Generate text based table
Create & Generate text based table
_workspace/src/golang.org/x/net/context
Package context defines the Context type, which carries deadlines, cancelation signals, and other request-scoped values across API boundaries and between processes.
Package context defines the Context type, which carries deadlines, cancelation signals, and other request-scoped values across API boundaries and between processes.
_workspace/src/golang.org/x/net/context/ctxhttp
Package ctxhttp provides helper functions for performing context-aware HTTP requests.
Package ctxhttp provides helper functions for performing context-aware HTTP requests.
cf
cmd
Package cmd implements cloudflare cli commands.
Package cmd implements cloudflare cli commands.

Jump to

Keyboard shortcuts

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