bluecat

package module
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Oct 6, 2026 License: MIT Imports: 16 Imported by: 3 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Bluecat for libdns

Go Reference

This package implements the libdns interfaces for Bluecat Address Manager, allowing you to manage DNS records.

Configuration

To use this provider, you need:

  • Bluecat Address Manager API endpoint (URL)
  • Username
  • Password

Example Usage

package main

import (
	"context"
	"fmt"
	"time"

	"github.com/libdns/bluecat"
	"github.com/libdns/libdns"
)

func main() {
	provider := &bluecat.Provider{
		ServerURL: "https://bluecat.example.com",
		Username:  "api_user",
		Password:  "api_password",
		// Optional: limit zone lookups to one DNS view
		// ViewName: "view",
	}

	zone := "example.com."
	ctx := context.Background()

	// Get existing records
	records, err := provider.GetRecords(ctx, zone)
	if err != nil {
		panic(err)
	}
	fmt.Printf("Found %d records\n", len(records))

	// Append a new A record
	newRecords := []libdns.Record{
		libdns.Address{
			Name: "test",
			TTL:  300 * time.Second,
			IP:   netip.MustParseAddr("192.0.2.1"),
		},
	}
	
	created, err := provider.AppendRecords(ctx, zone, newRecords)
	if err != nil {
		panic(err)
	}
	fmt.Printf("Created %d records\n", len(created))
}

Caveats

  • The provider requires Bluecat Address Manager 9.5.0 or later with the RESTful v2 API enabled
  • Record names should be relative to the zone (e.g., "www" for "www.example.com" in zone "example.com.")
  • Handling of Bluecat's linked records is not properly implemented yet. Networks and existing records to link A records and CNAMEs must already exist.
  • ConfigurationName is accepted but not yet applied to zone lookups. If the same zone name exists in more than one configuration (or in more than one view with no ViewName set), lookups fail with an ambiguity error instead of picking one.

Features

  • Authentication sessions are automatically managed and tokens are cached for efficiency
  • The provider supports A, AAAA, CNAME, TXT, MX, NS, and SRV record types

Documentation

Overview

Package bluecat implements a DNS record management client compatible with the libdns interfaces for Bluecat Address Manager.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsAlreadyExists added in v0.1.8

func IsAlreadyExists(err error) bool

IsAlreadyExists reports whether err is a Bluecat duplicate-resource error, i.e. the record we tried to create is already present.

func IsAuthError added in v0.1.8

func IsAuthError(err error) bool

IsAuthError reports whether err indicates the session is invalid or expired. The transport uses this to trigger re-authentication.

func IsNotFound added in v0.1.8

func IsNotFound(err error) bool

IsNotFound reports whether err indicates the resource does not exist. Deletes treat this as success, since the desired end state already holds.

func IsRetryable added in v0.1.8

func IsRetryable(err error) bool

IsRetryable reports whether err is transient and the request may be retried. Transport-level failures qualify; so do 429 and 5xx. Note that retrying is only safe for idempotent requests — see retryPolicy.Unsafe.

Types

type APIError added in v0.1.8

type APIError struct {
	StatusCode int    `json:"status"`
	Reason     string `json:"reason"`
	Code       string `json:"code"`
	Message    string `json:"message"`
	Detail     string `json:"detail"`

	// Method and Path identify the request that failed. Not part of the
	// Bluecat envelope; filled in by the transport.
	Method string `json:"-"`
	Path   string `json:"-"`

	// RawBody holds the (truncated) response body when it did not parse as
	// an error envelope. Empty when Code/Message were populated.
	RawBody string `json:"-"`
}

APIError is a structured error response from the Bluecat v2 API.

Bluecat returns errors as a JSON envelope, e.g.:

{"status":409,"reason":"Conflict","code":"ResourceAlreadyExists",
 "message":"The request attempted to create a resource that already exists",
 "detail":"Duplicate of another item"}

Callers should test for specific conditions with IsAlreadyExists, IsNotFound, IsAuthError and IsRetryable rather than inspecting fields directly.

func (*APIError) Error added in v0.1.8

func (e *APIError) Error() string

type BluecatResourceRecord

type BluecatResourceRecord struct {
	ID               int64  `json:"id,omitempty"`
	Type             string `json:"type"`
	Name             string `json:"name"`
	AbsoluteName     string `json:"absoluteName,omitempty"`
	TTL              int    `json:"ttl,omitempty"`
	RecordType       string `json:"recordType,omitempty"`
	RData            string `json:"rdata,omitempty"`
	Text             string `json:"text,omitempty"`
	LinkedRecordName string `json:"linkedRecordName,omitempty"`
	Priority         int    `json:"priority,omitempty"`
	Weight           int    `json:"weight,omitempty"`
	Port             int    `json:"port,omitempty"`
	Addresses        []struct {
		Address string `json:"address"`
	} `json:"addresses,omitempty"`
}

BluecatResourceRecord represents a resource record in the Bluecat API.

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client handles communication with the Bluecat Address Manager v2 API.

A Client is safe for concurrent use. It authenticates lazily on first use and re-authenticates automatically when Bluecat rejects a session.

func NewClient

func NewClient(baseURL, username, password string) (*Client, error)

NewClient creates a new Bluecat API client. It does not contact the server; authentication happens on the first request.

func (*Client) CreateOrAdopt added in v0.1.8

func (c *Client) CreateOrAdopt(ctx context.Context, zoneID int64, zone string, record libdns.Record) (libdns.Record, bool, error)

CreateOrAdopt creates a record, tolerating the case where it already exists.

Bluecat rejects a duplicate with 409 ResourceAlreadyExists. That happens routinely during ACME: a challenge that failed after the record was written is retried with the same key authorization, and another cluster node may have written the identical record already. In both cases the desired state already holds, so re-reading the RRset and adopting a record with a matching value is correct and lets issuance proceed.

A conflicting record with a *different* value is not adopted: that would silently change data the caller did not ask to change.

func (*Client) CreateResourceRecord

func (c *Client) CreateResourceRecord(ctx context.Context, zoneID int64, zone string, record libdns.Record) (libdns.Record, error)

CreateResourceRecord creates a resource record. A duplicate returns an *APIError for which IsAlreadyExists reports true; callers that want idempotent behaviour should use CreateOrAdopt.

func (*Client) DeleteResourceRecordByID added in v0.1.4

func (c *Client) DeleteResourceRecordByID(ctx context.Context, recordID int64) error

DeleteResourceRecordByID deletes a resource record. A record that is already gone is not an error: the requested end state holds either way.

func (*Client) DeployZone added in v0.1.1

func (c *Client) DeployZone(ctx context.Context, zoneID int64) error

DeployZone triggers a quick deployment of a zone and waits until Bluecat confirms it is complete, so callers don't begin DNS propagation checks before the records are actually live on the authoritative servers.

func (*Client) FindResourceRecords added in v0.1.8

func (c *Client) FindResourceRecords(ctx context.Context, zoneID int64, name, recordType, zone string) ([]BluecatResourceRecord, error)

FindResourceRecords returns every record in a zone matching a relative name and, when recordType is non-empty, that record type. Fully paginated, and returns all matches rather than just the first — an RRset with several values (notably concurrent _acme-challenge TXT records) has more than one.

func (*Client) GetResourceRecords

func (c *Client) GetResourceRecords(ctx context.Context, zoneID int64, zone string) ([]libdns.Record, error)

GetResourceRecords retrieves every resource record in a zone, following pagination to the end of the collection.

func (*Client) GetZoneID

func (c *Client) GetZoneID(ctx context.Context, zone, configName, viewName string) (int64, error)

GetZoneID resolves a zone name to its Bluecat zone ID, scoped to the given configuration and view.

The name is resolved most-specific-first: "a.b.example.com" is tried before "b.example.com" and then "example.com", so a delegated subzone wins over its parent. Unlike a plain "not found", a transport or authorization failure aborts the walk rather than silently falling back to a parent zone.

type Provider

type Provider struct {
	// ServerURL is the base URL of the Bluecat Address Manager server
	// (e.g., "https://bluecat.example.com")
	ServerURL string `json:"server_url,omitempty"`

	// Username for authenticating with the Bluecat API
	Username string `json:"username,omitempty"`

	// Password for authenticating with the Bluecat API
	Password string `json:"password,omitempty"`

	// ConfigurationName is accepted for compatibility but currently ignored:
	// zone lookups are not filtered by configuration. If a zone name matches
	// more than one zone (for example, the same zone in two configurations),
	// the lookup fails with an ambiguity error rather than guessing.
	ConfigurationName string `json:"configuration_name,omitempty"`

	// ViewName limits zone lookups to one DNS view (optional). Without it, a
	// zone that exists in more than one view fails with an ambiguity error.
	ViewName string `json:"view_name,omitempty"`

	// DeployDelay is how long to wait after the last record write before
	// issuing a QuickDeploy to Bluecat. This debounces rapid sequential
	// writes (e.g. multiple concurrent ACME DNS-01 challenges) into a
	// single deploy call, avoiding Bluecat timeouts.
	//
	// Defaults to 5 seconds when zero or unset.
	DeployDelay time.Duration `json:"deploy_delay,omitempty"`

	// MaxDeployDelay caps how long debouncing can postpone a deploy. Without
	// a cap, a steady stream of writes — a bulk renewal, say — resets the
	// debounce timer indefinitely and the deploy never runs at all.
	//
	// Defaults to four times DeployDelay, or 30 seconds, whichever is larger.
	MaxDeployDelay time.Duration `json:"max_deploy_delay,omitempty"`

	// DisableDeploy suppresses automatic deployment entirely. Records are
	// written to Bluecat but not pushed to the DNS servers, so callers must
	// arrange deployment themselves. Advanced use only.
	DisableDeploy bool `json:"disable_deploy,omitempty"`

	// Logger receives operational detail: adopted duplicate records,
	// re-authentication, deploy coalescing. Defaults to discarding output.
	Logger *slog.Logger `json:"-"`
	// contains filtered or unexported fields
}

Provider facilitates DNS record manipulation with Bluecat Address Manager.

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.

A record that already exists in Bluecat with the value being written is adopted rather than treated as an error. Bluecat rejects duplicates with 409 ResourceAlreadyExists, and during ACME that happens routinely: a retried challenge presents the same key authorization, and another cluster node may have written the identical record first. The requested state already holds in both cases.

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 actually deleted.

Records are matched on name, type and value; empty Type, TTL or Data fields act as wildcards, per the libdns contract. Matching on value matters: two concurrent ACME challenges can hold different TXT values at the same _acme-challenge name, and cleaning up one must not remove the other.

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.

Only the (name, type) pairs present in records are touched; every other record in the zone is left alone, per the libdns contract.

Jump to

Keyboard shortcuts

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