ionos

package module
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: MIT Imports: 14 Imported by: 6 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

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

Restricting writes to zones

IONOS API keys grant access to all zones of an account. Set AllowedZones (JSON: allowed_zones) to limit write operations (AppendRecords, SetRecords, DeleteRecords) to the listed zones. Empty means no restriction. This is a client-side safeguard against misconfiguration, not a security boundary.

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
=== RUN   Test_checkZoneAllowed
=== RUN   Test_checkZoneAllowed/empty_list_allows_all
=== RUN   Test_checkZoneAllowed/exact_match
=== RUN   Test_checkZoneAllowed/trailing_dot_in_zone
=== RUN   Test_checkZoneAllowed/trailing_dot_in_list
=== RUN   Test_checkZoneAllowed/case_insensitive
=== RUN   Test_checkZoneAllowed/not_listed
=== RUN   Test_checkZoneAllowed/subzone_not_matched
--- PASS: Test_checkZoneAllowed (0.00s)
    --- PASS: Test_checkZoneAllowed/empty_list_allows_all (0.00s)
    --- PASS: Test_checkZoneAllowed/exact_match (0.00s)
    --- PASS: Test_checkZoneAllowed/trailing_dot_in_zone (0.00s)
    --- PASS: Test_checkZoneAllowed/trailing_dot_in_list (0.00s)
    --- PASS: Test_checkZoneAllowed/case_insensitive (0.00s)
    --- PASS: Test_checkZoneAllowed/not_listed (0.00s)
    --- PASS: Test_checkZoneAllowed/subzone_not_matched (0.00s)
=== RUN   Test_WritesRejectDisallowedZone
--- PASS: Test_WritesRejectDisallowedZone (0.00s)
=== RUN   Test_ConfigCompatible
--- PASS: Test_ConfigCompatible (0.00s)
=== RUN   Test_AppendRecords
=== RUN   Test_AppendRecords/testcase_0
=== RUN   Test_AppendRecords/testcase_1
=== RUN   Test_AppendRecords/testcase_2
--- PASS: Test_AppendRecords (3.40s)
    --- PASS: Test_AppendRecords/testcase_0 (1.41s)
    --- PASS: Test_AppendRecords/testcase_1 (0.87s)
    --- PASS: Test_AppendRecords/testcase_2 (1.12s)
=== RUN   Test_DeleteRecords
--- PASS: Test_DeleteRecords (1.28s)
=== RUN   Test_DeleteRecordsWillNotDeleteWithoutName
--- PASS: Test_DeleteRecordsWillNotDeleteWithoutName (0.05s)
=== RUN   Test_DeleteRecordsRejectsZoneNotAllowed
--- PASS: Test_DeleteRecordsRejectsZoneNotAllowed (0.00s)
=== RUN   Test_GetRecords
--- PASS: Test_GetRecords (1.77s)
=== RUN   Test_UpdateRecords
--- PASS: Test_UpdateRecords (1.68s)
PASS
ok  	github.com/libdns/ionos	8.190s

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

Documentation

Overview

libdns client for IONOS DNS API

libdns implementation for IONOS DNS API. IONOS API documentaion: https://developer.hosting.ionos.de/docs/dns libdns: https://github.com/libdns/libdns

Index

Constants

View Source
const (
	APIEndpoint = "https://api.hosting.ionos.com/dns/v1"
)

Variables

View Source
var ErrZoneNotAllowed = errors.New("zone is not in the configured allow-list")

ErrZoneNotAllowed is returned by write operations on a zone not listed in AllowedZones.

Functions

This section is empty.

Types

type Provider

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

	// AllowedZones optionally restricts write operations to the listed zones.
	// Empty means no restriction. Read operations are unaffected.
	AllowedZones []string `json:"allowed_zones,omitempty"`
}

Provider implements the libdns interfaces for IONOS

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,
	zone string,
	records []libdns.Record,
) ([]libdns.Record, error)

DeleteRecords deletes the given records from the zone if they exist in the zone and exactly match the input. If the input records do not exist in the zone, they are silently ignored. DeleteRecords returns only the the records that were deleted, and does not return any records that were provided in the input but did not exist in the zone.

DeleteRecords only deletes records from the zone that *exactly* match the input records—that is, the name, type, TTL, and value all must be identical to a record in the zone for it to be deleted.

As a special case, you may leave any of the fields libdns.Record.Type, libdns.Record.TTL, or libdns.Record.Value empty ("", 0, and "" respectively). In this case, DeleteRecords will delete any records that match the other fields, regardless of the value of the fields that were left empty. Note that this behavior does *not* apply to the libdns.Record.Name field, which must always be specified.

Note that it is semantically invalid to remove the last “NS” record from a zone, so attempting to do is undefined behavior.

Implementations should return struct types defined by this package which correspond with the specific RR-type, rather than the [RR] struct, if possible.

Implementations must honor context cancellation and be safe for concurrent use.

libdns-ionos notes: we use ionosFindRecordsInZone to filter the records, which does not support TTL

func (*Provider) GetRecords

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

GetRecords lists all the records in the zone.

func (*Provider) ListZones added in v1.2.0

func (p *Provider) ListZones(ctx context.Context) ([]libdns.Zone, error)

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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