gandi

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2023 License: Unlicense Imports: 7 Imported by: 0

README

Libdns Gandi implementation

This is an implementation of Golang's libdns for Gandi's LiveDNS API.

It's an alternative to the seemingly stale implementation found on Github, adding support for personal access tokens and fixing bugs related to DNS record updates.

Note: Gandi's LiveDNS records can hold multiple values, which is not directly supported by libdns interface. To overcome this mismatch, records with multiple values are returned as multiple libdns records and vice-versa for write operations. This is done in best effort and with undefined behaviour for concurrent writes for the same name/type.

How to use


import (
	"github.com/libdns/libdns"
	"codeberg.com/tiagosimao/libdns-gandi"
)

func main() {
  provider := Provider{
    PersonalAccessToken: "my pat",
    // or this instead
    // APIToken: "the api token",
  }
  records, err = provider.GetRecords(ctx, zone)
  if err != nil {
    log.Fatal(err)
  }
  log.Printf("%+v\n", records)
}

How to test

Create a .env file (git ignored) with the following content

TEST_GANDI_PAT=pat
# or this instead
#TEST_GANDI_API_TOKEN=apitoken
TEST_DNS_ZONE=example.com

Run the tests with

make test

The tests will try to create and delete DNS records in the configured zone. Partially failed tests might leave garbage records behind, named with a libdns-test- prefix.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider struct {
	APIToken            string `json:"api_token,omitempty"`
	PersonalAccessToken string `json:"pat,omitempty"`
	// contains filtered or unexported fields
}

Provider implements the libdns interfaces for Gandi.

func (*Provider) AppendRecords

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

AppendRecords adds records to the zone and returns the records that were created If a record with the same name and type already exists, it gets the new value appended and TTL updated.

func (*Provider) DeleteRecords

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

DeleteRecords deletes records from the zone and returns the records that were deleted. Gandi DNS records with multiple values have just the requested entry removed

func (*Provider) GetRecords

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

GetRecords returns all the records in the DNS zone Gandi DNS records with multiple values are returned as separate Libdns records

func (*Provider) SetRecords

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

SetRecords creates or updates sets the records in the zone

Jump to

Keyboard shortcuts

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