Skip to content

StarHack/go-hetzner-dns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 

Repository files navigation

go-hetzner-dns

This is my implementation of golang support for the Hetzner Public DNS API. This project was part of a self-built ACME client implementation and it was needed to update DNS records of domains during the ACME Challenge.

Visit this page to generate a Hetzner Public DNS API Token.

Sample usage

Refer to the wiki tab in this repository for further examples.

package main

import (
  "fmt"
  "os"

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

func main() {
  h := hetzner.Hetzner{APIKey: "<your_api_key>"}
  zones, err := h.FindAllZones()

  if err != nil {
    panic(err)
  }

  for _, zone := range zones {
    fmt.Println(zone.Name)
  }

  zoneId, err := h.FindZoneID("example.com")

  if err != nil {
    panic(err)
  }

  h.CreateOrUpdateRecord(zoneId, "A", "www", "1.2.3.4")
  h.CreateRecord(zoneId, "TXT", "_acme-challenge", "ABCD")
  h.UpdateRecord(...)
  h.DeleteRecord(...)

  data, _ := h.ExportZoneFile("example.com")
  os.WriteFile("zone.txt", data, 0755)
}

Building

This is a Go project so download and install the latest version from https://go.dev/. Create a new directory test/ and create a file main.go with above file content in it. We may then run the following to init and build the project:

go mod init test
go get
go build
./test

Status

As of today, the current version of Hetzner DNS Public API is 1.1.1. So far, the following core features were implemented. A couple of features such as pagination are still missing but the basic functionality for all of the provided endpoints is there.

Authentication

  • Auth-API-Token

Zones

  • Get All Zones
  • Create Zone
  • Get Zone
  • Update Zone
  • Delete Zone
  • Import Zone file plain
  • Export Zone file
  • Validate Zone file plain

Records

  • Get All Records
  • Create Record
  • Get Record
  • Update Record
  • Delete Record
  • Bulk Create Records
  • Bulk Update Records

Primary Servers

The following endpoints were implemented but not tested yet.

  • Get All Primary Servers
  • Create Primary Server
  • Get Primary Server
  • Update Primary Server
  • Delete Primary Server

About

Hetzner DNS Client Implementation

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages