digitalocean

package module
Version: v0.0.0-...-e966f00 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2015 License: MPL-2.0 Imports: 9 Imported by: 54

README

digitalocean

This package provides the digitalocean package which offers an interface to the DigitalOcean V2 API.

It's intentionally designed to make heavy use of built-ins and strings in place of custom data structures and proper types. It also only implements specific endpoints, and doesn't have full API coverage.

For those reasons, I recommend looking elsewhere if you just need a standard DO API client.

Documentation

The full documentation is available on Godoc

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// Access Token
	Token string

	// URL to the DO API to use
	URL string

	// HttpClient is the client to use. Default will be
	// used if not provided.
	Http *http.Client
}

Client provides a client to the DigitalOcean API

func NewClient

func NewClient(token string) (*Client, error)

NewClient returns a new digitalocean client, requires an authorization token. You can generate an OAuth token by visiting the Apps & API section of the DigitalOcean control panel for your account.

func (*Client) Action

func (c *Client) Action(id string, action map[string]interface{}) error

Action sends the specified action to the droplet. An error is retunred, and is nil if successful

func (*Client) CreateDomain

func (c *Client) CreateDomain(opts *CreateDomain) (string, error)

CreateDomain creates a domain from the parameters specified and returns an error if it fails. If no error and the name is returned, the Domain was succesfully created.

func (*Client) CreateDroplet

func (c *Client) CreateDroplet(opts *CreateDroplet) (string, error)

CreateDroplet creates a droplet from the parameters specified and returns an error if it fails. If no error and an ID is returned, the Droplet was succesfully created.

func (*Client) CreateRecord

func (c *Client) CreateRecord(domain string, opts *CreateRecord) (string, error)

CreateRecord creates a record from the parameters specified and returns an error if it fails. If no error and the name is returned, the Record was succesfully created.

func (*Client) CreateSSHKey

func (c *Client) CreateSSHKey(opts *CreateSSHKey) (string, error)

CreateSSHKey creates an SSH key from the parameters specified and returns an error if it fails. If no error and the SSH key is returned, it was succesfully created.

func (*Client) DestroyDomain

func (c *Client) DestroyDomain(name string) error

DestroyDomain destroys a domain by the ID specified and returns an error if it fails. If no error is returned, the Domain was succesfully destroyed.

func (*Client) DestroyDroplet

func (c *Client) DestroyDroplet(id string) error

DestroyDroplet destroys a droplet by the ID specified and returns an error if it fails. If no error is returned, the Droplet was succesfully destroyed.

func (*Client) DestroyRecord

func (c *Client) DestroyRecord(domain string, id string) error

DestroyRecord destroys a record by the ID specified and returns an error if it fails. If no error is returned, the Record was succesfully destroyed.

func (*Client) DestroySSHKey

func (c *Client) DestroySSHKey(id string) error

DestroySSHKey destroys an SSH key by the ID specified and returns an error if it fails. If no error is returned, the key was succesfully destroyed.

func (*Client) EnableIPV6s

func (c *Client) EnableIPV6s(id string) error

Enables IPV6 on the droplet

func (*Client) EnablePrivateNetworking

func (c *Client) EnablePrivateNetworking(id string) error

Enables private networking on the droplet

func (*Client) NewRequest

func (c *Client) NewRequest(body interface{}, method string, endpoint string) (*http.Request, error)

Creates a new request with the params

func (*Client) PowerOff

func (c *Client) PowerOff(id string) error

Resizes a droplet to the size slug specified

func (*Client) PowerOn

func (c *Client) PowerOn(id string) error

Resizes a droplet to the size slug specified

func (*Client) Rename

func (c *Client) Rename(id string, name string) error

Renames a droplet to the name specified

func (*Client) RenameSSHKey

func (c *Client) RenameSSHKey(id string, name string) error

RenameSSHKey renames an SSH key to the name specified

func (*Client) Resize

func (c *Client) Resize(id string, size string) error

Resizes a droplet to the size slug specified

func (*Client) RetrieveDomain

func (c *Client) RetrieveDomain(name string) (Domain, error)

RetrieveDomain gets a domain by the ID specified and returns a Domain and an error. An error will be returned for failed requests with a nil Domain.

func (*Client) RetrieveDroplet

func (c *Client) RetrieveDroplet(id string) (Droplet, error)

RetrieveDroplet gets a droplet by the ID specified and returns a Droplet and an error. An error will be returned for failed requests with a nil Droplet.

func (*Client) RetrieveDroplets

func (c *Client) RetrieveDroplets() ([]Droplet, error)

RetrieveDroplets gets the list of Droplets and an error. An error will be returned for failed requests with a nil slice.

func (*Client) RetrieveRecord

func (c *Client) RetrieveRecord(domain string, id string) (Record, error)

RetrieveRecord gets a record by the ID specified and returns a Record and an error. An error will be returned for failed requests with a nil Record.

func (*Client) RetrieveSSHKey

func (c *Client) RetrieveSSHKey(id string) (SSHKey, error)

RetrieveSSHKey gets an SSH key by the ID specified and returns a SSHKey and an error. An error will be returned for failed requests with a nil SSHKey.

func (*Client) UpdateRecord

func (c *Client) UpdateRecord(domain string, id string, opts *UpdateRecord) error

UpdateRecord destroys a record by the ID specified and returns an error if it fails. If no error is returned, the Record was succesfully updated.

func (*Client) VerifyAuthentication

func (c *Client) VerifyAuthentication() error

VerifyAuthentication makes a simple request to verify the provided authentication is working and returns an error if it is not.

type CreateDomain

type CreateDomain struct {
	Name      string // Name of the domain
	IPAddress string // IPAddress of the domain
}

CreateDomain contains the request parameters to create a new domain.

type CreateDroplet

type CreateDroplet struct {
	Name              string   `json:"name,omitempty"`               // Name of the droplet
	Region            string   `json:"region,omitempty"`             // Slug of the region to create the droplet in
	Size              string   `json:"size,omitempty"`               // Slug of the size to use for the droplet
	Image             string   `json:"image,omitempty"`              // Slug of the image, if using a public image
	SSHKeys           []string `json:"ssh_keys,omitempty"`           // Array of SSH Key IDs that should be added
	Backups           bool     `json:"backups,omitempty"`            // true or false if backups are enabled
	IPV6              bool     `json:"ipv6,omitempty"`               // true or false if IPV6 is enabled
	PrivateNetworking bool     `json:"private_networking,omitempty"` // true or false if Private Networking is enabled
	UserData          string   `json:"user_data,omitempty"`          // metadata for the droplet
}

CreateDroplet contains the request parameters to create a new droplet.

type CreateRecord

type CreateRecord struct {
	Type     string
	Name     string
	Data     string
	Priority string
	Port     string
	Weight   string
}

CreateRecord contains the request parameters to create a new record.

type CreateSSHKey

type CreateSSHKey struct {
	Name      string `json:"name,omitempty"`
	PublicKey string `json:"public_key,omitempty"`
}

CreateSSHKey contains the request parameters to register a new SSH key.

type DoError

type DoError struct {
	Id      string `json:"id"`
	Message string `json:"message"`
}

DoError is the error format that they return to us if there is a problem

type Domain

type Domain struct {
	Name     string `json:"name"`
	ZoneFile string `json:"zone_file"`
}

Domain is used to represent a retrieved Domain. All properties are set as strings.

type DomainResponse

type DomainResponse struct {
	Domain Domain `json:"domain"`
}

type Droplet

type Droplet struct {
	Id       int64                               `json:"id"`
	Name     string                              `json:"name"`
	Region   map[string]interface{}              `json:"region"`
	Image    map[string]interface{}              `json:"image"`
	SizeSlug string                              `json:"size_slug"`
	Locked   bool                                `json:"locked"`
	Status   string                              `json:"status"`
	Networks map[string][]map[string]interface{} `json:"networks"`
}

Droplet is used to represent a retrieved Droplet. All properties are set as strings.

func (*Droplet) IPV4Address

func (d *Droplet) IPV4Address(addressType string) string

Returns the ipv4 address

func (*Droplet) IPV6Address

func (d *Droplet) IPV6Address(addressType string) string

Returns the ipv6 adddress

func (*Droplet) ImageId

func (d *Droplet) ImageId() string

func (*Droplet) ImageSlug

func (d *Droplet) ImageSlug() string

Returns the slug for the image

func (*Droplet) IsLocked

func (d *Droplet) IsLocked() string

Returns the string for Locked

func (*Droplet) NetworkingType

func (d *Droplet) NetworkingType() string

Currently DO only has a network type per droplet, so we just takes ipv4s

func (*Droplet) RegionSlug

func (d *Droplet) RegionSlug() string

Returns the slug for the region

func (*Droplet) StringId

func (d *Droplet) StringId() string

Returns the slug for the region

type DropletResponse

type DropletResponse struct {
	Droplet Droplet `json:"droplet"`
}

type DropletsResponse

type DropletsResponse struct {
	Droplets []Droplet `json:"droplets"`
}

type Record

type Record struct {
	Id       int    `json:"id"`
	Type     string `json:"type"`
	Name     string `json:"name"`
	Data     string `json:"data"`
	Priority int    `json:"priority"`
	Port     int    `json:"port"`
	Weight   int    `json:"weight"`
}

Record is used to represent a retrieved Record. All properties are set as strings.

func (*Record) StringId

func (r *Record) StringId() string

func (*Record) StringPort

func (r *Record) StringPort() string

func (*Record) StringPriority

func (r *Record) StringPriority() string

func (*Record) StringWeight

func (r *Record) StringWeight() string

type RecordResponse

type RecordResponse struct {
	Record Record `json:"domain_record"`
}

type SSHKey

type SSHKey struct {
	Id          int64  `json:"id"`
	Name        string `json:"name"`
	Fingerprint string `json:"fingerprint"`
	PublicKey   string `json:"public_key"`
}

SSHKey is used to represent a retrieved SSH key.

func (*SSHKey) StringId

func (k *SSHKey) StringId() string

StringId returns the slug for the key

type UpdateRecord

type UpdateRecord struct {
	Name string
}

UpdateRecord contains the request parameters to create a new record.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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