1
0
Fork 0

Vendor main dependencies.

This commit is contained in:
Timo Reimann 2017-02-07 22:33:23 +01:00
parent 49a09ab7dd
commit dd5e3fba01
2738 changed files with 1045689 additions and 0 deletions

69
vendor/github.com/timewasted/linode/dns/dns.go generated vendored Normal file
View file

@ -0,0 +1,69 @@
package dns
import (
"strconv"
"github.com/timewasted/linode"
)
type (
// DNS represents the interface to the DNS portion of Linode's API.
DNS struct {
linode *linode.Linode
}
)
// New returns a pointer to a new DNS object.
func New(apiKey string) *DNS {
return &DNS{
linode: linode.New(apiKey),
}
}
// FromLinode returns a pointer to a new DNS object, using the provided Linode
// instance as backing.
func FromLinode(l *linode.Linode) *DNS {
return &DNS{
linode: l,
}
}
// ToLinode returns a pointer to the internal Linode object.
func (d *DNS) ToLinode() *linode.Linode {
return d.linode
}
// GetDomains executes the "domain.list" API call. When domainID is nil, this
// will return a list of domains. Otherwise, it will return only the domain
// specified by domainID.
func (d *DNS) GetDomains(domainId interface{}) ([]*Domain, error) {
params := linode.Parameters{}
if domainId != nil {
id, ok := domainId.(int)
if ok {
params.Set("DomainID", strconv.Itoa(id))
}
}
var list []*Domain
_, err := d.linode.Request("domain.list", params, &list)
if err != nil {
return nil, err
}
return list, nil
}
// GetDomainResources executes the "domain.resource.list" API call. This will
// return a list of domain resources associated with the specified domainID.
func (d *DNS) GetDomainResources(domainID int) ([]*Resource, error) {
params := linode.Parameters{
"DomainID": strconv.Itoa(domainID),
}
var list []*Resource
_, err := d.linode.Request("domain.resource.list", params, &list)
if err != nil {
return nil, err
}
return list, nil
}

63
vendor/github.com/timewasted/linode/dns/domain.go generated vendored Normal file
View file

@ -0,0 +1,63 @@
package dns
import (
"errors"
"strconv"
"strings"
"github.com/timewasted/linode"
)
type (
// Domain represents a domain.
Domain struct {
AXFR_IPs string `json:"AXFR_IPS"`
Description string `json:"DESCRIPTION"`
Domain string `json:"DOMAIN"`
DomainID int `json:"DOMAINID"`
Expire_Sec int `json:"EXPIRE_SEC"`
LPM_DisplayGroup string `json:"LPM_DISPLAYGROUP"`
Master_IPs string `json:"MASTER_IPS"`
Refresh_Sec int `json:"REFRESH_SEC"`
Retry_Sec int `json:"RETRY_SEC"`
SOA_Email string `json:"SOA_EMAIL"`
Status int `json:"STATUS"`
TTL_Sec int `json:"TTL_SEC"`
Type string `json:"TYPE"`
}
// DomainResponse represents the response to a create, update, or
// delete domain API call.
DomainResponse struct {
DomainID int `json:"DomainID"`
}
)
// DeleteDomain executes the "domain.delete" API call. This will delete the
// domain specified by domainID.
func (d *DNS) DeleteDomain(domainID int) (*DomainResponse, error) {
params := linode.Parameters{
"DomainID": strconv.Itoa(domainID),
}
var response *DomainResponse
_, err := d.linode.Request("domain.delete", params, &response)
if err != nil {
return nil, err
}
return response, nil
}
// GetDomain returns the specified domain. This search is not case-sensitive.
func (d *DNS) GetDomain(domain string) (*Domain, error) {
list, err := d.GetDomains(nil)
if err != nil {
return nil, err
}
for _, d := range list {
if strings.EqualFold(d.Domain, domain) {
return d, nil
}
}
return nil, linode.NewError(errors.New("dns: requested domain not found"))
}

228
vendor/github.com/timewasted/linode/dns/resource.go generated vendored Normal file
View file

@ -0,0 +1,228 @@
package dns
import (
"errors"
"strconv"
"strings"
"github.com/timewasted/linode"
)
type (
// Resource represents a domain resource.
Resource struct {
DomainID int `json:"DOMAINID"`
Name string `json:"NAME"`
Port interface{} `json:"PORT"`
Priority interface{} `json:"PRIORITY"`
Protocol string `json:"PROTOCOL"`
ResourceID int `json:"RESOURCEID"`
Target string `json:"TARGET"`
TTL_Sec int `json:"TTL_SEC"`
Type string `json:"TYPE"`
Weight interface{} `json:"WEIGHT"`
}
// ResourceResponse represents the response to a create, update, or
// delete resource API call.
ResourceResponse struct {
ResourceID int `json:"ResourceID"`
}
)
// CreateDomainResourceA executes the "domain.resource.create" API call. This
// will create a new "A" resource using the specified parameters.
func (d *DNS) CreateDomainResourceA(domainID int, name, target string, ttlSeconds int) (*ResourceResponse, error) {
return d.createDomainResource(linode.Parameters{
"Type": "A",
"DomainID": strconv.Itoa(domainID),
"Name": name,
"Target": target,
"TTL_Sec": strconv.Itoa(ttlSeconds),
})
}
// CreateDomainResourceAAAA executes the "domain.resource.create" API call.
// This will create a new "AAAA" resource using the specified parameters.
func (d *DNS) CreateDomainResourceAAAA(domainID int, name, target string, ttlSeconds int) (*ResourceResponse, error) {
return d.createDomainResource(linode.Parameters{
"Type": "AAAA",
"DomainID": strconv.Itoa(domainID),
"Name": name,
"Target": target,
"TTL_Sec": strconv.Itoa(ttlSeconds),
})
}
// CreateDomainResourceCNAME executes the "domain.resource.create" API call.
// This will create a new "CNAME" resource using the specified parameters.
func (d *DNS) CreateDomainResourceCNAME(domainID int, name, target string, ttlSeconds int) (*ResourceResponse, error) {
return d.createDomainResource(linode.Parameters{
"Type": "CNAME",
"DomainID": strconv.Itoa(domainID),
"Name": name,
"Target": target,
"TTL_Sec": strconv.Itoa(ttlSeconds),
})
}
// CreateDomainResourceMX executes the "domain.resource.create" API call. This
// will create a new "MX" resource using the specified parameters.
func (d *DNS) CreateDomainResourceMX(domainID int, name, target string, priority, ttlSeconds int) (*ResourceResponse, error) {
return d.createDomainResource(linode.Parameters{
"Type": "MX",
"DomainID": strconv.Itoa(domainID),
"Name": name,
"Target": target,
"Priority": strconv.Itoa(priority),
"TTL_Sec": strconv.Itoa(ttlSeconds),
})
}
// CreateDomainResourceNS executes the "domain.resource.create" API call. This
// will create a new "NS" resource using the specified parameters.
func (d *DNS) CreateDomainResourceNS(domainID int, name, target string, ttlSeconds int) (*ResourceResponse, error) {
return d.createDomainResource(linode.Parameters{
"Type": "NS",
"DomainID": strconv.Itoa(domainID),
"Name": name,
"Target": target,
"TTL_Sec": strconv.Itoa(ttlSeconds),
})
}
// CreateDomainResourceSRV executes the "domain.resource.create" API call. This
// will create a new "SRV" resource using the specified parameters.
func (d *DNS) CreateDomainResourceSRV(domainID int, name, target, protocol string, priority, ttlSeconds int) (*ResourceResponse, error) {
// FIXME: This probably also needs weight and port. Weight has a valid
// range of 0-255, while port is 0-65535.
return d.createDomainResource(linode.Parameters{
"Type": "SRV",
"DomainID": strconv.Itoa(domainID),
"Name": name,
"Target": target,
"Protocol": protocol,
"Priority": strconv.Itoa(priority),
"TTL_Sec": strconv.Itoa(ttlSeconds),
})
}
// CreateDomainResourceTXT executes the "domain.resource.create" API call. This
// will create a new "TXT" resource using the specified parameters.
func (d *DNS) CreateDomainResourceTXT(domainID int, name, target string, ttlSeconds int) (*ResourceResponse, error) {
return d.createDomainResource(linode.Parameters{
"Type": "TXT",
"DomainID": strconv.Itoa(domainID),
"Name": name,
"Target": target,
"TTL_Sec": strconv.Itoa(ttlSeconds),
})
}
// CreateDomainResource executes the "domain.resource.create" API call. This
// will create a new resource using the values specified in the resource.
func (d *DNS) CreateDomainResource(r *Resource) (*ResourceResponse, error) {
// Ensure that the resource has a name.
if len(r.Name) == 0 {
return nil, linode.NewError(errors.New("dns: creating a resource requires Name be specified"))
}
// Initialize parameters that are shared across resource types.
params := linode.Parameters{
"DomainID": strconv.Itoa(r.DomainID),
"Name": r.Name,
"TTL_Sec": strconv.Itoa(r.TTL_Sec),
}
// Ensure that the resource has a valid, supported type.
r.Type = strings.ToUpper(r.Type)
switch r.Type {
case "A":
case "AAAA":
case "CNAME":
case "MX":
case "NS":
case "TXT":
// No further processing required for these types.
break
case "SRV":
// Ensure that SRV has a protocol.
if len(r.Protocol) == 0 {
return nil, linode.NewError(errors.New("dns: creating a SRV resource requires Priority be specified"))
}
params.Set("Protocol", r.Protocol)
break
default:
// Unsupported type.
return nil, linode.NewError(errors.New("dns: can not create resource of unsupported type: " + r.Type))
}
params.Set("Type", r.Type)
// Ensure that the resource has a valid target.
if len(r.Target) == 0 {
return nil, linode.NewError(errors.New("dns: creating a resource requires Target to be specified"))
}
params.Set("Target", r.Target)
if r.Name == "MX" || r.Name == "SRV" {
// If priority is defined, ensure that it's valid.
if r.Priority != nil {
priority, ok := r.Priority.(int)
if !ok {
return nil, linode.NewError(errors.New("dns: priority must be specified as an int"))
}
if priority < 0 || priority > 255 {
return nil, linode.NewError(errors.New("dns: priority must be within the range of 0-255"))
}
r.Priority = priority
params.Set("Priority", strconv.Itoa(priority))
}
}
// Create the resource.
return d.createDomainResource(params)
}
// createDomainResource executes the "domain.resource.create" API call. This
// will create a resource using the specified parameters.
func (d *DNS) createDomainResource(params linode.Parameters) (*ResourceResponse, error) {
var response *ResourceResponse
_, err := d.linode.Request("domain.resource.create", params, &response)
if err != nil {
return nil, err
}
return response, nil
}
// DeleteDomainResource executes the "domain.resource.delete" API call. This
// will delete the resource specified by resourceID under the domain specified
// by domainID.
func (d *DNS) DeleteDomainResource(domainID, resourceID int) (*ResourceResponse, error) {
params := linode.Parameters{
"DomainID": strconv.Itoa(domainID),
"ResourceID": strconv.Itoa(resourceID),
}
var response *ResourceResponse
_, err := d.linode.Request("domain.resource.delete", params, &response)
if err != nil {
return nil, err
}
return response, nil
}
// GetResourceByType returns a list of domain resources that match the specified
// type. This search is not case-sensitive.
func (d *DNS) GetResourcesByType(domainID int, res_type string) ([]*Resource, error) {
resources, err := d.GetDomainResources(domainID)
if err != nil {
return nil, err
}
list := []*Resource{}
for _, r := range resources {
if strings.EqualFold(r.Type, res_type) {
list = append(list, r)
}
}
return list, nil
}