Documentation
¶
Overview ¶
Package bluecat implements a DNS record management client compatible with the libdns interfaces for Bluecat Address Manager.
Index ¶
- func IsAlreadyExists(err error) bool
- func IsAuthError(err error) bool
- func IsNotFound(err error) bool
- func IsRetryable(err error) bool
- type APIError
- type BluecatResourceRecord
- type Client
- func (c *Client) CreateOrAdopt(ctx context.Context, zoneID int64, zone string, record libdns.Record) (libdns.Record, bool, error)
- func (c *Client) CreateResourceRecord(ctx context.Context, zoneID int64, zone string, record libdns.Record) (libdns.Record, error)
- func (c *Client) DeleteResourceRecordByID(ctx context.Context, recordID int64) error
- func (c *Client) DeployZone(ctx context.Context, zoneID int64) error
- func (c *Client) FindResourceRecords(ctx context.Context, zoneID int64, name, recordType, zone string) ([]BluecatResourceRecord, error)
- func (c *Client) GetResourceRecords(ctx context.Context, zoneID int64, zone string) ([]libdns.Record, error)
- func (c *Client) GetZoneID(ctx context.Context, zone, configName, viewName string) (int64, error)
- type Provider
- func (p *Provider) AppendRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)
- func (p *Provider) DeleteRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)
- func (p *Provider) GetRecords(ctx context.Context, zone string) ([]libdns.Record, error)
- func (p *Provider) SetRecords(ctx context.Context, zone string, records []libdns.Record) ([]libdns.Record, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsAlreadyExists ¶ added in v0.1.8
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
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
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
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.
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 ¶
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
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
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 ¶
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 ¶
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.