deens

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2016 License: BSD-3-Clause Imports: 5 Imported by: 2 modules, 2 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Dee NS

A go-library for updating DNS records

github.com/andreaskoch/dee-ns is a golang library for updating subdomain records that are managed by DNSimple.

Build Status

Usage

Create a new DNS client instance and fetch all domain names:

import (
	"fmt"
	"os"
	"github.com/andreaskoch/dee-ns"
)

func main() {
	// assemble the API credentials
	credentials := deens.APICredentials{"john.doe@example.com", "ApItOken"}

	// create a new DNS client
	dnsClient, clientError := deens.NewDNSClient(credentials)
	if clientError != nil {
		fmt.Fprintf(os.Stderr, "Unable to create DNS client: %s", clientError.Error())
		os.Exit(1)
	}

	// fetch all available domains
	domains, domainsError := dnsClient.GetDomains()
	if domainsError != nil {
		fmt.Fprintf(os.Stderr, "Unable to fetch domains: %s", domainsError.Error())
		os.Exit(1)
	}

	// print domain names to stdout
	for _, domain := range domains {
		fmt.Fprintf(os.Stdout, "%s\n", domain.Name)
	}
}

Create a new DNS info provider:

import (
	"fmt"
	"os"
	"github.com/andreaskoch/dee-ns"
)

func main() {

	// create a DNS client
	credentials := APICredentials{"john.doe@example.com", "ApItOken"}
	dnsClient, clientError := deens.NewDNSClient(credentials)
	if clientError != nil {
		fmt.Fprintf(os.Stderr, "Unable to create DNS client: %s", clientError.Error())
		os.Exit(1)
	}

	// create a new DNS info provider instance
	infoProvider := deens.NewDNSInfoProvider(dnsClient)

	// get all domain names
	domainNames, domainNamesError := infoProvider.GetDomainNames()
	if domainNamesError != nil {
		fmt.Fprintf(os.Stderr, "Unable to fetch domain names: %s", domainNamesError.Error())
		os.Exit(1)
	}

	// print a list all domain names
	for _, domainName := range domainNames {
		fmt.Fprintf(os.Stdout, "%s\n", domainName)
	}
}

Create a new DNS editor instance:

import (
	"fmt"
	"net"
	"os"
)

func main() {

	// create a DNS client
	credentials := APICredentials{"john.doe@example.com", "ApItOken"}
	dnsClient, clientError := NewDNSClient(credentials)
	if clientError != nil {
		fmt.Fprintf(os.Stderr, "Unable to create DNS client: %s", clientError.Error())
		os.Exit(1)
	}

	// create a new DNS info provider instance
	dnsInfoProvider := NewDNSInfoProvider(dnsClient)

	// create a new DNS editor instance
	dnsEditor := NewDNSEditor(dnsClient, dnsInfoProvider)

	// create an DNS A record for www.example.com pointing to 127.0.0.1
	domain := "example.com"
	subDomainName := "www"
	timeToLive := 600
	ip := net.ParseIP("127.0.0.1")

	createSubdomainError := dnsEditor.CreateSubdomain(domain, subDomainName, timeToLive, ip)
	if createSubdomainError != nil {
		fmt.Fprintf(os.Stderr, "Failed to create subdomain %s.%s: %s", subDomainName, domain, clientError.Error())
		os.Exit(1)
	}

	fmt.Fprintf(os.Stdout, "Created subdomain %s.%s", subDomainName, domain)
}

Dependencies

dee-ns uses the github.com/pearkes/dnsimple library for communicating with the DNSimple API.

Contribute

If you find a bug or if you want to add or improve some feature please create an issue or send me a pull requests. All contributions are welcome.

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APICredentials

type APICredentials struct {
	// Email is the E-Mail address that is used for accessing the DNSimple API
	Email string

	// Token is the API token used for accessing the DNSimple API
	Token string
}

APICredentials contains the credentials for accessing the DNSimple API.

func NewAPICredentials

func NewAPICredentials(email, token string) (APICredentials, error)

NewAPICredentials creates a new credentials model from the given e-mail address and API token. If the given parameters are invalid an error will be returned.

type CredentialDeleter

type CredentialDeleter interface {
	// DeleteCredentials deletes any saved credentials.
	DeleteCredentials() error
}

CredentialDeleter deletes credentials.

type CredentialProvider

type CredentialProvider interface {
	// GetCredentials returns any stored credentials if there are any.
	// Otherwise GetCredentials will return an error.
	GetCredentials() (APICredentials, error)
}

CredentialProvider returns credentials.

type CredentialSaver

type CredentialSaver interface {
	// SaveCredentials saves the given credentials.
	SaveCredentials(credentials APICredentials) error
}

CredentialSaver persists credentials.

type CredentialStore

type CredentialStore interface {
	CredentialProvider
	CredentialSaver
	CredentialDeleter
}

CredentialStore provides functions for reading and persisting APICredentials.

type DNSClient

type DNSClient interface {
	// UpdateRecord update the DNS record with the given id.
	UpdateRecord(domain string, id string, opts *dnsimple.ChangeRecord) (string, error)

	// GetRecords returns all DNS records for the given domain.
	GetRecords(domain string) ([]dnsimple.Record, error)

	// GetDomains returns a list of domain.
	GetDomains() ([]dnsimple.Domain, error)

	// CreateRecord creates a new DNS record for the given domain.
	CreateRecord(domain string, opts *dnsimple.ChangeRecord) (string, error)

	// DestroyRecord deletes the DNS record with the given id.
	DestroyRecord(domain string, id string) error
}

DNSClient provides functions for updating DNS records.

func NewDNSClient

func NewDNSClient(credentials APICredentials) (DNSClient, error)

NewDNSClient creates a new DNS client instance for the given credentials.

Example

Create a new DNS client instance and fetch all domain names.

// assemble the API credentials
credentials := APICredentials{"john.doe@example.com", "ApItOken"}

// create a new DNS client
dnsClient, clientError := NewDNSClient(credentials)
if clientError != nil {
	fmt.Fprintf(os.Stderr, "Unable to create DNS client: %s", clientError.Error())
	os.Exit(1)
}

// fetch all available domains
domains, domainsError := dnsClient.GetDomains()
if domainsError != nil {
	fmt.Fprintf(os.Stderr, "Unable to fetch domains: %s", domainsError.Error())
	os.Exit(1)
}

// print domain names to stdout
for _, domain := range domains {
	fmt.Fprintf(os.Stdout, "%s\n", domain.Name)
}

type DNSEditor

type DNSEditor struct {
	// contains filtered or unexported fields
}

DNSEditor updates DNSimple domain records.

func (*DNSEditor) CreateSubdomain

func (editor *DNSEditor) CreateSubdomain(domain, subdomain string, timeToLive int, ip net.IP) error

CreateSubdomain creates an address record for the given domain

func (*DNSEditor) DeleteSubdomain

func (editor *DNSEditor) DeleteSubdomain(domain, subdomain string, recordType string) error

DeleteSubdomain deletes the address record of the given domain

func (*DNSEditor) UpdateSubdomain

func (editor *DNSEditor) UpdateSubdomain(domain, subdomain string, ip net.IP) error

UpdateSubdomain updates the IP address of the given domain/subdomain.

type DNSInfoProvider

type DNSInfoProvider interface {

	// GetDomainNames returns a list of domain names.
	// Returns an error if the domain names cannot be fetched.
	GetDomainNames() ([]string, error)

	// GetDomainRecords returns all DNS records for the given domain.
	// Returns an error of the DNS records cannot be fetched or the
	// given domain was not found.
	GetDomainRecords(domain string) ([]dnsimple.Record, error)

	// GetSubdomainRecord returns the DNS record for the given domain, subdomain and record type.
	// Returns an error if no DNS record was found.
	GetSubdomainRecord(domain, subdomain, recordType string) (dnsimple.Record, error)

	// GetSubdomainRecords returns a list of all available DNS records for the
	// given domain and subdomain.
	GetSubdomainRecords(domain, subdomain string) ([]dnsimple.Record, error)
}

The DNSInfoProvider interface offer DNS info functions.

func NewDNSInfoProvider

func NewDNSInfoProvider(client DNSClient) DNSInfoProvider

NewDNSInfoProvider creates a new DNS info provider instance.

Example

Create a new DNS info provider.

// create a DNS client
credentials := APICredentials{"john.doe@example.com", "ApItOken"}
dnsClient, clientError := NewDNSClient(credentials)
if clientError != nil {
	fmt.Fprintf(os.Stderr, "Unable to create DNS client: %s", clientError.Error())
	os.Exit(1)
}

// create a new DNS info provider instance
dnsInfoProvider := NewDNSInfoProvider(dnsClient)

// get all domain names
domainNames, domainNamesError := dnsInfoProvider.GetDomainNames()
if domainNamesError != nil {
	fmt.Fprintf(os.Stderr, "Unable to fetch domain names: %s", domainNamesError.Error())
	os.Exit(1)
}

// print a list all domain names
for _, domainName := range domainNames {
	fmt.Fprintf(os.Stdout, "%s\n", domainName)
}

type DNSRecordCreator

type DNSRecordCreator interface {

	// CreateSubdomain creates a new subdomain address record.
	CreateSubdomain(domain, subDomainName string, timeToLive int, ip net.IP) error
}

The DNSRecordCreator interface offers functions for creating domain records.

type DNSRecordDeleter

type DNSRecordDeleter interface {

	// DeleteSubdomain removes subdomain address record of the given type.
	DeleteSubdomain(domain, subDomainName string, recordType string) error
}

The DNSRecordDeleter interface offers functions for creating domain records.

type DNSRecordEditor

type DNSRecordEditor interface {
	DNSRecordCreator
	DNSRecordUpdater
	DNSRecordDeleter
}

The DNSRecordEditor interface provides functions for editing DNS records.

func NewDNSEditor

func NewDNSEditor(client DNSClient, infoProvider DNSInfoProvider) DNSRecordEditor

NewDNSEditor creates an new DNSRecordEditor instance.

Example

Create a new DNS editor instance.

// create a DNS client
credentials := APICredentials{"john.doe@example.com", "ApItOken"}
dnsClient, clientError := NewDNSClient(credentials)
if clientError != nil {
	fmt.Fprintf(os.Stderr, "Unable to create DNS client: %s", clientError.Error())
	os.Exit(1)
}

// create a new DNS info provider instance
dnsInfoProvider := NewDNSInfoProvider(dnsClient)

// create a new DNS editor instance
dnsEditor := NewDNSEditor(dnsClient, dnsInfoProvider)

// create an DNS A record for www.example.com pointing to 127.0.0.1
domain := "example.com"
subDomainName := "www"
timeToLive := 600
ip := net.ParseIP("127.0.0.1")

createSubdomainError := dnsEditor.CreateSubdomain(domain, subDomainName, timeToLive, ip)
if createSubdomainError != nil {
	fmt.Fprintf(os.Stderr, "Failed to create subdomain %s.%s: %s", subDomainName, domain, clientError.Error())
	os.Exit(1)
}

fmt.Fprintf(os.Stdout, "Created subdomain %s.%s", subDomainName, domain)

type DNSRecordUpdater

type DNSRecordUpdater interface {

	// UpdateSubdomain sets ip address of the given subdomain.
	UpdateSubdomain(domain, subDomainName string, ip net.IP) error
}

The DNSRecordUpdater interface offers functions for updating domain records.

Jump to

Keyboard shortcuts

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