Skip to content

Latest commit

 

History

6 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

IONOS DNS API for libdns

This package implements the libdns interfaces for the IONOS DNS API

Authenticating

To authenticate you need to supply a IONOS API Key, as described on https://developer.hosting.ionos.de/docs/getstarted

Example

Here's a minimal example of how to get all DNS records for zone.

package main

import (
	"context"
	"fmt"
	"os"

	"github.com/libdns/ionos"
)

func main() {
	token := os.Getenv("LIBDNS_IONOS_TOKEN")
	if token == "" {
		panic("LIBDNS_IONOS_TOKEN not set")
	}

	zone := os.Getenv("LIBDNS_IONOS_ZONE")
	if zone == "" {
		panic("LIBDNS_IONOS_ZONE not set")
	}

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

	zones, err := p.ListZones(context.TODO())
	if err != nil {
		panic(err)
	}
	fmt.Print("Zones:\n")
	for _, z := range zones {
		fmt.Printf("%+v\n", z)
	}

	fmt.Printf("\nRecord in Zone %s\n", zone)
	records, err := p.GetRecords(context.TODO(), zone)
	if err != nil {
		panic(err)
	}

	for _, r := range records {
		fmt.Printf("%+v\n", r.RR())
	}
}

Test

The file provisioner_test.go contains an end-to-end test suite, using the original IONOS API service (i.e. no test doubles - be careful). To run the tests:

$ export LIBDNS_IONOS_TEST_ZONE=mydomain.org
$ export LIBDNS_IONOS_TEST_TOKEN=aaaaaaaaaaa.bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
$ go  test -v
go test -v
=== RUN   Test_AppendRecords
=== RUN   Test_AppendRecords/testcase_0
=== RUN   Test_AppendRecords/testcase_1
=== RUN   Test_AppendRecords/testcase_2
--- PASS: Test_AppendRecords (6.71s)
    --- PASS: Test_AppendRecords/testcase_0 (2.51s)
    --- PASS: Test_AppendRecords/testcase_1 (2.15s)
    --- PASS: Test_AppendRecords/testcase_2 (2.05s)
=== RUN   Test_DeleteRecords
=== RUN   Test_DeleteRecords/clear_record.ID=true
=== RUN   Test_DeleteRecords/clear_record.ID=false
--- PASS: Test_DeleteRecords (9.62s)
    --- PASS: Test_DeleteRecords/clear_record.ID=true (4.81s)
    --- PASS: Test_DeleteRecords/clear_record.ID=false (4.80s)
=== RUN   Test_GetRecords
--- PASS: Test_GetRecords (4.41s)
=== RUN   Test_UpdateRecords
=== RUN   Test_UpdateRecords/clear_record.ID=true
=== RUN   Test_UpdateRecords/clear_record.ID=false
--- PASS: Test_UpdateRecords (10.14s)
    --- PASS: Test_UpdateRecords/clear_record.ID=true (5.84s)
    --- PASS: Test_UpdateRecords/clear_record.ID=false (4.30s)
PASS
ok  	github.com/libdns/ionos	30.884s

Author

Original Work (C) Copyright 2020 by matthiasng (based on https://github.com/libdns/hetzner), this version (C) Copyright 2021 by Jan Delgado (github.com/jandelgado).

License: MIT

About

IONOS DNS libdns implementation

Topics

Resources

Stars

7 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages