Documentation
¶
Overview ¶
Package unifi implements a DNS record management client compatible with the libdns interfaces for UniFi
Index ¶
- 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)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Provider ¶
type Provider struct {
// ApiKey is the Unifi API authentication key.
ApiKey string `json:"api_key,omitempty"`
// SiteId is the UUID of the Unifi site containing the DNS policies.
SiteId string `json:"site_id,omitempty"`
// BaseUrl is the base URL of the Unifi controller API.
// Example: https://192.168.1.1/proxy/network/integration/v1
BaseUrl string `json:"base_url,omitempty"`
// contains filtered or unexported fields
}
Provider facilitates DNS record management for Unifi Network. It implements the libdns record management interfaces.
Credentials can be set directly on the struct fields or via environment variables:
Example ¶
ExampleProvider demonstrates basic usage of the unifi provider
package main
import (
"context"
"log"
"net/netip"
"time"
"github.com/libdns/libdns"
"github.com/libdns/unifi"
)
func main() {
provider := unifi.Provider{
ApiKey: "your-api-key",
SiteId: "your-site-uuid",
BaseUrl: "https://192.168.1.1/proxy/network/integration/v1",
}
ctx := context.Background()
// List all records
records, err := provider.GetRecords(ctx, "example.com")
if err != nil {
log.Fatal(err)
}
log.Printf("Found %d records\n", len(records))
// Add a new record
newRecord := libdns.Address{
Name: "www",
IP: netip.MustParseAddr("192.0.2.1"),
TTL: 3600 * time.Second,
}
created, err := provider.AppendRecords(ctx, "example.com", []libdns.Record{newRecord})
if err != nil {
log.Fatal(err)
}
log.Printf("Created %d records\n", len(created))
}
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 and returns the deleted records.
func (*Provider) GetRecords ¶
GetRecords lists all the records in the zone. The zone parameter is not used for Unifi (all records for the site are returned).