ionos

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 18, 2024 License: MIT Imports: 11 Imported by: 3

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

Example

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

package main

import (
	"context"
	"encoding/json"
	"fmt"
	"os"
	"time"

	"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,
	}

	records, err := p.GetRecords(context.TODO(), zone)
	if err != nil {
		panic(err)
	}

	out, _ := json.MarshalIndent(records, "", "  ")
	fmt.Println(string(out))
}

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

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

This section is empty.

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"`
}

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 records from the zone. Returns the list of records acutally deleted. Fails fast on first error, but in this case

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) 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