leaseweb

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2024 License: MIT Imports: 12 Imported by: 3

README

Leaseweb provider for libdns

Go Reference

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

Usage

Generate an API Key via the Leaseweb customer portal; under Administration -> API Key.

Place API Key in the configuration as APIKey.

Gotcha's

  • Leaseweb expects full domain (sub.example.com); where libdns does not (sub as name and example.com as zone).
  • libdns might providea TTL of 0; Leaseweb validates on their supported values (defauling to 60 for now).
  • Leaseweb does not expect a trailing dot in the zone; libdns provides one, so we remove it.

Compiling

Docker

Run:

docker run --rm -it -v "$PWD":/go/src/leaseweb -w /go/src/leaseweb golang:1.16

which will drop you in an interactive bash prompt where go and friends are available.

For example you can build the code with go build.

Example

package main

import (
	"context"
	"fmt"
	"github.com/libdns/leaseweb"
)

func main() {
	provider := leaseweb.Provider{APIKey: "<LEASEWEB API KEY>"}

	records, err  := provider.GetRecords(context.TODO(), "example.com")
	if err != nil {
		fmt.Println(err.Error())
	}

	for _, record := range records {
		fmt.Printf("%s %v %s %s\n", record.Name, record.TTL.Seconds(), record.Type, record.Value)
	}
}

Contributing / developing

Easiest way to get your hands dirty is to use Caddy.

Check contributing instructions at caddy-dns/leaseweb.

Documentation

Overview

Package leaseweb implements a DNS record management client compatible with the libdns interfaces for Leaseweb. Upstream documentation found at: https://developer.leaseweb.com/api-docs/domains_v2.html

Index

Constants

View Source
const (
	LeasewebApiKeyHeader = "X-LSW-Auth"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider struct {
	// Leasewebs API key. Generate one in the Leaseweb customer portal -> Administration -> API Key
	APIKey string `json:"api_token,omitempty"`
	// contains filtered or unexported fields
}

Provider facilitates DNS record manipulation with Leaseweb.

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. It returns the records that were deleted. Leaseweb specifics: - Well-formatted DELETE requests will always succeed, even for non-existing records. TODO: Extract HTTP logic into function in client.go.

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.

Jump to

Keyboard shortcuts

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