libdnsspaceship

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 13, 2025 License: MIT Imports: 12 Imported by: 1

README

Spaceship for libdns

Go Reference

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

Configuration

To use this provider, you need a Spaceship API key and secret. Configure the provider as follows:

provider := &libdnsspaceship.Provider{
    APIKey:    "your-spaceship-api-key",
    APISecret: "your-spaceship-api-secret",
}

Optionally, you can customize the API base URL (defaults to https://spaceship.dev/api):

provider := &libdnsspaceship.Provider{
    APIKey:    "your-spaceship-api-key",
    APISecret: "your-spaceship-api-secret",
    BaseURL:   "https://custom-api.spaceship.com",
}
Environment Variables

Alternatively, you can use environment variables or the NewProviderFromEnv() constructor to configure the provider:

provider := libdnsspaceship.NewProviderFromEnv()

The following environment variables are supported:

Environment Variable Description Required Default
LIBDNS_SPACESHIP_APIKEY Your Spaceship API key Yes -
LIBDNS_SPACESHIP_APISECRET Your Spaceship API secret Yes -
LIBDNS_SPACESHIP_BASEURL Custom API base URL No https://spaceship.dev/api
LIBDNS_SPACESHIP_PAGESIZE Page size for GetRecords pagination No 100
LIBDNS_SPACESHIP_TIMEOUT HTTP client timeout in seconds No 30
Example .env file
LIBDNS_SPACESHIP_APIKEY=your_api_key_here
LIBDNS_SPACESHIP_APISECRET=your_api_secret_here
LIBDNS_SPACESHIP_BASEURL=https://spaceship.dev/api
LIBDNS_SPACESHIP_PAGESIZE=100
LIBDNS_SPACESHIP_TIMEOUT=30

Usage

package main

import (
    "context"
    "time"
    
    "github.com/Redth/libdns-spaceship"
    "github.com/libdns/libdns"
)

func main() {
    provider := &libdnsspaceship.Provider{
        APIKey:    "your-spaceship-api-key",
        APISecret: "your-spaceship-api-secret",
    }
    
    zone := "example.com."
    
    // Get all records
    records, err := provider.GetRecords(context.TODO(), zone)
    if err != nil {
        panic(err)
    }
    
    // Add a new A record
    newRecords := []libdns.Record{
        libdns.Address{
            Name: "test",
            TTL:  300 * time.Second,
            IP:   netip.MustParseAddr("192.0.2.1"),
        },
    }
    
    createdRecords, err := provider.AppendRecords(context.TODO(), zone, newRecords)
    if err != nil {
        panic(err)
    }
}

Supported Record Types

This provider supports the following DNS record types:

  • A and AAAA records (libdns.Address)
  • TXT records (libdns.TXT)
  • CNAME records (libdns.CNAME)
  • MX records (libdns.MX)
  • SRV records (libdns.SRV)
  • NS records (libdns.NS)
  • CAA records (libdns.CAA)
  • HTTPS records (libdns.ServiceBinding with scheme "https")

Unsupported record types (such as PTR, TLSA, etc.) are filtered out and not returned by GetRecords.

API Documentation

For more information about the Spaceship API, see the official documentation.

License

MIT License (See LICENSE file)

Documentation

Overview

Package libdnsspaceship implements a DNS record management client compatible with the libdns interfaces for Spaceship. This package allows you to manage DNS records using the Spaceship DNS API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Provider

type Provider struct {
	// APIKey is the Spaceship API key for authentication
	APIKey string `json:"api_key,omitempty"`

	// APISecret is the Spaceship API secret for authentication
	APISecret string `json:"api_secret,omitempty"`

	// BaseURL is the base URL for the Spaceship API (defaults to https://spaceship.dev/api)
	BaseURL string `json:"base_url,omitempty"`

	// HTTPClient allows customization of the HTTP client used for API requests
	HTTPClient *http.Client `json:"-"`

	// PageSize controls pagination size used by GetRecords (defaults to 100)
	PageSize int `json:"page_size,omitempty"`
}

Provider facilitates DNS record manipulation with Spaceship.

func NewProviderFromEnv

func NewProviderFromEnv() *Provider

NewProviderFromEnv constructs a Provider using environment variables. Recognized environment variables: - LIBDNS_SPACESHIP_APIKEY: API key (required for API calls) - LIBDNS_SPACESHIP_APISECRET: API secret (required for API calls) - LIBDNS_SPACESHIP_BASEURL: optional base URL override - LIBDNS_SPACESHIP_PAGESIZE: optional page size for list operations - LIBDNS_SPACESHIP_TIMEOUT: optional HTTP client timeout in seconds

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

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

func (p *Provider) PopulateFromEnv()

PopulateFromEnv fills unset Provider fields from environment variables.

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 by saving the provided records (force update).

type ResourceRecordBase

type ResourceRecordBase struct {
	Type string `json:"type"`
	Name string `json:"name"`
	TTL  int    `json:"ttl,omitempty"`
}

ResourceRecordBase contains fields common to all Spaceship DNS record payloads (this is intentionally minimal; each specific record type augments this with fields appropriate for that type).

Jump to

Keyboard shortcuts

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