transip

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2025 License: MIT Imports: 17 Imported by: 6

README

TransIP for libdns

This package implements the libdns interfaces for the TransIP API

Authenticating

To authenticate, you need to generate a key pair key here.

Example

Here's a minimal example of how to get all your DNS records using this libdns provider

package main

import (
	"context"
	"fmt"
	"os"
	"text/tabwriter"

	"github.com/pbergman/provider"
	"github.com/libdns/transip"
)

func main() {
	var x = &transip.Provider{
		AuthLogin:  "user",
		PrivateKey: "private.key",
	}

	zones, err := x.ListZones(context.Background())

	if err != nil {
		panic(err)
	}

	var writer = tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', tabwriter.Debug)

	for _, zone := range zones {
		records, err := x.GetRecords(context.Background(), zone.Name)

		if err != nil {
			panic(err)
		}

		for _, record := range provider.RecordIterator(&records) {
			_, _ = fmt.Fprintf(writer, "%s\t%v\t%s\t%s\n", record.Name, record.TTL.Seconds(), record.Type, record.Data)
		}

	}

	_ = writer.Flush()
}

Debugging

This library provides the ability to debug the request/response communication with the API server.

To enable debugging, simply set the debugging property to true:

	var x = &transip.Provider{
        AuthLogin:  "user",
        PrivateKey: "private.key",
    }

	zones, err := provider.ListZones(context.Background())

	if err != nil {
		panic(err)
	}

	records, err := provider.GetRecords(context.Background(), "example.nl")
........................
[c] GET /v6/domains HTTP/1.1
[c] Host: api.transip.nl
[c] Accept: application/json
[c] Authorization: Bearer ********************
[c] Content-Type: application/json
[c] 
[s] HTTP/2.0 200 OK
[s] Connection: close
[s] Content-Type: application/json
......
[s] 
[s] {"domains":[{"name":"...

This will by default write to stdout but can set to any io.Writer by also setting the DebugOut property.

    var provider = &transip.Provider{
        AuthLogin:  "user",
        PrivateKey: "private.key",
        Debug: true,
        DebugOut: log.Writer(),
    }

Testing

This library comes with a test suite that verifies the interface by creating a few test records, validating them, and then removing those records. To run the tests, you can use:

KEY=<KEY_FILE> LOGIN=<USER> go test

Or run more verbose test to dump all api requests and responses:

KEY=<KEY_FILE> LOGIN=<USER> DEBUG=1 go test -v 

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTokenStorage added in v1.0.0

func NewTokenStorage(location string) client.Storage

Types

type ApiBaseUri added in v1.0.0

type ApiBaseUri url.URL

func DefaultApiBaseUri added in v1.0.0

func DefaultApiBaseUri() *ApiBaseUri

func (*ApiBaseUri) MarshalJSON added in v1.0.0

func (a *ApiBaseUri) MarshalJSON() ([]byte, error)

func (*ApiBaseUri) UnmarshalJSON added in v1.0.0

func (a *ApiBaseUri) UnmarshalJSON(data []byte) error

type Client added in v1.0.0

type Client interface {
	provider.Client
	provider.ZoneAwareClient
}

type Provider

type Provider struct {
	// AuthLogin the login used for authentication
	AuthLogin string `json:"login"`
	// AuthReadOnly set to true to create readonly keys
	AuthReadOnly bool `json:"read_only"`
	// AuthNotGlobalKey can be set to true to generate keys that are
	// restricted to clients with IP addresses included in the whitelist.
	AuthNotGlobalKey bool `json:"not_global_key"`
	// AuthExpirationTime specifies the time-to-live for an authentication token.
	AuthExpirationTime client.ExpirationTime `json:"expiration_time"`

	// PrivateKey can be generated here:
	// https://www.transip.nl/cp/account/api
	//
	// It is used for authentication and can be provided either as a
	// string containing the key or as a filepath to a file containing
	// the private key.
	PrivateKey string `json:"private_key"`

	// DebugLevel sets the verbosity for logging API requests and responses.
	DebugLevel provider.OutputLevel `json:"debug_level"`
	// DebugOut defines the output destination for debug logs.
	// Defaults to standard output (STDOUT).
	DebugOut io.Writer `json:"-"`

	// BaseURI is the base URI used for API calls.
	// Default: https://api.transip.nl/v6/
	BaseUri *ApiBaseUri `json:"base_uri"`

	// TokenStorage specifies where tokens are stored and can be reused
	// until they expire. It can be set to:
	// - "memory" for in-memory storage,
	// - a file path for storing keys on disk
	// - empty, in which case keys will be stored in a "transip" directory
	//   in the user's temp folder.
	TokenStorage string `json:"token_storage"`

	// ClientControl has two modes:
	// - RecordLevelControl (default): updates records individually.
	// - FullZoneControl: replaces the entire zone in a single call.
	//   While this is much faster, it can encounter race conditions if
	//   another program modifies the zone simultaneously, as updates
	//   may be overwritten.
	ClientControl client.ControleMode `json:"client_control_mode"`
	// contains filtered or unexported fields
}

func (*Provider) AppendRecords

func (p *Provider) AppendRecords(ctx context.Context, zone string, recs []libdns.Record) ([]libdns.Record, error)

func (*Provider) DebugOutput added in v1.0.0

func (p *Provider) DebugOutput() io.Writer

func (*Provider) DebugOutputLevel added in v1.0.0

func (p *Provider) DebugOutputLevel() provider.OutputLevel

func (*Provider) DeleteRecords

func (p *Provider) DeleteRecords(ctx context.Context, zone string, recs []libdns.Record) ([]libdns.Record, error)

func (*Provider) ExpirationTime added in v1.0.0

func (p *Provider) ExpirationTime() client.ExpirationTime

func (*Provider) GetBaseUri added in v1.0.0

func (p *Provider) GetBaseUri() *url.URL

func (*Provider) GetPrivateKey added in v1.0.0

func (p *Provider) GetPrivateKey() (*rsa.PrivateKey, error)

func (*Provider) GetRecords

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

func (*Provider) GlobalKey added in v1.0.0

func (p *Provider) GlobalKey() bool

func (*Provider) ListZones added in v1.0.0

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

func (*Provider) Login added in v1.0.0

func (p *Provider) Login() string

func (*Provider) ReadOnly added in v1.0.0

func (p *Provider) ReadOnly() bool

func (*Provider) SetDebug added in v1.0.0

func (p *Provider) SetDebug(level provider.OutputLevel, writer io.Writer)

func (*Provider) SetRecords

func (p *Provider) SetRecords(ctx context.Context, zone string, recs []libdns.Record) ([]libdns.Record, error)

func (*Provider) StorageKey added in v1.0.0

func (p *Provider) StorageKey() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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