cloudflare

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

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

Go to latest
Published: Dec 27, 2015 License: Apache-2.0 Imports: 7 Imported by: 0

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.0

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

$ cf zones list
+----------------------------------+-------------------+--------+---------+
|                ID                |       NAME        | PAUSED | STATUS  |
+----------------------------------+-------------------+--------+---------+
| xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | xxxxxxxxxxx.com   | no     | pending |
| xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | xxxxxxxxxxx.com   | no     | pending |
| xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | xxxxxxxxxxx.com   | no     | active  |
| xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | xxxxxxxxxxx.com   | no     | active  |
+----------------------------------+-------------------+--------+---------+
$ cf records list 5xxxxxcxxxxxxxxxxxxxxxxxxxxxxxx2
+----------------------------------+------+------------------+-------------+-----------+---------+--------+-----+---------------------+---------------------+
|                ID                | TYPE |       NAME       |   CONTENT   | PROXIABLE | PROXIED | LOCKED | TTL |     CREATED ON      |     MODIFIED ON     |
+----------------------------------+------+------------------+-------------+-----------+---------+--------+-----+---------------------+---------------------+
| xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | A    | xxxxxxxxx.pl     | xx.xx.xx.xx | yes       | yes     | no     |   1 | 2015/01/13 15:53:59 | 2015/01/13 15:53:59 |
| xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx | A    | www.xxxxxxxxx.pl | xx.xx.xx.xx | yes       | yes     | no     |   1 | 2015/01/13 15:53:59 | 2015/01/13 15:53:59 |
+----------------------------------+------+------------------+-------------+-----------+---------+--------+-----+---------------------+---------------------+

Usage

package main

import (
	"log"
	"time"

	"github.com/crackcomm/cloudflare"

	"golang.org/x/net/context"
)

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

	ctx := context.Background()
	ctx, _ = context.WithDeadline(ctx, time.Now().Add(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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	*Zones
	*Records
	// contains filtered or unexported fields
}

Client - Cloudflare API Client.

func New

func New(opts *Options) *Client

New - Creates a new Cloudflare client.

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

	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 {
	// contains filtered or unexported fields
}

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.

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           string `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 {
	// contains filtered or unexported fields
}

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.

func (*Zones) Details

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

Details - Requests Zone details by ID.

func (*Zones) List

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

List - Lists all zones.

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