hclouddns

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

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

Go to latest
Published: Dec 13, 2020 License: GPL-3.0 Imports: 7 Imported by: 1

README

Hetzner DNS golang library

I made this library to interact with Hetzner DNS API in most easy way. Hopefully in future it will be used for Hetzner external-dns provider. Check out example directory and API_help.md.

Get your own token on Hetzner DNS and place it to token variable and run code

token := "jcB2UywP9XtZGhvhSHpH5m"
client := hclouddns.New(token)

zones, err := client.GetZones(hclouddns.HCloudGetZonesParams{})
if err != nil {
	log.Fatalln(err)
}

for _, v := range zones.Zones {
	fmt.Printf("Zone %v:\n\tRecords count: %v\n\tStatus: %v\n\n", v.Name, v.RecordsCount, v.Status)
}

At this moment library supports all API requests. If you found some bug mail me or register here and create issue.


Copyright by Vladimir Smagin (21h) 2020
http://blindage.org email: 21h@blindage.org
Project page: https://git.blindage.org/21h/hcloud-dns

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HCloudAnswerCreateRecords

type HCloudAnswerCreateRecords struct {
	Records        []HCloudRecord `json:"records,omitempty"`
	ValidRecords   []HCloudRecord `json:"valid_records,omitempty"`
	InvalidRecords []HCloudRecord `json:"invalid_records,omitempty"`
	Error          HCloudError
}

type HCloudAnswerDeleteRecord

type HCloudAnswerDeleteRecord struct {
	Error HCloudError
}

type HCloudAnswerDeleteZone

type HCloudAnswerDeleteZone struct {
	Error HCloudError
}

type HCloudAnswerError

type HCloudAnswerError struct {
	Error HCloudError `json:"error,omitempty"`
}

sometime can be returned HCloudError

type HCloudAnswerErrorString

type HCloudAnswerErrorString struct {
	Error string `json:"error,omitempty"`
}

or plain string

type HCloudAnswerGetRecord

type HCloudAnswerGetRecord struct {
	Record HCloudRecord `json:"record,omitempty"`
	Error  HCloudError
}

type HCloudAnswerGetRecords

type HCloudAnswerGetRecords struct {
	Records []HCloudRecord `json:"records,omitempty"`
	Meta    HCloudMeta     `json:"meta,omitempty"`
	Error   HCloudError
}

type HCloudAnswerGetZone

type HCloudAnswerGetZone struct {
	Zone  HCloudZone  `json:"zone,omitempty"`
	Error HCloudError `json:",omitempty"`
}

type HCloudAnswerGetZonePlainText

type HCloudAnswerGetZonePlainText struct {
	ZonePlainText string `json:"zone,omitempty"`
	Error         HCloudError
}

type HCloudAnswerGetZones

type HCloudAnswerGetZones struct {
	Zones []HCloudZone `json:"zones,omitempty"`
	Meta  HCloudMeta   `json:"meta,omitempty"`
	Error HCloudError
}

type HCloudAnswerUpdateRecords

type HCloudAnswerUpdateRecords struct {
	Records        []HCloudRecord `json:"records,omitempty"`
	InvalidRecords []HCloudRecord `json:"failed_records,omitempty"`
	Error          HCloudError
}

type HCloudAnswerZoneValidate

type HCloudAnswerZoneValidate struct {
	ParsedRecords int          `json:"parsed_records,omitempty"`
	ValidRecords  []HCloudZone `json:"valid_records,omitempty"`
	Error         HCloudError
}

type HCloudClient

type HCloudClient struct {
	Token     string `yaml:"token"`
	APIserver string `yaml:"apiserver"`
}

func (*HCloudClient) CreateRecord

func (d *HCloudClient) CreateRecord(record HCloudRecord) (HCloudAnswerGetRecord, error)

CreateRecord creates new single record. Accepts HCloudRecord with record to create, of cource no ID. Returns HCloudAnswerGetRecord with HCloudRecord and error.

func (*HCloudClient) CreateRecordBulk

func (d *HCloudClient) CreateRecordBulk(record []HCloudRecord) (HCloudAnswerCreateRecords, error)

CreateRecordBulk creates many records at once. Accepts array of HCloudRecord, converts it to json and makes POST to Hetzner. Returns HCloudAnswerCreateRecords with arrays of HCloudRecord with whole list, valid and invalid, error.

func (*HCloudClient) CreateZone

func (d *HCloudClient) CreateZone(zone HCloudZone) (HCloudAnswerGetZone, error)

CreateZone creates new single zone. Accepts HCloudZone with record to create, of cource no ID. Returns HCloudAnswerGetZone with HCloudZone and error.

func (*HCloudClient) DeleteRecord

func (d *HCloudClient) DeleteRecord(ID string) (HCloudAnswerDeleteRecord, error)

DeleteRecord remove record by ID. Accepts single ID string. Returns HCloudAnswerDeleteRecord and error.

func (*HCloudClient) DeleteZone

func (d *HCloudClient) DeleteZone(ID string) (HCloudAnswerDeleteZone, error)

DeleteZone remove zone by ID. Accepts single ID string. Returns HCloudAnswerDeleteZone with error.

func (*HCloudClient) ExportZoneToString

func (d *HCloudClient) ExportZoneToString(zoneID string) (HCloudAnswerGetZonePlainText, error)

ExportZoneToString exports single zone from imported text. Accepts ID and zonePlainText strings. Returns HCloudAnswerGetZonePlainText with HCloudZone and error.

func (*HCloudClient) GetRecord

func (d *HCloudClient) GetRecord(ID string) (HCloudAnswerGetRecord, error)

GetRecord retrieve one single record by ID. Accepts single ID of record. Returns HCloudAnswerGetRecord with HCloudRecord and error.

func (*HCloudClient) GetRecords

GetRecords retrieve all records of user. Accepts HCloudGetRecordsParams struct Returns HCloudAnswerGetRecords with array of HCloudRecord, Meta and error.

func (*HCloudClient) GetZone

func (d *HCloudClient) GetZone(ID string) (HCloudAnswerGetZone, error)

GetZone retrieve one single zone by ID. Accepts zone ID string. Returns HCloudAnswerGetZone with HCloudZone and error

func (*HCloudClient) GetZones

GetZones retrieve all zones of user. Accepts exact name as string, search name with partial name. Returns HCloudAnswerGetZones with array of HCloudZone, Meta and error.

func (*HCloudClient) ImportZoneString

func (d *HCloudClient) ImportZoneString(zoneID string, zonePlainText string) (HCloudAnswerGetZone, error)

ImportZoneString imports single zone from imported text. Accepts ID and zonePlainText strings. Returns HCloudAnswerGetZone with HCloudZone and error.

func (*HCloudClient) UpdateRecord

func (d *HCloudClient) UpdateRecord(record HCloudRecord) (HCloudAnswerGetRecord, error)

UpdateRecord makes update of single record by ID. Accepts HCloudRecord with fullfilled fields. Returns HCloudAnswerGetRecord with HCloudRecord and error.

func (*HCloudClient) UpdateRecordBulk

func (d *HCloudClient) UpdateRecordBulk(record []HCloudRecord) (HCloudAnswerUpdateRecords, error)

UpdateRecordBulk updates many records at once. Accepts array of HCloudRecord, converting to json and makes PUT to Hetzner. Returns HCloudAnswerUpdateRecords with arrays of HCloudRecord with updated and failed, error.

func (*HCloudClient) UpdateZone

func (d *HCloudClient) UpdateZone(zone HCloudZone) (HCloudAnswerGetZone, error)

UpdateZone makes update of single zone by ID. Accepts HCloudZone with fullfilled fields. Returns HCloudAnswerGetZone with HCloudZone and error.

func (*HCloudClient) ValidateZoneString

func (d *HCloudClient) ValidateZoneString(zonePlainText string) (HCloudAnswerZoneValidate, error)

ValidateZoneString validate single zone from imported text. Accepts ID and zonePlainText strings. Returns HCloudAnswerZoneValidate with HCloudZone and error.

type HCloudClientAdapter

type HCloudClientAdapter interface {
	GetZone(ID string) (HCloudAnswerGetZone, error)
	GetZones(params HCloudGetZonesParams) (HCloudAnswerGetZones, error)
	UpdateZone(zone HCloudZone) (HCloudAnswerGetZone, error)
	DeleteZone(ID string) (HCloudAnswerDeleteZone, error)
	CreateZone(zone HCloudZone) (HCloudAnswerGetZone, error)
	ImportZoneString(zoneID string, zonePlainText string) (HCloudAnswerGetZone, error)
	ExportZoneToString(zoneID string) (HCloudAnswerGetZonePlainText, error)
	ValidateZoneString(zonePlainText string) (HCloudAnswerZoneValidate, error)
	GetRecord(ID string) (HCloudAnswerGetRecord, error)
	GetRecords(params HCloudGetRecordsParams) (HCloudAnswerGetRecords, error)
	UpdateRecord(record HCloudRecord) (HCloudAnswerGetRecord, error)
	DeleteRecord(ID string) (HCloudAnswerDeleteRecord, error)
	CreateRecord(record HCloudRecord) (HCloudAnswerGetRecord, error)
	CreateRecordBulk(record []HCloudRecord) (HCloudAnswerCreateRecords, error)
	UpdateRecordBulk(record []HCloudRecord) (HCloudAnswerUpdateRecords, error)
}

func New

New instance

type HCloudError

type HCloudError struct {
	Code    int    `json:"code,omitempty"`
	Message string `json:"message,omitempty"`
}

Hetzner errors roundabout. Fuck you Hetzner.

type HCloudGetRecordsParams

type HCloudGetRecordsParams struct {
	ZoneID  string
	Page    string
	PerPage string
}

type HCloudGetZonesParams

type HCloudGetZonesParams struct {
	Name       string
	SearchName string
	Page       string
	PerPage    string
}

type HCloudMeta

type HCloudMeta struct {
	Pagination struct {
		Page         int `json:"page"`
		PerPage      int `json:"per_page"`
		LastPage     int `json:"last_page"`
		TotalEntries int `json:"total_entries"`
	} `json:"pagination,omitempty"`
}

type HCloudRecord

type HCloudRecord struct {
	RecordType RecordType `json:"type"`
	ID         string     `json:"id"`
	Created    string     `json:"created"`
	Modified   string     `json:"modified"`
	ZoneID     string     `json:"zone_id"`
	Name       string     `json:"name"`
	Value      string     `json:"value"`
	TTL        int        `json:"ttl"`
}

type HCloudZone

type HCloudZone struct {
	ID              string   `json:"id,omitempty"`
	Created         string   `json:"created,omitempty"`
	Modified        string   `json:"modified,omitempty"`
	LegacyDNSHost   string   `json:"legacy_dns_host,omitempty"`
	LegacyNS        []string `json:"legacy_ns,omitempty"`
	Name            string   `json:"name,omitempty"`
	NS              []string `json:"ns,omitempty"`
	Owner           string   `json:"owner,omitempty"`
	Paused          bool     `json:"paused,omitempty"`
	Permission      string   `json:"permission,omitempty"`
	Project         string   `json:"project,omitempty"`
	Registrar       string   `json:"registrar,omitempty"`
	Status          string   `json:"status,omitempty"`
	TTL             int      `json:"ttl,omitempty"`
	Verified        string   `json:"verified,omitempty"`
	RecordsCount    int      `json:"records_count,omitempty"`
	IsSecondaryDNS  bool     `json:"is_secondary_dns,omitempty"`
	TXTverification struct {
		Name  string `json:"name,omitempty"`
		Token string `json:"token,omitempty"`
	} `json:"txt_verification,omitempty"`
}

type RecordType

type RecordType string

RecordType supported by Hetzner

const (
	A     RecordType = "A"
	AAAA  RecordType = "AAAA"
	CNAME RecordType = "CNAME"
	MX    RecordType = "MX"
	NS    RecordType = "NS"
	TXT   RecordType = "TXT"
	RP    RecordType = "RP"
	SOA   RecordType = "SOA"
	HINFO RecordType = "HINFO"
	SRV   RecordType = "SRV"
	DANE  RecordType = "DANE"
	TLSA  RecordType = "TLSA"
	DS    RecordType = "DS"
	CAA   RecordType = "CAA"
)

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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