dns

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package dns an SDK for the Hetzner DNS API.

Read the API docs over on https://dns.hetzner.com/api-docs.

Example:

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/jobstoit/hetzner-dns-go/dns"
)

func main() {
	client := dns.NewClient(dns.WithToken("token"))

	record, _, err := client.Record.GetByID(context.Background(), "randomid")
	if err != nil {
		log.Fatalf("error retrieving record: %v\n", err)
	}

	fmt.Printf("record of type: '%s' found with value: %s", record.Type, record.Value)
}

Index

Constants

View Source
const Endpoint = "https://dns.hetzner.com/api/v1"

Endpoint is the base URL of the API.

View Source
const UserAgent = "hetzner-dns/" + Version
View Source
const Version = "v0.1.0"

Version of the SDK

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Zone          *ZoneClient
	Record        *RecordClient
	PrimaryServer *PrimaryServerClient
	// contains filtered or unexported fields
}

Client is the client for the Hetzner DNS API.

func NewClient

func NewClient(options ...ClientOption) *Client

NewClient creates a new client.

func (*Client) Do

func (c *Client) Do(r *http.Request, v interface{}) (*Response, error)

Do performs an HTTP request against the API.

func (*Client) NewRequest

func (c *Client) NewRequest(ctx context.Context, method, path string, body io.Reader) (*http.Request, error)

NewRequest creates an HTTP request against the API. The returned request is assigned with ctx and has all necessary headers set (auth, user agent, etc.).

type ClientOption

type ClientOption func(*Client)

ClientOption is used to configure a client.

func WithApplication

func WithApplication(name, version string) ClientOption

WithApplication configures a Client with the given application name and application version. The version may be blank. Programs are encouraged to at least set an application name.

func WithDebugWriter

func WithDebugWriter(wr io.Writer) ClientOption

WithDebugWriter configures the client to use the given debug writer.

func WithEndpoint

func WithEndpoint(url string) ClientOption

WithEndpoint configures the client to use a different endpoint.

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) ClientOption

WithHTTPClient configures a Client to perform HTTP requests with httpClient.

func WithToken

func WithToken(token string) ClientOption

WithToken configures a client to use the specified token.

type ListOpts

type ListOpts struct {
	Page    int
	PerPage int
}

ListOpts specifies options for listing resources

type Meta

type Meta struct {
	Pagination *Pagination
}

Meta represents meta inforation included in the API response.

type Pagination

type Pagination struct {
	LastPage     int
	Page         int
	PerPage      int
	TotalEntries int
}

Pagination represents pagination meta information.

func PaginationFromSchema

func PaginationFromSchema(s schema.MetaPagination) Pagination

PaginationFromSchema converts a schema.MetaPagination to a Pagination.

type PrimaryServer

type PrimaryServer struct {
	ID       string
	Port     int
	Created  schema.HdnsTime
	Modified schema.HdnsTime
	Zone     *Zone
	Address  string
}

PrimaryServer represents a primary server in the Hetzner DNS API.

func PrimaryServerFromSchema

func PrimaryServerFromSchema(s schema.PrimaryServer) *PrimaryServer

PrimaryServerFromSchema converts a schema.PrimaryServer to a PrimaryServer

type PrimaryServerClient

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

RecordClient is a client for primary server API.

func (PrimaryServerClient) Create

Create creates a new primary server record.

func (PrimaryServerClient) Delete

func (c PrimaryServerClient) Delete(ctx context.Context, server *PrimaryServer) (*Response, error)

Delete deletes a primary server record.

func (PrimaryServerClient) GetByID

GetByID returns the PrimaryServer with the given id.

func (PrimaryServerClient) List

List returns all primary servers with the given parameters.

func (PrimaryServerClient) Update

Update updates a primary server record.

type PrimaryServerCreateOpts

type PrimaryServerCreateOpts struct {
	Address string
	Port    int
	ZoneID  string
}

PrimaryServerCreateOpts specifies options for creating a primary server.

type PrimaryServerListOpts

type PrimaryServerListOpts struct {
	ZoneID string
}

PrimaryServerListOpts specifies options for listing primary servers

type PrimaryServerUpdateOpts

type PrimaryServerUpdateOpts struct {
	Address string
	Port    int
	ZoneID  string
}

PrimaryServerUpdateOpts specifies options for updating a primary server.

type Record

type Record struct {
	Type     RecordType
	ID       string
	Created  schema.HdnsTime
	Modified schema.HdnsTime
	Zone     *Zone
	Name     string
	Value    string
	Ttl      int
}

Record represents a record in the Hetzner DNS.

func RecordFromSchema

func RecordFromSchema(s schema.Record) *Record

RecordFromSchema convers a schema.Record to Record

type RecordBulkCreateResponse

type RecordBulkCreateResponse struct {
	Records        []*Record
	ValidRecords   []*RecordEntry
	InvalidRecords []*RecordEntry
}

RecordBulkCreateResponse is returned when creating records in bulk.

type RecordBulkUpdateOpts

type RecordBulkUpdateOpts struct {
	ID    string
	Type  RecordType
	Zone  *Zone
	Name  string
	Value string
	Ttl   *int
}

RecordBulkUpdateOpts specifies options for a bulk record update entry

type RecordBulkUpdateResponse

type RecordBulkUpdateResponse struct {
	Records       []*Record
	FailedRecords []*RecordEntry
}

RecordBulkUpdateResponse is returned when creating records in bulk.

type RecordClient

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

RecordClient is a client for records API.

func (RecordClient) BulkCreate

BulkCreate creates multiple records.

func (RecordClient) BulkUpdate

BulkUpdate updates multiple records.

func (RecordClient) Create

func (c RecordClient) Create(ctx context.Context, opts RecordCreateOpts) (*Record, *Response, error)

Create creates a new record.

func (RecordClient) Delete

func (c RecordClient) Delete(ctx context.Context, rec *Record) (*Response, error)

Delete deletes a record.

func (RecordClient) GetByID

func (c RecordClient) GetByID(ctx context.Context, id string) (*Record, *Response, error)

GetByID returns a record with the given id.

func (RecordClient) List

func (c RecordClient) List(ctx context.Context, opts RecordListOpts) ([]*Record, *Response, error)

List returns all records with the given parameters.

func (RecordClient) Update

func (c RecordClient) Update(ctx context.Context, rec *Record, opts RecordUpdateOpts) (*Record, *Response, error)

Update updates a record.

type RecordCreateOpts

type RecordCreateOpts struct {
	Name  string
	Ttl   *int
	Type  RecordType
	Value string
	Zone  *Zone
}

RecordCreateOpts specifies options for creating a record.

type RecordEntry

type RecordEntry struct {
	Type   RecordType
	ZoneID string
	Name   string
	Value  string
	Ttl    *int
}

RecordEntry represents a record entry used for verification and updates.

func RecordEntryFromSchema

func RecordEntryFromSchema(s schema.RecordBulkEntry) *RecordEntry

RecordEntryFromSchema converts a schema.RecordCreateRequest to a RecordCreateOpts

type RecordListOpts

type RecordListOpts struct {
	ListOpts
	ZoneID string
}

RecordListOpts specifies options for listing records

type RecordType

type RecordType string
const (
	RecordTypeA     RecordType = "A"
	RecordTypeAAAA  RecordType = "AAAA"
	RecordTypePTR   RecordType = "PTR"
	RecordTypeNS    RecordType = "NS"
	RecordTypeMX    RecordType = "MX"
	RecordTypeCNAME RecordType = "CNAME"
	RecordTypeRP    RecordType = "RP"
	RecordTypeTXT   RecordType = "TXT"
	RecordTypeSOA   RecordType = "SOA"
	RecordTypeHINFO RecordType = "HINFO"
	RecordTypeSRV   RecordType = "SRV"
	RecordTypeDANE  RecordType = "DANE"
	RecordTypeTLSA  RecordType = "TLSA"
	RecordTypeDS    RecordType = "DS"
	RecordTypeCAA   RecordType = "CAA"
)

type RecordUpdateOpts

type RecordUpdateOpts struct {
	Name  string
	Ttl   *int
	Type  RecordType
	Value string
	Zone  *Zone
}

RecordUpdateOpts specifies options for creating a record.

type Response

type Response struct {
	*http.Response
	Meta Meta
}

Response represents a response from the API. It embeds http.Response.

type TxtVerification

type TxtVerification struct {
	Name  string
	Token string
}

TxtVerification represents a txt verification of a zone.

func TxtVerificationFromSchema

func TxtVerificationFromSchema(s schema.TxtVerification) *TxtVerification

TxtVerificationFromSchema converts schema.TxtVerification to TxtVerification

type ValidatedZoneFile

type ValidatedZoneFile struct {
	PassedRecords int
	ValidRecords  []*Record
}

ValidatedZoneFile is returned when validating a zone file.

func ValidateZoneFileFromSchema

func ValidateZoneFileFromSchema(s schema.ValidateZoneFileResponse) *ValidatedZoneFile

ValidateZoneFileFromSchema converts a schema.ValidateZoneFileResponse to a ValidatedZoneFile.

type Zone

type Zone struct {
	ID              string
	Created         schema.HdnsTime
	Modified        schema.HdnsTime
	LegacyDNSHost   string
	LegacyNS        []string
	Name            string
	NS              []string
	Owner           string
	Paused          bool
	Permission      string
	Project         string
	Registrar       string
	Status          ZoneStatus
	Ttl             int
	Verified        schema.HdnsTime
	RecordsCount    int
	IsSecondaryDNS  bool
	TxtVerification *TxtVerification
}

Zone represents a zone in Hetzner DNS.

func ZoneFromSchema

func ZoneFromSchema(s schema.Zone) *Zone

ZoneFromSchema converts schema.Zone to a Zone.

type ZoneClient

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

ZoneClient is a client for zones API.

func (ZoneClient) Create

func (c ZoneClient) Create(ctx context.Context, opts ZoneCreateOpts) (*Zone, *Response, error)

Create creates a new zone.

func (ZoneClient) Delete

func (c ZoneClient) Delete(ctx context.Context, zone *Zone) (*Response, error)

Delete deletes a zone.

func (ZoneClient) Export

func (c ZoneClient) Export(ctx context.Context, zone *Zone) (io.Reader, *Response, error)

Export exports a zone in text/plain format.

func (ZoneClient) GetByID

func (c ZoneClient) GetByID(ctx context.Context, id string) (*Zone, *Response, error)

GetByID returns the zone with the given id.

func (ZoneClient) Import

func (c ZoneClient) Import(ctx context.Context, zone *Zone, file io.Reader) (*Zone, *Response, error)

Import imports a zone file in text/plain format.

func (ZoneClient) List

func (c ZoneClient) List(ctx context.Context, opts ZoneListOpts) ([]*Zone, *Response, error)

List returns all zones with the given parameters.

func (ZoneClient) Update

func (c ZoneClient) Update(ctx context.Context, zone *Zone, opts ZoneUpdateOpts) (*Zone, *Response, error)

Update updates a zone.

func (ZoneClient) ValidateFile

func (c ZoneClient) ValidateFile(ctx context.Context, file io.Reader) (*ValidatedZoneFile, *Response, error)

ValidateFile validates a zone file.

type ZoneCreateOpts

type ZoneCreateOpts struct {
	Name string
	Ttl  *int
}

ZoneCreateOpts specifies options for creating a new zone.

func (ZoneCreateOpts) Validate

func (o ZoneCreateOpts) Validate() error

Validate checks if the options are valid.

type ZoneListOpts

type ZoneListOpts struct {
	ListOpts
	Name       string
	SearchName string
}

ZoneListOptions specifies options for listing zones.

type ZoneStatus

type ZoneStatus string
const (
	ZoneStatusVerified ZoneStatus = `verified`
	ZoneStatusFailed   ZoneStatus = `failed`
	ZoneStatusPending  ZoneStatus = `pending`
)

type ZoneUpdateOpts

type ZoneUpdateOpts struct {
	Name string
	Ttl  *int
}

ZoneUpdateOpts specifies options for updating a zone.

func (ZoneUpdateOpts) Validate

func (o ZoneUpdateOpts) Validate() error

Validate checks if the options are valid.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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