vegadns2client

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

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

Go to latest
Published: Apr 18, 2018 License: Apache-2.0 Imports: 9 Imported by: 99

README

vegadns2client

vegadns2client is a go client for VegaDNS-API. This is an incomplete client, initially intended to support lego.

Example Usage

An example of looking up the auth zone for a hostname:
package main

import (
    "fmt"
    "github.com/opendns/vegadns2client"
)

func main() {
    v := vegadns2client.NewVegaDNSClient("http://localhost:5000")
    v.APIKey = "mykey"
    v.APISecret = "mysecret"

    authZone, domainID, err := v.GetAuthZone("example.com")
    fmt.Println(authZone, domainID, err)
}

Which will output the following:

2018/02/22 16:11:48 tmpHostname for i = 1: example.com
2018/02/22 16:11:48 {ok 1 [{active example.com 2 0}]}
2018/02/22 16:11:48 Found zone: example.com
	Shortened to foobar.com
foobar.com <nil>
An example of creating and deleting a TXT record
package main

import (
    "fmt"
    "github.com/opendns/vegadns2client"
)

func main() {
    v := vegadns2client.NewVegaDNSClient("http://localhost:5000")
    v.APIKey = "mykey"
    v.APISecret = "mysecret"

    authZone, domainID, err := v.GetAuthZone("example.com")
    fmt.Println(authZone, domainID, err)

    result := v.CreateTXT(domainID, "_acme-challenge.example.com", "test challenge", 25)
    fmt.Println(result)

    recordID, err := v.GetRecordID(domainID, "_acme-challenge.example.com", "TXT")
    fmt.Println(recordID, err)

    err = v.DeleteRecord(recordID)
    fmt.Println(err)
}

Which will output the following:

2018/02/26 14:59:53 tmpHostname for i = 1: example.com
2018/02/26 14:59:53 {ok 1 [{active example.com 1 0}]}
2018/02/26 14:59:53 Found zone: example.com
	Shortened to example.com
example.com 1 <nil>
<nil>
3 <nil>
<nil>

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Domain

type Domain struct {
	Status   string `json:"status"`
	Domain   string `json:"domain"`
	DomainID int    `json:"domain_id"`
	OwnerID  int    `json:"owner_id"`
}

Domain - struct containing a domain object

type DomainResponse

type DomainResponse struct {
	Status  string   `json:"status"`
	Total   int      `json:"total_domains"`
	Domains []Domain `json:"domains"`
}

DomainResponse - api response of a domain list

type Record

type Record struct {
	Name       string `json:"name"`
	Value      string `json:"value"`
	RecordType string `json:"record_type"`
	TTL        int    `json:"ttl"`
	RecordID   int    `json:"record_id"`
	LocationID string `json:"location_id"`
	DomainID   int    `json:"domain_id"`
}

Record - struct representing a Record object

type RecordsResponse

type RecordsResponse struct {
	Status  string   `json:"status"`
	Total   int      `json:"total_records"`
	Domain  Domain   `json:"domain"`
	Records []Record `json:"records"`
}

RecordsResponse - api response list of records

type Token

type Token struct {
	Token     string `json:"access_token"`
	TokenType string `json:"token_type"`
	ExpiresIn int    `json:"expires_in"`
	ExpiresAt time.Time
}

Token - struct to hold token information

type VegaDNSClient

type VegaDNSClient struct {
	User      string
	Pass      string
	APIKey    string
	APISecret string
	// contains filtered or unexported fields
}

VegaDNSClient - Struct for holding VegaDNSClient specific attributes

func NewVegaDNSClient

func NewVegaDNSClient(url string) VegaDNSClient

NewVegaDNSClient - helper to instantiate a client Input: url string Output: VegaDNSClient

func (*VegaDNSClient) CreateTXT

func (vega *VegaDNSClient) CreateTXT(domainID int, fqdn string, value string, ttl int) error

CreateTXT - Creates a TXT record Input: domainID, fqdn, value, ttl Output: nil or error

func (*VegaDNSClient) DeleteRecord

func (vega *VegaDNSClient) DeleteRecord(recordID int) error

DeleteRecord - deletes a record by id Input: recordID Output: nil or error

func (*VegaDNSClient) GetAuthZone

func (vega *VegaDNSClient) GetAuthZone(fqdn string) (string, int, error)

GetAuthZone retrieves the closest match to a given domain. Example: Given an argument "a.b.c.d.e", and a VegaDNS hosted domain of "c.d.e", GetClosestMatchingDomain will return "c.d.e".

func (*VegaDNSClient) GetDomainID

func (vega *VegaDNSClient) GetDomainID(domain string) (int, error)

GetDomainID - returns the id for a domain Input: domain Output: int, err

func (*VegaDNSClient) GetRecordID

func (vega *VegaDNSClient) GetRecordID(domainID int, record string, recordType string) (int, error)

GetRecordID - helper to get the id of a record Input: domainID, record, recordType Output: int

func (*VegaDNSClient) Send

func (vega *VegaDNSClient) Send(method string, endpoint string, params map[string]string) (*http.Response, error)

Send - Central place for sending requests Input: method, endpoint, params Output: *http.Response

Jump to

Keyboard shortcuts

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