hetzner

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2025 License: MIT Imports: 11 Imported by: 1

README

Hetzner DNS for libdns

godoc reference

This package implements the libdns interfaces for the Hetzner DNS API

Authenticating

To authenticate you need to supply a Hetzner Auth-API-Token.

Example

Here's a minimal example of how to get all DNS records for zone. See also: provider_test.go

package main

import (
	"context"
	"fmt"
	"os"
	"time"

	"github.com/libdns/libdns/hetzner"
)

func main() {
	token := os.Getenv("LIBDNS_HETZNER_TOKEN")
	if token == "" {
		fmt.Printf("LIBDNS_HETZNER_TOKEN not set\n")
		return
	}

	zone := os.Getenv("LIBDNS_HETZNER_ZONE")
	if token == "" {
		fmt.Printf("LIBDNS_HETZNER_ZONE not set\n")
		return
	}

	p := &hetzner.Provider{
		AuthAPIToken: token,
	}

	records, err := p.GetRecords(context.WithTimeout(context.Background(), time.Duration(15*time.Second)), zone)
	if err != nil {
        fmt.Printf("Error: %s", err.Error())
        return
	}

	fmt.Println(records)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider struct {
	// AuthAPIToken is the Hetzner Auth API token - see https://dns.hetzner.com/api-docs#section/Authentication/Auth-API-Token
	AuthAPIToken string `json:"auth_api_token"`
}

Provider implements the libdns interfaces for Hetzner

func (*Provider) AppendRecords

func (p *Provider) AppendRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)

AppendRecords adds records to the zone. It returns the records that were added.

func (*Provider) DeleteRecords

func (p *Provider) DeleteRecords(ctx context.Context, _ string, records []libdns.Record) ([]libdns.Record, error)

DeleteRecords deletes the records from the zone.

func (*Provider) GetRecords

func (p *Provider) GetRecords(ctx context.Context, zone string) ([]libdns.Record, error)

GetRecords lists all the records in the zone.

func (*Provider) SetRecords

func (p *Provider) SetRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)

SetRecords sets the records in the zone, either by updating existing records or creating new ones. It returns the updated records.

Jump to

Keyboard shortcuts

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