From 2e8df65ff3d0f06b2f6a21d7da88a494be76af5b Mon Sep 17 00:00:00 2001 From: Buddy Sandidge Date: Tue, 22 Nov 2016 21:10:36 -0800 Subject: [PATCH] Add dnsimple to vendor --- .../dnsimple/dnsimple-go/LICENSE.txt | 21 ++ .../dnsimple/dnsimple-go/dnsimple/accounts.go | 49 +++ .../dnsimple-go/dnsimple/authentication.go | 69 ++++ .../dnsimple-go/dnsimple/certificates.go | 135 +++++++ .../dnsimple-go/dnsimple/collaborators.go | 97 +++++ .../dnsimple/dnsimple-go/dnsimple/contacts.go | 139 +++++++ .../dnsimple/dnsimple-go/dnsimple/dnsimple.go | 341 ++++++++++++++++++ .../dnsimple/dnsimple-go/dnsimple/domains.go | 161 +++++++++ .../dnsimple/domains_email_forwards.go | 106 ++++++ .../dnsimple-go/dnsimple/domains_pushes.go | 117 ++++++ .../dnsimple/dnsimple-go/dnsimple/identity.go | 48 +++ .../dnsimple/dnsimple-go/dnsimple/oauth.go | 113 ++++++ .../dnsimple-go/dnsimple/registrar.go | 170 +++++++++ .../dnsimple/registrar_auto_renewal.go | 37 ++ .../dnsimple/registrar_delegation.go | 84 +++++ .../dnsimple/registrar_whois_privacy.go | 69 ++++ .../dnsimple/dnsimple-go/dnsimple/services.go | 93 +++++ .../dnsimple-go/dnsimple/services_domains.go | 70 ++++ .../dnsimple-go/dnsimple/templates.go | 129 +++++++ .../dnsimple-go/dnsimple/templates_domains.go | 21 ++ .../dnsimple-go/dnsimple/templates_records.go | 107 ++++++ .../dnsimple/dnsimple-go/dnsimple/tlds.go | 117 ++++++ .../dnsimple/dnsimple-go/dnsimple/users.go | 7 + .../dnsimple/vanity_name_server.go | 65 ++++ .../dnsimple/dnsimple-go/dnsimple/webhooks.go | 104 ++++++ .../dnsimple/dnsimple-go/dnsimple/zones.go | 108 ++++++ .../dnsimple-go/dnsimple/zones_records.go | 144 ++++++++ vendor/vendor.json | 6 + 28 files changed, 2727 insertions(+) create mode 100644 vendor/github.com/dnsimple/dnsimple-go/LICENSE.txt create mode 100644 vendor/github.com/dnsimple/dnsimple-go/dnsimple/accounts.go create mode 100644 vendor/github.com/dnsimple/dnsimple-go/dnsimple/authentication.go create mode 100644 vendor/github.com/dnsimple/dnsimple-go/dnsimple/certificates.go create mode 100644 vendor/github.com/dnsimple/dnsimple-go/dnsimple/collaborators.go create mode 100644 vendor/github.com/dnsimple/dnsimple-go/dnsimple/contacts.go create mode 100644 vendor/github.com/dnsimple/dnsimple-go/dnsimple/dnsimple.go create mode 100644 vendor/github.com/dnsimple/dnsimple-go/dnsimple/domains.go create mode 100644 vendor/github.com/dnsimple/dnsimple-go/dnsimple/domains_email_forwards.go create mode 100644 vendor/github.com/dnsimple/dnsimple-go/dnsimple/domains_pushes.go create mode 100644 vendor/github.com/dnsimple/dnsimple-go/dnsimple/identity.go create mode 100644 vendor/github.com/dnsimple/dnsimple-go/dnsimple/oauth.go create mode 100644 vendor/github.com/dnsimple/dnsimple-go/dnsimple/registrar.go create mode 100644 vendor/github.com/dnsimple/dnsimple-go/dnsimple/registrar_auto_renewal.go create mode 100644 vendor/github.com/dnsimple/dnsimple-go/dnsimple/registrar_delegation.go create mode 100644 vendor/github.com/dnsimple/dnsimple-go/dnsimple/registrar_whois_privacy.go create mode 100644 vendor/github.com/dnsimple/dnsimple-go/dnsimple/services.go create mode 100644 vendor/github.com/dnsimple/dnsimple-go/dnsimple/services_domains.go create mode 100644 vendor/github.com/dnsimple/dnsimple-go/dnsimple/templates.go create mode 100644 vendor/github.com/dnsimple/dnsimple-go/dnsimple/templates_domains.go create mode 100644 vendor/github.com/dnsimple/dnsimple-go/dnsimple/templates_records.go create mode 100644 vendor/github.com/dnsimple/dnsimple-go/dnsimple/tlds.go create mode 100644 vendor/github.com/dnsimple/dnsimple-go/dnsimple/users.go create mode 100644 vendor/github.com/dnsimple/dnsimple-go/dnsimple/vanity_name_server.go create mode 100644 vendor/github.com/dnsimple/dnsimple-go/dnsimple/webhooks.go create mode 100644 vendor/github.com/dnsimple/dnsimple-go/dnsimple/zones.go create mode 100644 vendor/github.com/dnsimple/dnsimple-go/dnsimple/zones_records.go diff --git a/vendor/github.com/dnsimple/dnsimple-go/LICENSE.txt b/vendor/github.com/dnsimple/dnsimple-go/LICENSE.txt new file mode 100644 index 0000000..0bf65d5 --- /dev/null +++ b/vendor/github.com/dnsimple/dnsimple-go/LICENSE.txt @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014-2016 Aetrion LLC + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/vendor/github.com/dnsimple/dnsimple-go/dnsimple/accounts.go b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/accounts.go new file mode 100644 index 0000000..8efa8a3 --- /dev/null +++ b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/accounts.go @@ -0,0 +1,49 @@ +package dnsimple + +import ( + "fmt" +) + +type AccountsService struct { + client *Client +} + +// Account represents a DNSimple account. +type Account struct { + ID int `json:"id,omitempty"` + Email string `json:"email,omitempty"` + PlanIdentifier string `json:"plan_identifier,omitempty"` + CreatedAt string `json:"created_at,omitempty"` + UpdatedAt string `json:"updated_at,omitempty"` +} + +func accountsPath() string { + return fmt.Sprintf("/accounts") +} + +// AccountsResponse represents a response from an API method that returns a collection of Account struct. +type AccountsResponse struct { + Response + Data []Account `json:"data"` +} + +// ListAccounts list the accounts for an user. +// +// See https://developer.dnsimple.com/v2/accounts/#list +func (s *AccountsService) ListAccounts(options *ListOptions) (*AccountsResponse, error) { + path := versioned(accountsPath()) + accountsResponse := &AccountsResponse{} + + path, err := addURLQueryOptions(path, options) + if err != nil { + return nil, err + } + + resp, err := s.client.get(path, accountsResponse) + if err != nil { + return accountsResponse, err + } + + accountsResponse.HttpResponse = resp + return accountsResponse, nil +} diff --git a/vendor/github.com/dnsimple/dnsimple-go/dnsimple/authentication.go b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/authentication.go new file mode 100644 index 0000000..b904c2d --- /dev/null +++ b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/authentication.go @@ -0,0 +1,69 @@ +package dnsimple + +import ( + "encoding/base64" +) + +const ( + httpHeaderDomainToken = "X-DNSimple-Domain-Token" + httpHeaderApiToken = "X-DNSimple-Token" + httpHeaderAuthorization = "Authorization" +) + +// Provides credentials that can be used for authenticating with DNSimple. +// +// See https://developer.dnsimple.com/v2/#authentication +type Credentials interface { + // Returns the HTTP headers that should be set + // to authenticate the HTTP Request. + Headers() map[string]string +} + +// Domain token authentication +type domainTokenCredentials struct { + domainToken string +} + +// NewDomainTokenCredentials construct Credentials using the DNSimple Domain Token method. +func NewDomainTokenCredentials(domainToken string) Credentials { + return &domainTokenCredentials{domainToken: domainToken} +} + +func (c *domainTokenCredentials) Headers() map[string]string { + return map[string]string{httpHeaderDomainToken: c.domainToken} +} + +// HTTP basic authentication +type httpBasicCredentials struct { + email string + password string +} + +// NewHTTPBasicCredentials construct Credentials using HTTP Basic Auth. +func NewHTTPBasicCredentials(email, password string) Credentials { + return &httpBasicCredentials{email, password} +} + +func (c *httpBasicCredentials) Headers() map[string]string { + return map[string]string{httpHeaderAuthorization: "Basic " + c.basicAuth(c.email, c.password)} +} + +func (c *httpBasicCredentials) basicAuth(username, password string) string { + auth := username + ":" + password + return base64.StdEncoding.EncodeToString([]byte(auth)) +} + +// OAuth token authentication + +type oauthTokenCredentials struct { + oauthToken string +} + +// NewOauthTokenCredentials construct Credentials using the OAuth access token. +func NewOauthTokenCredentials(oauthToken string) Credentials { + return &oauthTokenCredentials{oauthToken: oauthToken} +} + +func (c *oauthTokenCredentials) Headers() map[string]string { + return map[string]string{httpHeaderAuthorization: "Bearer " + c.oauthToken} +} diff --git a/vendor/github.com/dnsimple/dnsimple-go/dnsimple/certificates.go b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/certificates.go new file mode 100644 index 0000000..1a31679 --- /dev/null +++ b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/certificates.go @@ -0,0 +1,135 @@ +package dnsimple + +import ( + "fmt" + "strconv" +) + +// CertificatesService handles communication with the certificate related +// methods of the DNSimple API. +// +// See https://developer.dnsimple.com/v2/domains/certificates +type CertificatesService struct { + client *Client +} + +// Certificate represents a Certificate in DNSimple. +type Certificate struct { + ID int `json:"id,omitempty"` + DomainID int `json:"domain_id,omitempty"` + CommonName string `json:"common_name,omitempty"` + Years int `json:"years,omitempty"` + State string `json:"state,omitempty"` + AuthorityIdentifier string `json:"authority_identifier,omitempty"` + CreatedAt string `json:"created_at,omitempty"` + UpdatedAt string `json:"updated_at,omitempty"` + ExpiresOn string `json:"expires_on,omitempty"` + CertificateRequest string `json:"csr,omitempty"` +} + +// CertificateBundle represents a container for all the PEM-encoded X509 certificate entities, +// such as the private key, the server certificate and the intermediate chain. +type CertificateBundle struct { + // CertificateRequest string `json:"csr,omitempty"` + PrivateKey string `json:"private_key,omitempty"` + ServerCertificate string `json:"server,omitempty"` + RootCertificate string `json:"root,omitempty"` + IntermediateCertificates []string `json:"chain,omitempty"` +} + +func certificatePath(accountID, domainIdentifier, certificateID string) string { + path := fmt.Sprintf("%v/certificates", domainPath(accountID, domainIdentifier)) + + if certificateID != "" { + path += fmt.Sprintf("/%v", certificateID) + } + return path +} + +// CertificateResponse represents a response from an API method that returns a Certificate struct. +type CertificateResponse struct { + Response + Data *Certificate `json:"data"` +} + +// CertificateBundleResponse represents a response from an API method that returns a CertificatBundle struct. +type CertificateBundleResponse struct { + Response + Data *CertificateBundle `json:"data"` +} + +// CertificatesResponse represents a response from an API method that returns a collection of Certificate struct. +type CertificatesResponse struct { + Response + Data []Certificate `json:"data"` +} + +// ListCertificates list the certificates for a domain. +// +// See https://developer.dnsimple.com/v2/domains/certificates#list +func (s *CertificatesService) ListCertificates(accountID, domainIdentifier string, options *ListOptions) (*CertificatesResponse, error) { + path := versioned(certificatePath(accountID, domainIdentifier, "")) + certificatesResponse := &CertificatesResponse{} + + path, err := addURLQueryOptions(path, options) + if err != nil { + return nil, err + } + + resp, err := s.client.get(path, certificatesResponse) + if err != nil { + return certificatesResponse, err + } + + certificatesResponse.HttpResponse = resp + return certificatesResponse, nil +} + +// GetCertificate fetches the certificate. +// +// See https://developer.dnsimple.com/v2/domains/certificates#get +func (s *CertificatesService) GetCertificate(accountID, domainIdentifier string, certificateID int) (*CertificateResponse, error) { + path := versioned(certificatePath(accountID, domainIdentifier, strconv.Itoa(certificateID))) + certificateResponse := &CertificateResponse{} + + resp, err := s.client.get(path, certificateResponse) + if err != nil { + return nil, err + } + + certificateResponse.HttpResponse = resp + return certificateResponse, nil +} + +// DownloadCertificate download the issued server certificate, +// as well the root certificate and the intermediate chain. +// +// See https://developer.dnsimple.com/v2/domains/certificates#download +func (s *CertificatesService) DownloadCertificate(accountID, domainIdentifier string, certificateID int) (*CertificateBundleResponse, error) { + path := versioned(certificatePath(accountID, domainIdentifier, strconv.Itoa(certificateID)) + "/download") + certificateBundleResponse := &CertificateBundleResponse{} + + resp, err := s.client.get(path, certificateBundleResponse) + if err != nil { + return nil, err + } + + certificateBundleResponse.HttpResponse = resp + return certificateBundleResponse, nil +} + +// GetCertificatePrivateKey fetches the certificate private key. +// +// See https://developer.dnsimple.com/v2/domains/certificates#get-private-key +func (s *CertificatesService) GetCertificatePrivateKey(accountID, domainIdentifier string, certificateID int) (*CertificateBundleResponse, error) { + path := versioned(certificatePath(accountID, domainIdentifier, strconv.Itoa(certificateID)) + "/private_key") + certificateBundleResponse := &CertificateBundleResponse{} + + resp, err := s.client.get(path, certificateBundleResponse) + if err != nil { + return nil, err + } + + certificateBundleResponse.HttpResponse = resp + return certificateBundleResponse, nil +} diff --git a/vendor/github.com/dnsimple/dnsimple-go/dnsimple/collaborators.go b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/collaborators.go new file mode 100644 index 0000000..a4387af --- /dev/null +++ b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/collaborators.go @@ -0,0 +1,97 @@ +package dnsimple + +import ( + "fmt" +) + +// Collaborator represents a Collaborator in DNSimple. +type Collaborator struct { + ID int `json:"id,omitempty"` + DomainID int `json:"domain_id,omitempty"` + DomainName string `json:"domain_name,omitempty"` + UserID int `json:"user_id,omitempty"` + UserEmail string `json:"user_email,omitempty"` + Invitation bool `json:"invitation,omitempty"` + CreatedAt string `json:"created_at,omitempty"` + UpdatedAt string `json:"updated_at,omitempty"` + AcceptedAt string `json:"accepted_at,omitempty"` +} + +// CollaboratorAttributes represents Collaborator attributes for AddCollaborator operation. +type CollaboratorAttributes struct { + Email string `json:"email,omitempty"` +} + +func collaboratorPath(accountID, domainIdentifier, collaboratorID string) string { + path := fmt.Sprintf("%v/collaborators", domainPath(accountID, domainIdentifier)) + + if collaboratorID != "" { + path += fmt.Sprintf("/%v", collaboratorID) + } + return path +} + +// CollaboratorResponse represents a response from an API method that returns a Collaborator struct. +type CollaboratorResponse struct { + Response + Data *Collaborator `json:"data"` +} + +// CollaboratorsResponse represents a response from an API method that returns a collection of Collaborator struct. +type CollaboratorsResponse struct { + Response + Data []Collaborator `json:"data"` +} + +// ListCollaborators list the collaborators for a domain. +// +// See https://developer.dnsimple.com/v2/domains/collaborators#list +func (s *DomainsService) ListCollaborators(accountID, domainIdentifier string, options *ListOptions) (*CollaboratorsResponse, error) { + path := versioned(collaboratorPath(accountID, domainIdentifier, "")) + collaboratorsResponse := &CollaboratorsResponse{} + + path, err := addURLQueryOptions(path, options) + if err != nil { + return nil, err + } + + resp, err := s.client.get(path, collaboratorsResponse) + if err != nil { + return collaboratorsResponse, err + } + + collaboratorsResponse.HttpResponse = resp + return collaboratorsResponse, nil +} + +// AddCollaborator adds a new collaborator to the domain in the account. +// +// See https://developer.dnsimple.com/v2/domains/collaborators#add +func (s *DomainsService) AddCollaborator(accountID string, domainIdentifier string, attributes CollaboratorAttributes) (*CollaboratorResponse, error) { + path := versioned(collaboratorPath(accountID, domainIdentifier, "")) + collaboratorResponse := &CollaboratorResponse{} + + resp, err := s.client.post(path, attributes, collaboratorResponse) + if err != nil { + return nil, err + } + + collaboratorResponse.HttpResponse = resp + return collaboratorResponse, nil +} + +// RemoveCollaborator PERMANENTLY deletes a domain from the account. +// +// See https://developer.dnsimple.com/v2/domains/collaborators#add +func (s *DomainsService) RemoveCollaborator(accountID string, domainIdentifier string, collaboratorID string) (*CollaboratorResponse, error) { + path := versioned(collaboratorPath(accountID, domainIdentifier, collaboratorID)) + collaboratorResponse := &CollaboratorResponse{} + + resp, err := s.client.delete(path, nil, nil) + if err != nil { + return nil, err + } + + collaboratorResponse.HttpResponse = resp + return collaboratorResponse, nil +} diff --git a/vendor/github.com/dnsimple/dnsimple-go/dnsimple/contacts.go b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/contacts.go new file mode 100644 index 0000000..c902882 --- /dev/null +++ b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/contacts.go @@ -0,0 +1,139 @@ +package dnsimple + +import ( + "fmt" +) + +// ContactsService handles communication with the contact related +// methods of the DNSimple API. +// +// See https://developer.dnsimple.com/v2/contacts/ +type ContactsService struct { + client *Client +} + +// Contact represents a Contact in DNSimple. +type Contact struct { + ID int `json:"id,omitempty"` + AccountID int `json:"account_id,omitempty"` + Label string `json:"label,omitempty"` + FirstName string `json:"first_name,omitempty"` + LastName string `json:"last_name,omitempty"` + JobTitle string `json:"job_title,omitempty"` + Organization string `json:"organization_name,omitempty"` + Address1 string `json:"address1,omitempty"` + Address2 string `json:"address2,omitempty"` + City string `json:"city,omitempty"` + StateProvince string `json:"state_province,omitempty"` + PostalCode string `json:"postal_code,omitempty"` + Country string `json:"country,omitempty"` + Phone string `json:"phone,omitempty"` + Fax string `json:"fax,omitempty"` + Email string `json:"email,omitempty"` + CreatedAt string `json:"created_at,omitempty"` + UpdatedAt string `json:"updated_at,omitempty"` +} + +func contactPath(accountID string, contact interface{}) string { + if contact != nil { + return fmt.Sprintf("/%v/contacts/%v", accountID, contact) + } + return fmt.Sprintf("/%v/contacts", accountID) +} + +// ContactResponse represents a response from an API method that returns a Contact struct. +type ContactResponse struct { + Response + Data *Contact `json:"data"` +} + +// ContactsResponse represents a response from an API method that returns a collection of Contact struct. +type ContactsResponse struct { + Response + Data []Contact `json:"data"` +} + +// ListContacts list the contacts for an account. +// +// See https://developer.dnsimple.com/v2/contacts/#list +func (s *ContactsService) ListContacts(accountID string, options *ListOptions) (*ContactsResponse, error) { + path := versioned(contactPath(accountID, nil)) + contactsResponse := &ContactsResponse{} + + path, err := addURLQueryOptions(path, options) + if err != nil { + return nil, err + } + + resp, err := s.client.get(path, contactsResponse) + if err != nil { + return contactsResponse, err + } + + contactsResponse.HttpResponse = resp + return contactsResponse, nil +} + +// CreateContact creates a new contact. +// +// See https://developer.dnsimple.com/v2/contacts/#create +func (s *ContactsService) CreateContact(accountID string, contactAttributes Contact) (*ContactResponse, error) { + path := versioned(contactPath(accountID, nil)) + contactResponse := &ContactResponse{} + + resp, err := s.client.post(path, contactAttributes, contactResponse) + if err != nil { + return nil, err + } + + contactResponse.HttpResponse = resp + return contactResponse, nil +} + +// GetContact fetches a contact. +// +// See https://developer.dnsimple.com/v2/contacts/#get +func (s *ContactsService) GetContact(accountID string, contactID int) (*ContactResponse, error) { + path := versioned(contactPath(accountID, contactID)) + contactResponse := &ContactResponse{} + + resp, err := s.client.get(path, contactResponse) + if err != nil { + return nil, err + } + + contactResponse.HttpResponse = resp + return contactResponse, nil +} + +// UpdateContact updates a contact. +// +// See https://developer.dnsimple.com/v2/contacts/#update +func (s *ContactsService) UpdateContact(accountID string, contactID int, contactAttributes Contact) (*ContactResponse, error) { + path := versioned(contactPath(accountID, contactID)) + contactResponse := &ContactResponse{} + + resp, err := s.client.patch(path, contactAttributes, contactResponse) + if err != nil { + return nil, err + } + + contactResponse.HttpResponse = resp + return contactResponse, nil +} + +// DeleteContact PERMANENTLY deletes a contact from the account. +// +// See https://developer.dnsimple.com/v2/contacts/#delete +func (s *ContactsService) DeleteContact(accountID string, contactID int) (*ContactResponse, error) { + path := versioned(contactPath(accountID, contactID)) + contactResponse := &ContactResponse{} + + resp, err := s.client.delete(path, nil, nil) + if err != nil { + return nil, err + } + + contactResponse.HttpResponse = resp + return contactResponse, nil +} diff --git a/vendor/github.com/dnsimple/dnsimple-go/dnsimple/dnsimple.go b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/dnsimple.go new file mode 100644 index 0000000..1b1bcee --- /dev/null +++ b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/dnsimple.go @@ -0,0 +1,341 @@ +// Package dnsimple provides a client for the DNSimple API. +// In order to use this package you will need a DNSimple account. +package dnsimple + +import ( + "bytes" + "encoding/json" + "fmt" + "io" + "log" + "net/http" + "net/url" + "reflect" + "strconv" + "strings" + "time" + + "github.com/google/go-querystring/query" +) + +const ( + // libraryVersion identifies the current library version. + // This is a pro-forma convention given that Go dependencies + // tends to be fetched directly from the repo. + // It is also used in the user-agent identify the client. + libraryVersion = "0.13.0" + + // defaultBaseURL to the DNSimple production API. + defaultBaseURL = "https://api.dnsimple.com" + + // userAgent represents the default user agent used + // when no other user agent is set. + defaultUserAgent = "dnsimple-go/" + libraryVersion + + apiVersion = "v2" +) + +// Client represents a client to the DNSimple API. +type Client struct { + // HttpClient is the underlying HTTP client + // used to communicate with the API. + HttpClient *http.Client + + // Credentials used for accessing the DNSimple API + Credentials Credentials + + // BaseURL for API requests. + // Defaults to the public DNSimple API, but can be set to a different endpoint (e.g. the sandbox). + BaseURL string + + // UserAgent used when communicating with the DNSimple API. + UserAgent string + + // Services used for talking to different parts of the DNSimple API. + Identity *IdentityService + Accounts *AccountsService + Certificates *CertificatesService + Contacts *ContactsService + Domains *DomainsService + Oauth *OauthService + Registrar *RegistrarService + Services *ServicesService + Templates *TemplatesService + Tlds *TldsService + VanityNameServers *VanityNameServersService + Webhooks *WebhooksService + Zones *ZonesService + + // Set to true to output debugging logs during API calls + Debug bool +} + +// ListOptions contains the common options you can pass to a List method +// in order to control parameters such as paginations and page number. +type ListOptions struct { + // The page to return + Page int `url:"page,omitempty"` + + // The number of entries to return per page + PerPage int `url:"per_page,omitempty"` + + // The order criteria to sort the results. + // The value is a comma-separated list of field[:direction], + // eg. name | name:desc | name:desc,expiration:desc + Sort string `url:"sort,omitempty"` +} + +// NewClient returns a new DNSimple API client using the given credentials. +func NewClient(credentials Credentials) *Client { + c := &Client{Credentials: credentials, HttpClient: &http.Client{}, BaseURL: defaultBaseURL} + c.Identity = &IdentityService{client: c} + c.Accounts = &AccountsService{client: c} + c.Certificates = &CertificatesService{client: c} + c.Contacts = &ContactsService{client: c} + c.Domains = &DomainsService{client: c} + c.Oauth = &OauthService{client: c} + c.Registrar = &RegistrarService{client: c} + c.Services = &ServicesService{client: c} + c.Templates = &TemplatesService{client: c} + c.Tlds = &TldsService{client: c} + c.VanityNameServers = &VanityNameServersService{client: c} + c.Webhooks = &WebhooksService{client: c} + c.Zones = &ZonesService{client: c} + return c +} + +// NewRequest creates an API request. +// The path is expected to be a relative path and will be resolved +// according to the BaseURL of the Client. Paths should always be specified without a preceding slash. +func (c *Client) NewRequest(method, path string, payload interface{}) (*http.Request, error) { + url := c.BaseURL + path + + body := new(bytes.Buffer) + if payload != nil { + err := json.NewEncoder(body).Encode(payload) + if err != nil { + return nil, err + } + } + + req, err := http.NewRequest(method, url, body) + if err != nil { + return nil, err + } + + req.Header.Set("Content-Type", "application/json") + req.Header.Add("Accept", "application/json") + req.Header.Add("User-Agent", formatUserAgent(c.UserAgent)) + for key, value := range c.Credentials.Headers() { + req.Header.Add(key, value) + } + + return req, nil +} + +// formatUserAgent builds the final user agent to use for HTTP requests. +// +// If no custom user agent is provided, the default user agent is used. +// +// dnsimple-go/1.0 +// +// If a custom user agent is provided, the final user agent is the combination of the custom user agent +// prepended by the default user agent. +// +// dnsimple-go/1.0 customAgentFlag +// +func formatUserAgent(customUserAgent string) string { + if customUserAgent == "" { + return defaultUserAgent + } + + return fmt.Sprintf("%s %s", defaultUserAgent, customUserAgent) +} + +func versioned(path string) string { + return fmt.Sprintf("/%s/%s", apiVersion, strings.Trim(path, "/")) +} + +func (c *Client) get(path string, obj interface{}) (*http.Response, error) { + req, err := c.NewRequest("GET", path, nil) + if err != nil { + return nil, err + } + + return c.Do(req, obj) +} + +func (c *Client) post(path string, payload, obj interface{}) (*http.Response, error) { + req, err := c.NewRequest("POST", path, payload) + if err != nil { + return nil, err + } + + return c.Do(req, obj) +} + +func (c *Client) put(path string, payload, obj interface{}) (*http.Response, error) { + req, err := c.NewRequest("PUT", path, payload) + if err != nil { + return nil, err + } + + return c.Do(req, obj) +} + +func (c *Client) patch(path string, payload, obj interface{}) (*http.Response, error) { + req, err := c.NewRequest("PATCH", path, payload) + if err != nil { + return nil, err + } + + return c.Do(req, obj) +} + +func (c *Client) delete(path string, payload interface{}, obj interface{}) (*http.Response, error) { + req, err := c.NewRequest("DELETE", path, payload) + if err != nil { + return nil, err + } + + return c.Do(req, obj) +} + +// Do sends an API request and returns the API response. +// +// The API response is JSON decoded and stored in the value pointed by obj, +// or returned as an error if an API error has occurred. +// If obj implements the io.Writer interface, the raw response body will be written to obj, +// without attempting to decode it. +func (c *Client) Do(req *http.Request, obj interface{}) (*http.Response, error) { + if c.Debug { + log.Printf("Executing request (%v): %#v", req.URL, req) + } + + resp, err := c.HttpClient.Do(req) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + if c.Debug { + log.Printf("Response received: %#v", resp) + } + + err = CheckResponse(resp) + if err != nil { + return resp, err + } + + // If obj implements the io.Writer, + // the response body is decoded into v. + if obj != nil { + if w, ok := obj.(io.Writer); ok { + io.Copy(w, resp.Body) + } else { + err = json.NewDecoder(resp.Body).Decode(obj) + } + } + + return resp, err +} + +// A Response represents an API response. +type Response struct { + // HTTP response + HttpResponse *http.Response + + // If the response is paginated, the Pagination will store them. + Pagination *Pagination `json:"pagination"` +} + +// RateLimit returns the maximum amount of requests this account can send in an hour. +func (r *Response) RateLimit() int { + value, _ := strconv.Atoi(r.HttpResponse.Header.Get("X-RateLimit-Limit")) + return value +} + +// RateLimitRemaining returns the remaining amount of requests this account can send within this hour window. +func (r *Response) RateLimitRemaining() int { + value, _ := strconv.Atoi(r.HttpResponse.Header.Get("X-RateLimit-Remaining")) + return value +} + +// RateLimitReset returns when the throttling window will be reset for this account. +func (r *Response) RateLimitReset() time.Time { + value, _ := strconv.ParseInt(r.HttpResponse.Header.Get("X-RateLimit-Reset"), 10, 64) + return time.Unix(value, 0) +} + +// If the response is paginated, Pagination represents the pagination information. +type Pagination struct { + CurrentPage int `json:"current_page"` + PerPage int `json:"per_page"` + TotalPages int `json:"total_pages"` + TotalEntries int `json:"total_entries"` +} + +// An ErrorResponse represents an API response that generated an error. +type ErrorResponse struct { + Response + + // human-readable message + Message string `json:"message"` +} + +// Error implements the error interface. +func (r *ErrorResponse) Error() string { + return fmt.Sprintf("%v %v: %v %v", + r.HttpResponse.Request.Method, r.HttpResponse.Request.URL, + r.HttpResponse.StatusCode, r.Message) +} + +// CheckResponse checks the API response for errors, and returns them if present. +// A response is considered an error if the status code is different than 2xx. Specific requests +// may have additional requirements, but this is sufficient in most of the cases. +func CheckResponse(resp *http.Response) error { + if code := resp.StatusCode; 200 <= code && code <= 299 { + return nil + } + + errorResponse := &ErrorResponse{} + errorResponse.HttpResponse = resp + + err := json.NewDecoder(resp.Body).Decode(errorResponse) + if err != nil { + return err + } + + return errorResponse +} + +// addOptions adds the parameters in opt as URL query parameters to s. opt +// must be a struct whose fields may contain "url" tags. +func addURLQueryOptions(path string, options interface{}) (string, error) { + opt := reflect.ValueOf(options) + + // options is a pointer + // return if the value of the pointer is nil, + if opt.Kind() == reflect.Ptr && opt.IsNil() { + return path, nil + } + + // append the options to the URL + u, err := url.Parse(path) + if err != nil { + return path, err + } + + qs, err := query.Values(options) + if err != nil { + return path, err + } + + uqs := u.Query() + for k, _ := range qs { + uqs.Set(k, qs.Get(k)) + } + u.RawQuery = uqs.Encode() + + return u.String(), nil +} diff --git a/vendor/github.com/dnsimple/dnsimple-go/dnsimple/domains.go b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/domains.go new file mode 100644 index 0000000..66a27c8 --- /dev/null +++ b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/domains.go @@ -0,0 +1,161 @@ +package dnsimple + +import ( + "fmt" +) + +// DomainsService handles communication with the domain related +// methods of the DNSimple API. +// +// See https://developer.dnsimple.com/v2/domains/ +type DomainsService struct { + client *Client +} + +// Domain represents a domain in DNSimple. +type Domain struct { + ID int `json:"id,omitempty"` + AccountID int `json:"account_id,omitempty"` + RegistrantID int `json:"registrant_id,omitempty"` + Name string `json:"name,omitempty"` + UnicodeName string `json:"unicode_name,omitempty"` + Token string `json:"token,omitempty"` + State string `json:"state,omitempty"` + AutoRenew bool `json:"auto_renew,omitempty"` + PrivateWhois bool `json:"private_whois,omitempty"` + ExpiresOn string `json:"expires_on,omitempty"` + CreatedAt string `json:"created_at,omitempty"` + UpdatedAt string `json:"updated_at,omitempty"` +} + +// DomainListOptions specifies the optional parameters you can provide +// to customize the DomainsService.ListDomains method. +type DomainListOptions struct { + // Select domains where the name contains given string. + NameLike string `url:"name_like,omitempty"` + + // Select domains where the registrant matches given ID. + RegistrantID int `url:"registrant_id,omitempty"` + + ListOptions +} + +// DomainResponse represents a response from an API method that returns a Domain struct. +type DomainResponse struct { + Response + Data *Domain `json:"data"` +} + +// DomainsResponse represents a response from an API method that returns a collection of Domain struct. +type DomainsResponse struct { + Response + Data []Domain `json:"data"` +} + +// domainRequest represents a generic wrapper for a domain request, +// when domainWrapper cannot be used because of type constraint on Domain. +type domainRequest struct { + Domain interface{} `json:"domain"` +} + +func domainIdentifier(value interface{}) string { + switch value := value.(type) { + case string: + return value + case int: + return fmt.Sprintf("%d", value) + } + return "" +} + +func domainPath(accountID string, domain interface{}) string { + if domain != nil { + return fmt.Sprintf("/%v/domains/%v", accountID, domainIdentifier(domain)) + } + return fmt.Sprintf("/%v/domains", accountID) +} + +// ListDomains lists the domains for an account. +// +// See https://developer.dnsimple.com/v2/domains/#list +func (s *DomainsService) ListDomains(accountID string, options *DomainListOptions) (*DomainsResponse, error) { + path := versioned(domainPath(accountID, nil)) + domainsResponse := &DomainsResponse{} + + path, err := addURLQueryOptions(path, options) + if err != nil { + return nil, err + } + + resp, err := s.client.get(path, domainsResponse) + if err != nil { + return nil, err + } + + domainsResponse.HttpResponse = resp + return domainsResponse, nil +} + +// CreateDomain creates a new domain in the account. +// +// See https://developer.dnsimple.com/v2/domains/#create +func (s *DomainsService) CreateDomain(accountID string, domainAttributes Domain) (*DomainResponse, error) { + path := versioned(domainPath(accountID, nil)) + domainResponse := &DomainResponse{} + + resp, err := s.client.post(path, domainAttributes, domainResponse) + if err != nil { + return nil, err + } + + domainResponse.HttpResponse = resp + return domainResponse, nil +} + +// GetDomain fetches a domain. +// +// See https://developer.dnsimple.com/v2/domains/#get +func (s *DomainsService) GetDomain(accountID string, domain interface{}) (*DomainResponse, error) { + path := versioned(domainPath(accountID, domain)) + domainResponse := &DomainResponse{} + + resp, err := s.client.get(path, domainResponse) + if err != nil { + return nil, err + } + + domainResponse.HttpResponse = resp + return domainResponse, nil +} + +// DeleteDomain PERMANENTLY deletes a domain from the account. +// +// See https://developer.dnsimple.com/v2/domains/#delete +func (s *DomainsService) DeleteDomain(accountID string, domain interface{}) (*DomainResponse, error) { + path := versioned(domainPath(accountID, domain)) + domainResponse := &DomainResponse{} + + resp, err := s.client.delete(path, nil, nil) + if err != nil { + return nil, err + } + + domainResponse.HttpResponse = resp + return domainResponse, nil +} + +// ResetDomainToken resets the domain token. +// +// See https://developer.dnsimple.com/v2/domains/#reset-token +func (s *DomainsService) ResetDomainToken(accountID string, domain interface{}) (*DomainResponse, error) { + path := versioned(domainPath(accountID, domain) + "/token") + domainResponse := &DomainResponse{} + + resp, err := s.client.post(path, nil, domainResponse) + if err != nil { + return nil, err + } + + domainResponse.HttpResponse = resp + return domainResponse, nil +} diff --git a/vendor/github.com/dnsimple/dnsimple-go/dnsimple/domains_email_forwards.go b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/domains_email_forwards.go new file mode 100644 index 0000000..7235cad --- /dev/null +++ b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/domains_email_forwards.go @@ -0,0 +1,106 @@ +package dnsimple + +import ( + "fmt" +) + +// EmailForward represents an email forward in DNSimple. +type EmailForward struct { + ID int `json:"id,omitempty"` + DomainID int `json:"domain_id,omitempty"` + From string `json:"from,omitempty"` + To string `json:"to,omitempty"` + CreatedAt string `json:"created_at,omitempty"` + UpdatedAt string `json:"updated_at,omitempty"` +} + +// EmailForwardResponse represents a response from an API method that returns an EmailForward struct. +type EmailForwardResponse struct { + Response + Data *EmailForward `json:"data"` +} + +// EmailForwardsResponse represents a response from an API method that returns a collection of EmailForward struct. +type EmailForwardsResponse struct { + Response + Data []EmailForward `json:"data"` +} + +func emailForwardPath(accountID string, domain interface{}, forwardID int) string { + path := fmt.Sprintf("%v/email_forwards", domainPath(accountID, domain)) + + if forwardID != 0 { + path += fmt.Sprintf("/%d", forwardID) + } + + return path +} + +// ListEmailForwards lists the email forwards for a domain. +// +// See https://developer.dnsimple.com/v2/domains/email-forwards/#list +func (s *DomainsService) ListEmailForwards(accountID string, domain interface{}, options *ListOptions) (*EmailForwardsResponse, error) { + path := versioned(emailForwardPath(accountID, domain, 0)) + forwardsResponse := &EmailForwardsResponse{} + + path, err := addURLQueryOptions(path, options) + if err != nil { + return nil, err + } + + resp, err := s.client.get(path, forwardsResponse) + if err != nil { + return nil, err + } + + forwardsResponse.HttpResponse = resp + return forwardsResponse, nil +} + +// CreateEmailForward creates a new email forward. +// +// See https://developer.dnsimple.com/v2/domains/email-forwards/#create +func (s *DomainsService) CreateEmailForward(accountID string, domain interface{}, forwardAttributes EmailForward) (*EmailForwardResponse, error) { + path := versioned(emailForwardPath(accountID, domain, 0)) + forwardResponse := &EmailForwardResponse{} + + resp, err := s.client.post(path, forwardAttributes, forwardResponse) + if err != nil { + return nil, err + } + + forwardResponse.HttpResponse = resp + return forwardResponse, nil +} + +// GetEmailForward fetches an email forward. +// +// See https://developer.dnsimple.com/v2/domains/email-forwards/#get +func (s *DomainsService) GetEmailForward(accountID string, domain interface{}, forwardID int) (*EmailForwardResponse, error) { + path := versioned(emailForwardPath(accountID, domain, forwardID)) + forwardResponse := &EmailForwardResponse{} + + resp, err := s.client.get(path, forwardResponse) + if err != nil { + return nil, err + } + + forwardResponse.HttpResponse = resp + return forwardResponse, nil +} + +// DeleteEmailForward PERMANENTLY deletes an email forward from the domain. +// +// See https://developer.dnsimple.com/v2/domains/email-forwards/#delete +func (s *DomainsService) DeleteEmailForward(accountID string, domain interface{}, forwardID int) (*EmailForwardResponse, error) { + path := versioned(emailForwardPath(accountID, domain, forwardID)) + forwardResponse := &EmailForwardResponse{} + + resp, err := s.client.delete(path, nil, nil) + if err != nil { + return nil, err + } + + forwardResponse.HttpResponse = resp + return forwardResponse, nil +} diff --git a/vendor/github.com/dnsimple/dnsimple-go/dnsimple/domains_pushes.go b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/domains_pushes.go new file mode 100644 index 0000000..2a23f75 --- /dev/null +++ b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/domains_pushes.go @@ -0,0 +1,117 @@ +package dnsimple + +import ( + "fmt" +) + +// DomainPush represents a domain push in DNSimple. +type DomainPush struct { + ID int `json:"id,omitempty"` + DomainID int `json:"domain_id,omitempty"` + ContactID int `json:"contact_id,omitempty"` + AccountID int `json:"account_id,omitempty"` + CreatedAt string `json:"created_at,omitempty"` + UpdatedAt string `json:"updated_at,omitempty"` + AcceptedAt string `json:"accepted_at,omitempty"` +} + +// DomainPushAttributes represent a domain push payload (see initiate). +type DomainPushAttributes struct { + NewAccountEmail string `json:"new_account_email,omitempty"` + ContactID string `json:"contact_id,omitempty"` +} + +// DomainPushResponse represents a response from an API method that returns a DomainPush struct. +type DomainPushResponse struct { + Response + Data *DomainPush `json:"data"` +} + +// DomainPushesResponse represents a response from an API method that returns a collection of DomainPush struct. +type DomainPushesResponse struct { + Response + Data []DomainPush `json:"data"` +} + +func initiateDomainPushPath(accountID string, domainID string) string { + return fmt.Sprintf("%v/pushes", domainPath(accountID, domainID)) +} + +func domainPushPath(accountID string, pushID int) string { + path := fmt.Sprintf("%v/pushes", accountID) + + if pushID != 0 { + path += fmt.Sprintf("/%d", pushID) + } + + return path +} + +// InitiatePush initiate a new domain push. +// +// See https://developer.dnsimple.com/v2/domains/pushes/#initiate +func (s *DomainsService) InitiatePush(accountID string, domainID string, pushAttributes DomainPushAttributes) (*DomainPushResponse, error) { + path := versioned(initiateDomainPushPath(accountID, domainID)) + pushResponse := &DomainPushResponse{} + + resp, err := s.client.post(path, pushAttributes, pushResponse) + if err != nil { + return nil, err + } + + pushResponse.HttpResponse = resp + return pushResponse, nil +} + +// ListPushes lists the pushes for an account. +// +// See https://developer.dnsimple.com/v2/domains/pushes/#list +func (s *DomainsService) ListPushes(accountID string, options *ListOptions) (*DomainPushesResponse, error) { + path := versioned(domainPushPath(accountID, 0)) + pushesResponse := &DomainPushesResponse{} + + path, err := addURLQueryOptions(path, options) + if err != nil { + return nil, err + } + + resp, err := s.client.get(path, pushesResponse) + if err != nil { + return nil, err + } + + pushesResponse.HttpResponse = resp + return pushesResponse, nil +} + +// AcceptPush accept a push for a domain. +// +// See https://developer.dnsimple.com/v2/domains/pushes/#accept +func (s *DomainsService) AcceptPush(accountID string, pushID int, pushAttributes DomainPushAttributes) (*DomainPushResponse, error) { + path := versioned(domainPushPath(accountID, pushID)) + pushResponse := &DomainPushResponse{} + + resp, err := s.client.post(path, pushAttributes, nil) + if err != nil { + return nil, err + } + + pushResponse.HttpResponse = resp + return pushResponse, nil +} + +// RejectPush reject a push for a domain. +// +// See https://developer.dnsimple.com/v2/domains/pushes/#reject +func (s *DomainsService) RejectPush(accountID string, pushID int) (*DomainPushResponse, error) { + path := versioned(domainPushPath(accountID, pushID)) + pushResponse := &DomainPushResponse{} + + resp, err := s.client.delete(path, nil, nil) + if err != nil { + return nil, err + } + + pushResponse.HttpResponse = resp + return pushResponse, nil +} diff --git a/vendor/github.com/dnsimple/dnsimple-go/dnsimple/identity.go b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/identity.go new file mode 100644 index 0000000..549c4ae --- /dev/null +++ b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/identity.go @@ -0,0 +1,48 @@ +package dnsimple + +// IdentityService handles communication with several authentication identity +// methods of the DNSimple API. +// +// See https://developer.dnsimple.com/v2/identity/ +type IdentityService struct { + client *Client +} + +// WhoamiData represents an authenticated context +// that contains information about the current logged User and/or Account. +type WhoamiData struct { + User *User `json:"user,omitempty"` + Account *Account `json:"account,omitempty"` +} + +// WhoamiResponse represents a response from an API method that returns a Whoami struct. +type WhoamiResponse struct { + Response + Data *WhoamiData `json:"data"` +} + +// Whoami gets the current authenticate context. +// +// See https://developer.dnsimple.com/v2/whoami +func (s *IdentityService) Whoami() (*WhoamiResponse, error) { + path := versioned("/whoami") + whoamiResponse := &WhoamiResponse{} + + resp, err := s.client.get(path, whoamiResponse) + if err != nil { + return nil, err + } + + whoamiResponse.HttpResponse = resp + return whoamiResponse, nil +} + +// Whoami is a state-less shortcut to client.Whoami() +// that returns only the relevant Data. +func Whoami(c *Client) (data *WhoamiData, err error) { + resp, err := c.Identity.Whoami() + if resp != nil { + data = resp.Data + } + return +} diff --git a/vendor/github.com/dnsimple/dnsimple-go/dnsimple/oauth.go b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/oauth.go new file mode 100644 index 0000000..fc20989 --- /dev/null +++ b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/oauth.go @@ -0,0 +1,113 @@ +package dnsimple + +import ( + "encoding/json" + "fmt" + "net/http" + "net/url" + "strings" +) + +// GrantType is a string that identifies a particular grant type in the exchange request. +type GrantType string + +const ( + // AuthorizationCodeGrant is the type of access token request + // for an Authorization Code Grant flow. + // https://tools.ietf.org/html/rfc6749#section-4.1 + AuthorizationCodeGrant = GrantType("authorization_code") +) + +// OauthService handles communication with the authorization related +// methods of the DNSimple API. +// +// See https://developer.dnsimple.com/v2/oauth/ +type OauthService struct { + client *Client +} + +// AccessToken represents a DNSimple Oauth access token. +type AccessToken struct { + Token string `json:"access_token"` + Type string `json:"token_type"` + AccountID int `json:"account_id"` +} + +// ExchangeAuthorizationRequest represents a request to exchange +// an authorization code for an access token. +// RedirectURI is optional, all the other fields are mandatory. +type ExchangeAuthorizationRequest struct { + Code string `json:"code"` + ClientID string `json:"client_id"` + ClientSecret string `json:"client_secret"` + RedirectURI string `json:"redirect_uri,omitempty"` + State string `json:"state,omitempty"` + GrantType GrantType `json:"grant_type,omitempty"` +} + +// ExchangeAuthorizationError represents a failed request to exchange +// an authorization code for an access token. +type ExchangeAuthorizationError struct { + // HTTP response + HttpResponse *http.Response + + ErrorCode string `json:"error"` + ErrorDescription string `json:"error_description"` +} + +// Error implements the error interface. +func (r *ExchangeAuthorizationError) Error() string { + return fmt.Sprintf("%v %v: %v %v", + r.HttpResponse.Request.Method, r.HttpResponse.Request.URL, + r.ErrorCode, r.ErrorDescription) +} + +// ExchangeAuthorizationForToken exchanges the short-lived authorization code for an access token +// you can use to authenticate your API calls. +func (s *OauthService) ExchangeAuthorizationForToken(authorization *ExchangeAuthorizationRequest) (*AccessToken, error) { + path := versioned("/oauth/access_token") + + req, err := s.client.NewRequest("POST", path, authorization) + if err != nil { + return nil, err + } + + resp, err := s.client.HttpClient.Do(req) + if err != nil { + return nil, err + } + defer resp.Body.Close() + + if resp.StatusCode != 200 { + errorResponse := &ExchangeAuthorizationError{} + errorResponse.HttpResponse = resp + json.NewDecoder(resp.Body).Decode(errorResponse) + return nil, errorResponse + } + + accessToken := &AccessToken{} + err = json.NewDecoder(resp.Body).Decode(accessToken) + + return accessToken, err +} + +// AuthorizationOptions represents the option you can use to generate an authorization URL. +type AuthorizationOptions struct { + RedirectURI string `url:"redirect_uri,omitempty"` + // A randomly generated string to verify the validity of the request. + // Currently "state" is required by the DNSimple OAuth implementation, so you must specify it. + State string `url:"state,omitempty"` +} + +// AuthorizeURL generates the URL to authorize an user for an application via the OAuth2 flow. +func (s *OauthService) AuthorizeURL(clientID string, options *AuthorizationOptions) string { + uri, _ := url.Parse(strings.Replace(s.client.BaseURL, "api.", "", 1)) + uri.Path = "/oauth/authorize" + query := uri.Query() + query.Add("client_id", clientID) + query.Add("response_type", "code") + uri.RawQuery = query.Encode() + + path, _ := addURLQueryOptions(uri.String(), options) + return path +} diff --git a/vendor/github.com/dnsimple/dnsimple-go/dnsimple/registrar.go b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/registrar.go new file mode 100644 index 0000000..520c46f --- /dev/null +++ b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/registrar.go @@ -0,0 +1,170 @@ +package dnsimple + +import ( + "fmt" +) + +// RegistrarService handles communication with the registrar related +// methods of the DNSimple API. +// +// See https://developer.dnsimple.com/v2/registrar/ +type RegistrarService struct { + client *Client +} + +// DomainCheck represents the result of a domain check. +type DomainCheck struct { + Domain string `json:"domain"` + Available bool `json:"available"` + Premium bool `json:"premium"` +} + +// DomainCheckResponse represents a response from the domain check. +type DomainCheckResponse struct { + Response + Data *DomainCheck `json:"data"` +} + +// CheckDomain checks a domain name. +// +// See https://developer.dnsimple.com/v2/registrar/#check +func (s *RegistrarService) CheckDomain(accountID string, domainName string) (*DomainCheckResponse, error) { + path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/check", accountID, domainName)) + checkResponse := &DomainCheckResponse{} + + resp, err := s.client.get(path, checkResponse) + if err != nil { + return nil, err + } + + checkResponse.HttpResponse = resp + return checkResponse, nil +} + +// DomainRegisterRequest represents the attributes you can pass to a register API request. +// Some attributes are mandatory. +type DomainRegisterRequest struct { + // The ID of the Contact to use as registrant for the domain + RegistrantID int `json:"registrant_id"` + // Set to true to enable the whois privacy service. An extra cost may apply. + // Default to false. + EnableWhoisPrivacy bool `json:"private_whois,omitempty"` + // Set to true to enable the auto-renewal of the domain. + // Default to true. + EnableAutoRenewal bool `json:"auto_renew,omitempty"` +} + +// DomainRegistrationResponse represents a response from an API method that results in a domain registration. +type DomainRegistrationResponse struct { + Response + Data *Domain `json:"data"` +} + +// RegisterDomain registers a domain name. +// +// See https://developer.dnsimple.com/v2/registrar/#register +func (s *RegistrarService) RegisterDomain(accountID string, domainName string, request *DomainRegisterRequest) (*DomainRegistrationResponse, error) { + path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/registration", accountID, domainName)) + registrationResponse := &DomainRegistrationResponse{} + + // TODO: validate mandatory attributes RegistrantID + + resp, err := s.client.post(path, request, registrationResponse) + if err != nil { + return nil, err + } + + registrationResponse.HttpResponse = resp + return registrationResponse, nil +} + +// DomainTransferRequest represents the attributes you can pass to a transfer API request. +// Some attributes are mandatory. +type DomainTransferRequest struct { + // The ID of the Contact to use as registrant for the domain + RegistrantID int `json:"registrant_id"` + // The Auth-Code required to transfer the domain. + // This is provided by the current registrar of the domain. + AuthCode string `json:"auth_code,omitempty"` + // Set to true to enable the whois privacy service. An extra cost may apply. + // Default to false. + EnableWhoisPrivacy bool `json:"private_whois,omitempty"` + // Set to true to enable the auto-renewal of the domain. + // Default to true. + EnableAutoRenewal bool `json:"auto_renew,omitempty"` +} + +// DomainTransferResponse represents a response from an API method that results in a domain transfer. +type DomainTransferResponse struct { + Response + Data *Domain `json:"data"` +} + +// TransferDomain transfers a domain name. +// +// See https://developer.dnsimple.com/v2/registrar/#transfer +func (s *RegistrarService) TransferDomain(accountID string, domainName string, request *DomainTransferRequest) (*DomainTransferResponse, error) { + path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/transfer", accountID, domainName)) + transferResponse := &DomainTransferResponse{} + + // TODO: validate mandatory attributes RegistrantID + + resp, err := s.client.post(path, request, transferResponse) + if err != nil { + return nil, err + } + + transferResponse.HttpResponse = resp + return transferResponse, nil +} + +// DomainTransferOutResponse represents a response from an API method that results in a domain transfer out. +type DomainTransferOutResponse struct { + Response + Data *Domain `json:"data"` +} + +// Transfer out a domain name. +// +// See https://developer.dnsimple.com/v2/registrar/#transfer-out +func (s *RegistrarService) TransferDomainOut(accountID string, domainName string) (*DomainTransferOutResponse, error) { + path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/transfer_out", accountID, domainName)) + transferResponse := &DomainTransferOutResponse{} + + resp, err := s.client.post(path, nil, nil) + if err != nil { + return nil, err + } + + transferResponse.HttpResponse = resp + return transferResponse, nil +} + +// DomainRenewRequest represents the attributes you can pass to a renew API request. +// Some attributes are mandatory. +type DomainRenewRequest struct { + // The number of years + Period int `json:"period"` +} + +// DomainRenewalResponse represents a response from an API method that results in a domain renewal. +type DomainRenewalResponse struct { + Response + Data *Domain `json:"data"` +} + +// RenewDomain renews a domain name. +// +// See https://developer.dnsimple.com/v2/registrar/#register +func (s *RegistrarService) RenewDomain(accountID string, domainName string, request *DomainRenewRequest) (*DomainRenewalResponse, error) { + path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/renewal", accountID, domainName)) + renewalResponse := &DomainRenewalResponse{} + + resp, err := s.client.post(path, request, renewalResponse) + if err != nil { + return nil, err + } + + renewalResponse.HttpResponse = resp + return renewalResponse, nil +} diff --git a/vendor/github.com/dnsimple/dnsimple-go/dnsimple/registrar_auto_renewal.go b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/registrar_auto_renewal.go new file mode 100644 index 0000000..5bb59ae --- /dev/null +++ b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/registrar_auto_renewal.go @@ -0,0 +1,37 @@ +package dnsimple + +import ( + "fmt" +) + +// EnableDomainAutoRenewal enables auto-renewal for the domain. +// +// See https://developer.dnsimple.com/v2/registrar/auto-renewal/#enable +func (s *RegistrarService) EnableDomainAutoRenewal(accountID string, domainName string) (*DomainResponse, error) { + path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/auto_renewal", accountID, domainName)) + domainResponse := &DomainResponse{} + + resp, err := s.client.put(path, nil, nil) + if err != nil { + return nil, err + } + + domainResponse.HttpResponse = resp + return domainResponse, nil +} + +// DisableDomainAutoRenewal disables auto-renewal for the domain. +// +// See https://developer.dnsimple.com/v2/registrar/auto-renewal/#enable +func (s *RegistrarService) DisableDomainAutoRenewal(accountID string, domainName string) (*DomainResponse, error) { + path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/auto_renewal", accountID, domainName)) + domainResponse := &DomainResponse{} + + resp, err := s.client.delete(path, nil, nil) + if err != nil { + return nil, err + } + + domainResponse.HttpResponse = resp + return domainResponse, nil +} diff --git a/vendor/github.com/dnsimple/dnsimple-go/dnsimple/registrar_delegation.go b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/registrar_delegation.go new file mode 100644 index 0000000..b95578d --- /dev/null +++ b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/registrar_delegation.go @@ -0,0 +1,84 @@ +package dnsimple + +import ( + "fmt" +) + +// Delegation represents a list of name servers that correspond to a domain delegation. +type Delegation []string + +// DelegationResponse represents a response from an API method that returns a delegation struct. +type DelegationResponse struct { + Response + Data *Delegation `json:"data"` +} + +// VanityDelegationResponse represents a response for vanity name server enable and disable operations. +type VanityDelegationResponse struct { + Response + Data []VanityNameServer `json:"data"` +} + +// GetDomainDelegation gets the current delegated name servers for the domain. +// +// See https://developer.dnsimple.com/v2/registrar/delegation/#get +func (s *RegistrarService) GetDomainDelegation(accountID string, domainName string) (*DelegationResponse, error) { + path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/delegation", accountID, domainName)) + delegationResponse := &DelegationResponse{} + + resp, err := s.client.get(path, delegationResponse) + if err != nil { + return nil, err + } + + delegationResponse.HttpResponse = resp + return delegationResponse, nil +} + +// ChangeDomainDelegation updates the delegated name severs for the domain. +// +// See https://developer.dnsimple.com/v2/registrar/delegation/#get +func (s *RegistrarService) ChangeDomainDelegation(accountID string, domainName string, newDelegation *Delegation) (*DelegationResponse, error) { + path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/delegation", accountID, domainName)) + delegationResponse := &DelegationResponse{} + + resp, err := s.client.put(path, newDelegation, delegationResponse) + if err != nil { + return nil, err + } + + delegationResponse.HttpResponse = resp + return delegationResponse, nil +} + +// ChangeDomainDelegationToVanity enables vanity name servers for the given domain. +// +// See https://developer.dnsimple.com/v2/registrar/delegation/#delegateToVanity +func (s *RegistrarService) ChangeDomainDelegationToVanity(accountID string, domainName string, newDelegation *Delegation) (*VanityDelegationResponse, error) { + path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/delegation/vanity", accountID, domainName)) + delegationResponse := &VanityDelegationResponse{} + + resp, err := s.client.put(path, newDelegation, delegationResponse) + if err != nil { + return nil, err + } + + delegationResponse.HttpResponse = resp + return delegationResponse, nil +} + +// ChangeDomainDelegationFromVanity disables vanity name servers for the given domain. +// +// See https://developer.dnsimple.com/v2/registrar/delegation/#dedelegateFromVanity +func (s *RegistrarService) ChangeDomainDelegationFromVanity(accountID string, domainName string) (*VanityDelegationResponse, error) { + path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/delegation/vanity", accountID, domainName)) + delegationResponse := &VanityDelegationResponse{} + + resp, err := s.client.delete(path, nil, nil) + if err != nil { + return nil, err + } + + delegationResponse.HttpResponse = resp + return delegationResponse, nil +} diff --git a/vendor/github.com/dnsimple/dnsimple-go/dnsimple/registrar_whois_privacy.go b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/registrar_whois_privacy.go new file mode 100644 index 0000000..91d45bb --- /dev/null +++ b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/registrar_whois_privacy.go @@ -0,0 +1,69 @@ +package dnsimple + +import ( + "fmt" +) + +// WhoisPrivacy represents a whois privacy in DNSimple. +type WhoisPrivacy struct { + ID int `json:"id,omitempty"` + DomainID int `json:"domain_id,omitempty"` + Enabled bool `json:"enabled,omitempty"` + ExpiresOn string `json:"expires_on,omitempty"` + CreatedAt string `json:"created_at,omitempty"` + UpdatedAt string `json:"updated_at,omitempty"` +} + +// WhoisPrivacyResponse represents a response from an API method that returns a WhoisPrivacy struct. +type WhoisPrivacyResponse struct { + Response + Data *WhoisPrivacy `json:"data"` +} + +// GetWhoisPrivacy gets the whois privacy for the domain. +// +// See https://developer.dnsimple.com/v2/registrar/whois-privacy/#get +func (s *RegistrarService) GetWhoisPrivacy(accountID string, domainName string) (*WhoisPrivacyResponse, error) { + path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/whois_privacy", accountID, domainName)) + privacyResponse := &WhoisPrivacyResponse{} + + resp, err := s.client.get(path, privacyResponse) + if err != nil { + return nil, err + } + + privacyResponse.HttpResponse = resp + return privacyResponse, nil +} + +// EnableWhoisPrivacy enables the whois privacy for the domain. +// +// See https://developer.dnsimple.com/v2/registrar/whois-privacy/#enable +func (s *RegistrarService) EnableWhoisPrivacy(accountID string, domainName string) (*WhoisPrivacyResponse, error) { + path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/whois_privacy", accountID, domainName)) + privacyResponse := &WhoisPrivacyResponse{} + + resp, err := s.client.put(path, nil, privacyResponse) + if err != nil { + return nil, err + } + + privacyResponse.HttpResponse = resp + return privacyResponse, nil +} + +// DisablePrivacy disables the whois privacy for the domain. +// +// See https://developer.dnsimple.com/v2/registrar/whois-privacy/#enable +func (s *RegistrarService) DisableWhoisPrivacy(accountID string, domainName string) (*WhoisPrivacyResponse, error) { + path := versioned(fmt.Sprintf("/%v/registrar/domains/%v/whois_privacy", accountID, domainName)) + privacyResponse := &WhoisPrivacyResponse{} + + resp, err := s.client.delete(path, nil, privacyResponse) + if err != nil { + return nil, err + } + + privacyResponse.HttpResponse = resp + return privacyResponse, nil +} diff --git a/vendor/github.com/dnsimple/dnsimple-go/dnsimple/services.go b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/services.go new file mode 100644 index 0000000..4b9d909 --- /dev/null +++ b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/services.go @@ -0,0 +1,93 @@ +package dnsimple + +import ( + "fmt" +) + +// ServicesService handles communication with the service related +// methods of the DNSimple API. +// +// See https://developer.dnsimple.com/v2/services/ +type ServicesService struct { + client *Client +} + +// ServiceSetting represents a single group of settings for a DNSimple Service. +type ServiceSetting struct { + Name string `json:"name,omitempty"` + Label string `json:"label,omitempty"` + Append string `json:"append,omitempty"` + Description string `json:"description,omitempty"` + Example string `json:"example,omitempty"` + Password bool `json:"password,omitempty"` +} + +// Service represents a Service in DNSimple. +type Service struct { + ID int `json:"id,omitempty"` + Name string `json:"name,omitempty"` + ShortName string `json:"short_name,omitempty"` + Description string `json:"description,omitempty"` + SetupDescription string `json:"setup_description,omitempty"` + RequiresSetup bool `json:"requires_setup,omitempty"` + DefaultSubdomain string `json:"default_subdomain,omitempty"` + CreatedAt string `json:"created_at,omitempty"` + UpdatedAt string `json:"updated_at,omitempty"` + Settings []ServiceSetting `json:"settings,omitempty"` +} + +func servicePath(serviceID string) string { + if serviceID != "" { + return fmt.Sprintf("/services/%v", serviceID) + } + return fmt.Sprintf("/services") +} + +// ServiceResponse represents a response from an API method that returns a Service struct. +type ServiceResponse struct { + Response + Data *Service `json:"data"` +} + +// ServicesResponse represents a response from an API method that returns a collection of Service struct. +type ServicesResponse struct { + Response + Data []Service `json:"data"` +} + +// ListServices lists the one-click services available in DNSimple. +// +// See https://developer.dnsimple.com/v2/services/#list +func (s *ServicesService) ListServices(options *ListOptions) (*ServicesResponse, error) { + path := versioned(servicePath("")) + servicesResponse := &ServicesResponse{} + + path, err := addURLQueryOptions(path, options) + if err != nil { + return nil, err + } + + resp, err := s.client.get(path, servicesResponse) + if err != nil { + return servicesResponse, err + } + + servicesResponse.HttpResponse = resp + return servicesResponse, nil +} + +// GetService fetches a one-click service. +// +// See https://developer.dnsimple.com/v2/services/#get +func (s *ServicesService) GetService(serviceIdentifier string) (*ServiceResponse, error) { + path := versioned(servicePath(serviceIdentifier)) + serviceResponse := &ServiceResponse{} + + resp, err := s.client.get(path, serviceResponse) + if err != nil { + return nil, err + } + + serviceResponse.HttpResponse = resp + return serviceResponse, nil +} diff --git a/vendor/github.com/dnsimple/dnsimple-go/dnsimple/services_domains.go b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/services_domains.go new file mode 100644 index 0000000..e15eeee --- /dev/null +++ b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/services_domains.go @@ -0,0 +1,70 @@ +package dnsimple + +import ( + "fmt" +) + +func domainServicesPath(accountID string, domainID string, serviceIdentifier string) string { + if serviceIdentifier != "" { + return fmt.Sprintf("/%v/domains/%v/services/%v", accountID, domainID, serviceIdentifier) + } + return fmt.Sprintf("/%v/domains/%v/services", accountID, domainID) +} + +// DomainServiceSettings represents optional settings when applying a DNSimple one-click service to a domain. +type DomainServiceSettings struct { + Settings map[string]string `url:"settings,omitempty"` +} + +// AppliedServices lists the applied one-click services for a domain. +// +// See https://developer.dnsimple.com/v2/services/domains/#applied +func (s *ServicesService) AppliedServices(accountID string, domainID string, options *ListOptions) (*ServicesResponse, error) { + path := versioned(domainServicesPath(accountID, domainID, "")) + servicesResponse := &ServicesResponse{} + + path, err := addURLQueryOptions(path, options) + if err != nil { + return nil, err + } + + resp, err := s.client.get(path, servicesResponse) + if err != nil { + return servicesResponse, err + } + + servicesResponse.HttpResponse = resp + return servicesResponse, nil +} + +// ApplyService applies a one-click services to a domain. +// +// See https://developer.dnsimple.com/v2/services/domains/#apply +func (s *ServicesService) ApplyService(accountID string, serviceIdentifier string, domainID string, settings DomainServiceSettings) (*ServiceResponse, error) { + path := versioned(domainServicesPath(accountID, domainID, serviceIdentifier)) + serviceResponse := &ServiceResponse{} + + resp, err := s.client.post(path, settings, nil) + if err != nil { + return nil, err + } + + serviceResponse.HttpResponse = resp + return serviceResponse, nil +} + +// UnapplyService unapplies a one-click services from a domain. +// +// See https://developer.dnsimple.com/v2/services/domains/#unapply +func (s *ServicesService) UnapplyService(accountID string, serviceIdentifier string, domainID string) (*ServiceResponse, error) { + path := versioned(domainServicesPath(accountID, domainID, serviceIdentifier)) + serviceResponse := &ServiceResponse{} + + resp, err := s.client.delete(path, nil, nil) + if err != nil { + return nil, err + } + + serviceResponse.HttpResponse = resp + return serviceResponse, nil +} diff --git a/vendor/github.com/dnsimple/dnsimple-go/dnsimple/templates.go b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/templates.go new file mode 100644 index 0000000..620d266 --- /dev/null +++ b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/templates.go @@ -0,0 +1,129 @@ +package dnsimple + +import ( + "fmt" +) + +// TemplatesService handles communication with the template related +// methods of the DNSimple API. +// +// See https://developer.dnsimple.com/v2/templates/ +type TemplatesService struct { + client *Client +} + +// Template represents a Template in DNSimple. +type Template struct { + ID int `json:"id,omitempty"` + AccountID int `json:"account_id,omitempty"` + Name string `json:"name,omitempty"` + ShortName string `json:"short_name,omitempty"` + Description string `json:"description,omitempty"` + CreatedAt string `json:"created_at,omitempty"` + UpdatedAt string `json:"updated_at,omitempty"` +} + +func templatePath(accountID string, templateIdentifier string) string { + if templateIdentifier != "" { + return fmt.Sprintf("/%v/templates/%v", accountID, templateIdentifier) + } + + return fmt.Sprintf("/%v/templates", accountID) +} + +// TemplateResponse represents a response from an API method that returns a Template struct. +type TemplateResponse struct { + Response + Data *Template `json:"data"` +} + +// TemplatesResponse represents a response from an API method that returns a collection of Template struct. +type TemplatesResponse struct { + Response + Data []Template `json:"data"` +} + +// ListTemplates list the templates for an account. +// +// See https://developer.dnsimple.com/v2/templates/#list +func (s *TemplatesService) ListTemplates(accountID string, options *ListOptions) (*TemplatesResponse, error) { + path := versioned(templatePath(accountID, "")) + templatesResponse := &TemplatesResponse{} + + path, err := addURLQueryOptions(path, options) + if err != nil { + return nil, err + } + + resp, err := s.client.get(path, templatesResponse) + if err != nil { + return templatesResponse, err + } + + templatesResponse.HttpResponse = resp + return templatesResponse, nil +} + +// CreateTemplate creates a new template. +// +// See https://developer.dnsimple.com/v2/templates/#create +func (s *TemplatesService) CreateTemplate(accountID string, templateAttributes Template) (*TemplateResponse, error) { + path := versioned(templatePath(accountID, "")) + templateResponse := &TemplateResponse{} + + resp, err := s.client.post(path, templateAttributes, templateResponse) + if err != nil { + return nil, err + } + + templateResponse.HttpResponse = resp + return templateResponse, nil +} + +// GetTemplate fetches a template. +// +// See https://developer.dnsimple.com/v2/templates/#get +func (s *TemplatesService) GetTemplate(accountID string, templateIdentifier string) (*TemplateResponse, error) { + path := versioned(templatePath(accountID, templateIdentifier)) + templateResponse := &TemplateResponse{} + + resp, err := s.client.get(path, templateResponse) + if err != nil { + return nil, err + } + + templateResponse.HttpResponse = resp + return templateResponse, nil +} + +// UpdateTemplate updates a template. +// +// See https://developer.dnsimple.com/v2/templates/#update +func (s *TemplatesService) UpdateTemplate(accountID string, templateIdentifier string, templateAttributes Template) (*TemplateResponse, error) { + path := versioned(templatePath(accountID, templateIdentifier)) + templateResponse := &TemplateResponse{} + + resp, err := s.client.patch(path, templateAttributes, templateResponse) + if err != nil { + return nil, err + } + + templateResponse.HttpResponse = resp + return templateResponse, nil +} + +// DeleteTemplate deletes a template. +// +// See https://developer.dnsimple.com/v2/templates/#delete +func (s *TemplatesService) DeleteTemplate(accountID string, templateIdentifier string) (*TemplateResponse, error) { + path := versioned(templatePath(accountID, templateIdentifier)) + templateResponse := &TemplateResponse{} + + resp, err := s.client.delete(path, nil, nil) + if err != nil { + return nil, err + } + + templateResponse.HttpResponse = resp + return templateResponse, nil +} diff --git a/vendor/github.com/dnsimple/dnsimple-go/dnsimple/templates_domains.go b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/templates_domains.go new file mode 100644 index 0000000..126dcc4 --- /dev/null +++ b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/templates_domains.go @@ -0,0 +1,21 @@ +package dnsimple + +import ( + "fmt" +) + +// ApplyTemplate applies a template to the given domain. +// +// See https://developer.dnsimple.com/v2/templates/domains/#apply +func (s *TemplatesService) ApplyTemplate(accountID string, templateIdentifier string, domainID string) (*TemplateResponse, error) { + path := versioned(fmt.Sprintf("%v/templates/%v", domainPath(accountID, domainID), templateIdentifier)) + templateResponse := &TemplateResponse{} + + resp, err := s.client.post(path, nil, nil) + if err != nil { + return nil, err + } + + templateResponse.HttpResponse = resp + return templateResponse, nil +} diff --git a/vendor/github.com/dnsimple/dnsimple-go/dnsimple/templates_records.go b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/templates_records.go new file mode 100644 index 0000000..3e362ab --- /dev/null +++ b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/templates_records.go @@ -0,0 +1,107 @@ +package dnsimple + +import ( + "fmt" +) + +// TemplateRecord represents a DNS record for a template in DNSimple. +type TemplateRecord struct { + ID int `json:"id,omitempty"` + TemplateID int `json:"template_id,omitempty"` + Name string `json:"name"` + Content string `json:"content,omitempty"` + TTL int `json:"ttl,omitempty"` + Type string `json:"type,omitempty"` + Priority int `json:"priority,omitempty"` + CreatedAt string `json:"created_at,omitempty"` + UpdatedAt string `json:"updated_at,omitempty"` +} + +// TemplateRecordResponse represents a response from an API method that returns a TemplateRecord struct. +type TemplateRecordResponse struct { + Response + Data *TemplateRecord `json:"data"` +} + +// TemplateRecordsResponse represents a response from an API method that returns a collection of TemplateRecord struct. +type TemplateRecordsResponse struct { + Response + Data []TemplateRecord `json:"data"` +} + +func templateRecordPath(accountID string, templateIdentifier string, templateRecordID string) string { + if templateRecordID != "" { + return fmt.Sprintf("%v/records/%v", templatePath(accountID, templateIdentifier), templateRecordID) + } + + return templatePath(accountID, templateIdentifier) + "/records" +} + +// ListTemplateRecords list the templates for an account. +// +// See https://developer.dnsimple.com/v2/templates/records/#list +func (s *TemplatesService) ListTemplateRecords(accountID string, templateIdentifier string, options *ListOptions) (*TemplateRecordsResponse, error) { + path := versioned(templateRecordPath(accountID, templateIdentifier, "")) + templateRecordsResponse := &TemplateRecordsResponse{} + + path, err := addURLQueryOptions(path, options) + if err != nil { + return nil, err + } + + resp, err := s.client.get(path, templateRecordsResponse) + if err != nil { + return templateRecordsResponse, err + } + + templateRecordsResponse.HttpResponse = resp + return templateRecordsResponse, nil +} + +// CreateTemplateRecord creates a new template record. +// +// See https://developer.dnsimple.com/v2/templates/records/#create +func (s *TemplatesService) CreateTemplateRecord(accountID string, templateIdentifier string, templateRecordAttributes TemplateRecord) (*TemplateRecordResponse, error) { + path := versioned(templateRecordPath(accountID, templateIdentifier, "")) + templateRecordResponse := &TemplateRecordResponse{} + + resp, err := s.client.post(path, templateRecordAttributes, templateRecordResponse) + if err != nil { + return nil, err + } + + templateRecordResponse.HttpResponse = resp + return templateRecordResponse, nil +} + +// GetTemplateRecord fetches a template record. +// +// See https://developer.dnsimple.com/v2/templates/records/#get +func (s *TemplatesService) GetTemplateRecord(accountID string, templateIdentifier string, templateRecordID string) (*TemplateRecordResponse, error) { + path := versioned(templateRecordPath(accountID, templateIdentifier, templateRecordID)) + templateRecordResponse := &TemplateRecordResponse{} + + resp, err := s.client.get(path, templateRecordResponse) + if err != nil { + return nil, err + } + + templateRecordResponse.HttpResponse = resp + return templateRecordResponse, nil +} + +// DeleteTemplateRecord deletes a template record. +// +// See https://developer.dnsimple.com/v2/templates/records/#delete +func (s *TemplatesService) DeleteTemplateRecord(accountID string, templateIdentifier string, templateRecordID string) (*TemplateRecordResponse, error) { + path := versioned(templateRecordPath(accountID, templateIdentifier, templateRecordID)) + templateRecordResponse := &TemplateRecordResponse{} + + resp, err := s.client.delete(path, nil, nil) + if err != nil { + return nil, err + } + + templateRecordResponse.HttpResponse = resp + return templateRecordResponse, nil +} diff --git a/vendor/github.com/dnsimple/dnsimple-go/dnsimple/tlds.go b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/tlds.go new file mode 100644 index 0000000..06b1a7f --- /dev/null +++ b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/tlds.go @@ -0,0 +1,117 @@ +package dnsimple + +import ( + "fmt" +) + +// TldsService handles communication with the Tld related +// methods of the DNSimple API. +// +// See https://developer.dnsimple.com/v2/tlds/ +type TldsService struct { + client *Client +} + +// Tld represents a TLD in DNSimple. +type Tld struct { + Tld string `json:"tld"` + TldType int `json:"tld_type"` + WhoisPrivacy bool `json:"whois_privacy"` + AutoRenewOnly bool `json:"auto_renew_only"` + MinimumRegistration int `json:"minimum_registration"` + RegistrationEnabled bool `json:"registration_enabled"` + RenewalEnabled bool `json:"renewal_enabled"` + TransferEnabled bool `json:"transfer_enabled"` +} + +// TldExtendedAttribute represents an extended attributes supported or required +// by a specific TLD. +// +// See https://developer.dnsimple.com/v2/tlds/ +type TldExtendedAttribute struct { + Name string `json:"name"` + Description string `json:"description"` + Required bool `json:"required"` + Options []TldExtendedAttributeOption `json:"options"` +} + +// TldExtendedAttributeOption represents a single option you can assign to an extended attributes. +// +// See https://developer.dnsimple.com/v2/tlds/ +type TldExtendedAttributeOption struct { + Title string `json:"title"` + Value string `json:"value"` + Description string `json:"description"` +} + +// TldResponse represents a response from an API method that returns a Tld struct. +type TldResponse struct { + Response + Data *Tld `json:"data"` +} + +// TldsResponse represents a response from an API method that returns a collection of Tld struct. +type TldsResponse struct { + Response + Data []Tld `json:"data"` +} + +// TldExtendedAttributesResponse represents a response from an API method that returns +// a collection of Tld extended attributes. +type TldExtendedAttributesResponse struct { + Response + Data []TldExtendedAttribute `json:"data"` +} + +// ListTlds lists the supported TLDs. +// +// See https://developer.dnsimple.com/v2/tlds/#list +func (s *TldsService) ListTlds(options *ListOptions) (*TldsResponse, error) { + path := versioned("/tlds") + tldsResponse := &TldsResponse{} + + path, err := addURLQueryOptions(path, options) + if err != nil { + return nil, err + } + + resp, err := s.client.get(path, tldsResponse) + if err != nil { + return tldsResponse, err + } + + tldsResponse.HttpResponse = resp + return tldsResponse, nil +} + +// GetTld fetches a TLD. +// +// See https://developer.dnsimple.com/v2/tlds/#get +func (s *TldsService) GetTld(tld string) (*TldResponse, error) { + path := versioned(fmt.Sprintf("/tlds/%s", tld)) + tldResponse := &TldResponse{} + + resp, err := s.client.get(path, tldResponse) + if err != nil { + return nil, err + } + + tldResponse.HttpResponse = resp + return tldResponse, nil +} + +// GetTld fetches the extended attributes of a TLD. +// +// See https://developer.dnsimple.com/v2/tlds/#get +func (s *TldsService) GetTldExtendedAttributes(tld string) (*TldExtendedAttributesResponse, error) { + path := versioned(fmt.Sprintf("/tlds/%s/extended_attributes", tld)) + tldResponse := &TldExtendedAttributesResponse{} + + resp, err := s.client.get(path, tldResponse) + if err != nil { + return nil, err + } + + tldResponse.HttpResponse = resp + return tldResponse, nil +} diff --git a/vendor/github.com/dnsimple/dnsimple-go/dnsimple/users.go b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/users.go new file mode 100644 index 0000000..90cd25b --- /dev/null +++ b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/users.go @@ -0,0 +1,7 @@ +package dnsimple + +// User represents a DNSimple user. +type User struct { + ID int `json:"id,omitempty"` + Email string `json:"email,omitempty"` +} diff --git a/vendor/github.com/dnsimple/dnsimple-go/dnsimple/vanity_name_server.go b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/vanity_name_server.go new file mode 100644 index 0000000..d5e75ae --- /dev/null +++ b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/vanity_name_server.go @@ -0,0 +1,65 @@ +package dnsimple + +import ( + "fmt" +) + +// VanityNameServersService handles communication with Vanity Name Servers +// methods of the DNSimple API. +// +// See https://developer.dnsimple.com/v2/vanity/ +type VanityNameServersService struct { + client *Client +} + +// VanityNameServer represents data for a single vanity name server +type VanityNameServer struct { + ID int `json:"id,omitempty"` + Name string `json:"name,omitempty"` + IPv4 string `json:"ipv4,omitempty"` + IPv6 string `json:"ipv6,omitempty"` + CreatedAt string `json:"created_at,omitempty"` + UpdatedAt string `json:"updated_at,omitempty"` +} + +// VanityNameServerResponse represents a response for vanity name server enable and disable operations. +type VanityNameServerResponse struct { + Response + Data []VanityNameServer `json:"data"` +} + +func vanityNameServerPath(accountID string, domainID string) string { + return fmt.Sprintf("/%v/vanity/%v", accountID, domainID) +} + +// EnableVanityNameServers Vanity Name Servers for the given domain +// +// See https://developer.dnsimple.com/v2/vanity/#enable +func (s *VanityNameServersService) EnableVanityNameServers(accountID string, domainID string) (*VanityNameServerResponse, error) { + path := versioned(vanityNameServerPath(accountID, domainID)) + vanityNameServerResponse := &VanityNameServerResponse{} + + resp, err := s.client.put(path, nil, vanityNameServerResponse) + if err != nil { + return nil, err + } + + vanityNameServerResponse.HttpResponse = resp + return vanityNameServerResponse, nil +} + +// DisableVanityNameServers Vanity Name Servers for the given domain +// +// See https://developer.dnsimple.com/v2/vanity/#disable +func (s *VanityNameServersService) DisableVanityNameServers(accountID string, domainID string) (*VanityNameServerResponse, error) { + path := versioned(vanityNameServerPath(accountID, domainID)) + vanityNameServerResponse := &VanityNameServerResponse{} + + resp, err := s.client.delete(path, nil, nil) + if err != nil { + return nil, err + } + + vanityNameServerResponse.HttpResponse = resp + return vanityNameServerResponse, nil +} diff --git a/vendor/github.com/dnsimple/dnsimple-go/dnsimple/webhooks.go b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/webhooks.go new file mode 100644 index 0000000..1a91ab8 --- /dev/null +++ b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/webhooks.go @@ -0,0 +1,104 @@ +package dnsimple + +import ( + "fmt" +) + +// WebhooksService handles communication with the webhook related +// methods of the DNSimple API. +// +// See https://developer.dnsimple.com/v2/webhooks +type WebhooksService struct { + client *Client +} + +// Webhook represents a DNSimple webhook. +type Webhook struct { + ID int `json:"id,omitempty"` + URL string `json:"url,omitempty"` +} + +// WebhookResponse represents a response from an API method that returns a Webhook struct. +type WebhookResponse struct { + Response + Data *Webhook `json:"data"` +} + +// WebhookResponse represents a response from an API method that returns a collection of Webhook struct. +type WebhooksResponse struct { + Response + Data []Webhook `json:"data"` +} + +// webhookPath generates the resource path for given webhook. +func webhookPath(accountID string, webhookID int) (path string) { + path = fmt.Sprintf("/%v/webhooks", accountID) + if webhookID != 0 { + path = fmt.Sprintf("%v/%v", path, webhookID) + } + return +} + +// ListWebhooks lists the webhooks for an account. +// +// See https://developer.dnsimple.com/v2/webhooks#list +func (s *WebhooksService) ListWebhooks(accountID string, _ *ListOptions) (*WebhooksResponse, error) { + path := versioned(webhookPath(accountID, 0)) + webhooksResponse := &WebhooksResponse{} + + resp, err := s.client.get(path, webhooksResponse) + if err != nil { + return webhooksResponse, err + } + + webhooksResponse.HttpResponse = resp + return webhooksResponse, nil +} + +// CreateWebhook creates a new webhook. +// +// See https://developer.dnsimple.com/v2/webhooks#create +func (s *WebhooksService) CreateWebhook(accountID string, webhookAttributes Webhook) (*WebhookResponse, error) { + path := versioned(webhookPath(accountID, 0)) + webhookResponse := &WebhookResponse{} + + resp, err := s.client.post(path, webhookAttributes, webhookResponse) + if err != nil { + return nil, err + } + + webhookResponse.HttpResponse = resp + return webhookResponse, nil +} + +// GetWebhook fetches a webhook. +// +// See https://developer.dnsimple.com/v2/webhooks#get +func (s *WebhooksService) GetWebhook(accountID string, webhookID int) (*WebhookResponse, error) { + path := versioned(webhookPath(accountID, webhookID)) + webhookResponse := &WebhookResponse{} + + resp, err := s.client.get(path, webhookResponse) + if err != nil { + return nil, err + } + + webhookResponse.HttpResponse = resp + return webhookResponse, nil +} + +// DeleteWebhook PERMANENTLY deletes a webhook from the account. +// +// See https://developer.dnsimple.com/v2/webhooks#delete +func (s *WebhooksService) DeleteWebhook(accountID string, webhookID int) (*WebhookResponse, error) { + path := versioned(webhookPath(accountID, webhookID)) + webhookResponse := &WebhookResponse{} + + resp, err := s.client.delete(path, nil, nil) + if err != nil { + return nil, err + } + + webhookResponse.HttpResponse = resp + return webhookResponse, nil +} diff --git a/vendor/github.com/dnsimple/dnsimple-go/dnsimple/zones.go b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/zones.go new file mode 100644 index 0000000..14fef26 --- /dev/null +++ b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/zones.go @@ -0,0 +1,108 @@ +package dnsimple + +import ( + "fmt" +) + +// ZonesService handles communication with the zone related +// methods of the DNSimple API. +// +// See https://developer.dnsimple.com/v2/zones/ +type ZonesService struct { + client *Client +} + +// Zone represents a Zone in DNSimple. +type Zone struct { + ID int `json:"id,omitempty"` + AccountID int `json:"account_id,omitempty"` + Name string `json:"name,omitempty"` + Reverse bool `json:"reverse,omitempty"` + CreatedAt string `json:"created_at,omitempty"` + UpdatedAt string `json:"updated_at,omitempty"` +} + +// ZoneFile represents a Zone File in DNSimple. +type ZoneFile struct { + Zone string `json:"zone,omitempty"` +} + +// ZoneListOptions specifies the optional parameters you can provide +// to customize the ZonesService.ListZones method. +type ZoneListOptions struct { + // Select domains where the name contains given string. + NameLike string `url:"name_like,omitempty"` + + ListOptions +} + +// ZoneResponse represents a response from an API method that returns a Zone struct. +type ZoneResponse struct { + Response + Data *Zone `json:"data"` +} + +// ZonesResponse represents a response from an API method that returns a collection of Zone struct. +type ZonesResponse struct { + Response + Data []Zone `json:"data"` +} + +// ZoneFileResponse represents a response from an API method that returns a ZoneFile struct. +type ZoneFileResponse struct { + Response + Data *ZoneFile `json:"data"` +} + +// ListZones the zones for an account. +// +// See https://developer.dnsimple.com/v2/zones/#list +func (s *ZonesService) ListZones(accountID string, options *ZoneListOptions) (*ZonesResponse, error) { + path := versioned(fmt.Sprintf("/%v/zones", accountID)) + zonesResponse := &ZonesResponse{} + + path, err := addURLQueryOptions(path, options) + if err != nil { + return nil, err + } + + resp, err := s.client.get(path, zonesResponse) + if err != nil { + return zonesResponse, err + } + + zonesResponse.HttpResponse = resp + return zonesResponse, nil +} + +// GetZone fetches a zone. +// +// See https://developer.dnsimple.com/v2/zones/#get +func (s *ZonesService) GetZone(accountID string, zoneName string) (*ZoneResponse, error) { + path := versioned(fmt.Sprintf("/%v/zones/%v", accountID, zoneName)) + zoneResponse := &ZoneResponse{} + + resp, err := s.client.get(path, zoneResponse) + if err != nil { + return nil, err + } + + zoneResponse.HttpResponse = resp + return zoneResponse, nil +} + +// GetZoneFile fetches a zone file. +// +// See https://developer.dnsimple.com/v2/zones/#get-file +func (s *ZonesService) GetZoneFile(accountID string, zoneName string) (*ZoneFileResponse, error) { + path := versioned(fmt.Sprintf("/%v/zones/%v/file", accountID, zoneName)) + zoneFileResponse := &ZoneFileResponse{} + + resp, err := s.client.get(path, zoneFileResponse) + if err != nil { + return nil, err + } + + zoneFileResponse.HttpResponse = resp + return zoneFileResponse, nil +} diff --git a/vendor/github.com/dnsimple/dnsimple-go/dnsimple/zones_records.go b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/zones_records.go new file mode 100644 index 0000000..9107e94 --- /dev/null +++ b/vendor/github.com/dnsimple/dnsimple-go/dnsimple/zones_records.go @@ -0,0 +1,144 @@ +package dnsimple + +import ( + "fmt" +) + +// ZoneRecord represents a DNS record in DNSimple. +type ZoneRecord struct { + ID int `json:"id,omitempty"` + ZoneID string `json:"zone_id,omitempty"` + ParentID int `json:"parent_id,omitempty"` + Type string `json:"type,omitempty"` + Name string `json:"name"` + Content string `json:"content,omitempty"` + TTL int `json:"ttl,omitempty"` + Priority int `json:"priority,omitempty"` + SystemRecord bool `json:"system_record,omitempty"` + Regions []string `json:"regions,omitempty"` + CreatedAt string `json:"created_at,omitempty"` + UpdatedAt string `json:"updated_at,omitempty"` +} + +// ZoneRecordListOptions specifies the optional parameters you can provide +// to customize the ZonesService.ListZoneRecords method. +type ZoneRecordListOptions struct { + // Select records where the name matches given string. + Name string `url:"name,omitempty"` + + // Select records where the name contains given string. + NameLike string `url:"name_like,omitempty"` + + // Select records of given type. + // Eg. TXT, A, NS. + Type string `url:"record_type,omitempty"` + + ListOptions +} + +// ZoneRecordResponse represents a response from an API method that returns a ZoneRecord struct. +type ZoneRecordResponse struct { + Response + Data *ZoneRecord `json:"data"` +} + +// ZoneRecordsResponse represents a response from an API method that returns a collection of ZoneRecord struct. +type ZoneRecordsResponse struct { + Response + Data []ZoneRecord `json:"data"` +} + +func zoneRecordPath(accountID string, zoneID string, recordID int) string { + path := fmt.Sprintf("/%v/zones/%v/records", accountID, zoneID) + + if recordID != 0 { + path += fmt.Sprintf("/%d", recordID) + } + + return path +} + +// ListRecords lists the zone records for a zone. +// +// See https://developer.dnsimple.com/v2/zones/#list +func (s *ZonesService) ListRecords(accountID string, zoneID string, options *ZoneRecordListOptions) (*ZoneRecordsResponse, error) { + path := versioned(zoneRecordPath(accountID, zoneID, 0)) + recordsResponse := &ZoneRecordsResponse{} + + path, err := addURLQueryOptions(path, options) + if err != nil { + return nil, err + } + + resp, err := s.client.get(path, recordsResponse) + if err != nil { + return nil, err + } + + recordsResponse.HttpResponse = resp + return recordsResponse, nil +} + +// CreateRecord creates a zone record. +// +// See https://developer.dnsimple.com/v2/zones/#create +func (s *ZonesService) CreateRecord(accountID string, zoneID string, recordAttributes ZoneRecord) (*ZoneRecordResponse, error) { + path := versioned(zoneRecordPath(accountID, zoneID, 0)) + recordResponse := &ZoneRecordResponse{} + + resp, err := s.client.post(path, recordAttributes, recordResponse) + if err != nil { + return nil, err + } + + recordResponse.HttpResponse = resp + return recordResponse, nil +} + +// GetRecord fetches a zone record. +// +// See https://developer.dnsimple.com/v2/zones/#get +func (s *ZonesService) GetRecord(accountID string, zoneID string, recordID int) (*ZoneRecordResponse, error) { + path := versioned(zoneRecordPath(accountID, zoneID, recordID)) + recordResponse := &ZoneRecordResponse{} + + resp, err := s.client.get(path, recordResponse) + if err != nil { + return nil, err + } + + recordResponse.HttpResponse = resp + return recordResponse, nil +} + +// UpdateRecord updates a zone record. +// +// See https://developer.dnsimple.com/v2/zones/#update +func (s *ZonesService) UpdateRecord(accountID string, zoneID string, recordID int, recordAttributes ZoneRecord) (*ZoneRecordResponse, error) { + path := versioned(zoneRecordPath(accountID, zoneID, recordID)) + recordResponse := &ZoneRecordResponse{} + resp, err := s.client.patch(path, recordAttributes, recordResponse) + + if err != nil { + return nil, err + } + + recordResponse.HttpResponse = resp + return recordResponse, nil +} + +// DeleteRecord PERMANENTLY deletes a zone record from the zone. +// +// See https://developer.dnsimple.com/v2/zones/#delete +func (s *ZonesService) DeleteRecord(accountID string, zoneID string, recordID int) (*ZoneRecordResponse, error) { + path := versioned(zoneRecordPath(accountID, zoneID, recordID)) + recordResponse := &ZoneRecordResponse{} + + resp, err := s.client.delete(path, nil, nil) + if err != nil { + return nil, err + } + + recordResponse.HttpResponse = resp + return recordResponse, nil +} diff --git a/vendor/vendor.json b/vendor/vendor.json index 66ba5f6..81b5075 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -2,6 +2,12 @@ "comment": "", "ignore": "test", "package": [ + { + "checksumSHA1": "Txg0JnycL8J24q8M+3bMuQPikR4=", + "path": "github.com/dnsimple/dnsimple-go/dnsimple", + "revision": "c5e18853275d3022c35e13fd9600048320f1d84f", + "revisionTime": "2016-11-22T10:27:37Z" + }, { "checksumSHA1": "ynJSWoF6v+3zMnh9R0QmmG6iGV8=", "path": "github.com/pkg/errors",