netcup

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2025 License: MIT Imports: 10 Imported by: 7

README

netcup for libdns

Go Reference

This package implements the libdns interfaces for the netcup DNS API, allowing you to manage DNS records.

Configuration

The provider is configured by instantiating the netcup.Provider with the customer number, the API key and the API password for the DNS API obtained from netcup (guide). Here is a minimal working example to get all DNS records using environment variables for the credentials:

import (
	"context"
	"fmt"
	"os"

	"github.com/libdns/netcup"
)

func main() {
	provider := netcup.Provider{
		CustomerNumber: os.Getenv("LIBDNS_NETCUP_CUSTOMER_NUMBER"),
		APIKey:         os.Getenv("LIBDNS_NETCUP_API_KEY"),
		APIPassword:    os.Getenv("LIBDNS_NETCUP_API_PASSWORD"),
	}
	ctx := context.TODO()
	zone := os.Getenv("LIBDNS_NETCUP_ZONE")

	records, err := provider.GetRecords(ctx, zone)
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	for _, record := range records {
		fmt.Printf("%+v\n", record)
	}
}

Usage

⚠ The netcup API does not offer setting the TTL for individual records.

⚠ As the ID attribute has been removed in the libdns record structs, using the ID field is not possible.

Updating and deleting records can be done by either filling all struct fields of the dnsRecord, or just Name and Type (+ Priority for MX records). Then the first record matching these criteria is updated/deleted.

Documentation

Overview

Package netcup implements a DNS record management client compatible with the libdns interfaces for netcup.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider struct {
	CustomerNumber string `json:"customer_number"`
	APIKey         string `json:"api_key"`
	APIPassword    string `json:"api_password"`
	// contains filtered or unexported fields
}

Provider facilitates DNS record manipulation with netcup. CustomerNumber, APIKey and APIPassword have to be filled with the respective credentials from netcup. The netcup API requires a session ID for all requests, so at the beginning of each method call a login is performed to receive the session ID and at the end the session is stopped with a logout. The mutex locks concurrent access on all four implemented methods to make sure there is no race condition in the netcup zone and record configuration.

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. netcup records cannot have individual TTLs, there is one TTL for all records in the zone

For each input record, if no ID is given, the first record that matches the host name and type is searched. If none is found or the search result doesn't equal the input, a new one is appended. For MX records the priority is needed as an additional search parameter.

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. It returns the records that were deleted.

For each input record, if no ID is given, the first record that matches the host name and type is searched and deleted. For MX records the priority is needed as an additional search parameter. To be safe, the records to delete should include the IDs (for example from GetRecords)

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.

netcup records cannot have individual TTLs, there is one TTL for all records in the zone. So these can not be set.

For each input record, if no ID is given, the first record that matches the host name and type is searched. If none is found, the input is appended. If one is found, it is updated accordingly. For MX records the priority is needed as an additional search parameter.

Jump to

Keyboard shortcuts

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