dnsapi

package
v0.0.0-...-8bcd307 Latest Latest
Warning

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

Go to latest
Published: Jul 9, 2026 License: BSD-3-Clause Imports: 36 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	RuntimeModePrimary   = "primary"
	RuntimeModeSecondary = "secondary"
)
View Source
const (
	SecondaryZoneSyncTransfer = "transfer"
	SecondaryZoneSyncPush     = "push"
)
View Source
const (
	// Where zones are saved in bind's config directory
	PrimaryZonePath = "/var/cache/bind"
	// Where bind's configuration is saved in bind's directory (master)
	PrimaryBindConfigPath = "/etc/bind/named.conf.rosti"
	// Where bind's configuration is saved in bind's directory (slave)
	SecondaryBindConfigPath = "/etc/bind/named.conf.rosti"

	RECORD_NOT_FOUND_MESSAGE = "record not found"
)

Variables

This section is empty.

Functions

func ChangeOwnerHandler

func ChangeOwnerHandler(c echo.Context) error

@Summary Change zone owner @Description Change the owner of a zone. Optionally pass ?owner= to require the zone to currently belong to that owner before the change is applied (returns 404 if not). @ID change-zone-owner @Tags zones @Security ApiKeyAuth @Accept json @Produce json @Param zone_id path int true "Zone ID" @Param owner query string false "Require zone to be owned by this owner (returns 404 if not)" @Param body body ChangeOwnerRequest true "New owner" @Success 200 {object} Zone @Failure 400 {object} ErrorResponse @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /zones/{zone_id}/owner [patch]

func Commit

func Commit(zoneId uint) error

Write new zone into DNS servers

func CommitAllHandler

func CommitAllHandler(c echo.Context) error

@Summary Commit all zones @Description Commit every zone in the database, regenerating zone files and syncing to secondaries. Returns the count of successfully committed zones. @ID commit-all-zones @Tags zones @Security ApiKeyAuth @Produce json @Success 200 {object} map[string]int @Failure 500 {object} ErrorResponse @Router /zones/commit-all [put]

func CommitAllZones

func CommitAllZones() (int, error)

CommitAllZones commits every zone in the database in bulk, avoiding the named.conf write/reload race that occurs when calling Commit() per zone. Zone files are written sequentially, then named.conf is written and bind is reloaded exactly once. Secondary sync and transfer happen in goroutines.

func CommitHandler

func CommitHandler(c echo.Context) error

@Summary Commit zone @Description Write zone changes into DNS servers. @ID commit-zone @Tags zones @Security ApiKeyAuth @Produce json @Param zone_id path int true "Zone ID" @Param owner query string false "Require zone to be owned by this owner (returns 404 if not)" @Success 200 {object} MessageResponse @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /zones/{zone_id}/commit [put]

func DeleteRecord

func DeleteRecord(zoneId uint, recordId uint) error

Delete existing record

func DeleteRecordHandler

func DeleteRecordHandler(c echo.Context) error

@Summary Delete record @Description Delete a record within a zone. @ID delete-record @Tags records @Security ApiKeyAuth @Produce json @Param zone_id path int true "Zone ID" @Param record_id path int true "Record ID" @Param owner query string false "Require zone to be owned by this owner (returns 404 if not)" @Success 200 {object} MessageResponse @Failure 404 {object} ErrorResponse @Failure 400 {object} ErrorResponse @Router /zones/{zone_id}/records/{record_id} [delete]

func DeleteZone

func DeleteZone(zoneId uint) error

Delete existing zone

func DeleteZoneFile

func DeleteZoneFile(domain string) error

DeleteZoneFile removes a zone file. Returns nil if the file does not exist.

func DeleteZoneFileHandler

func DeleteZoneFileHandler(c echo.Context) error

@Summary Delete zone file (secondary mode) @Description Removes a zone file from the bind zone directory. @ID delete-zone-file @Tags secondary @Security ApiKeyAuth @Param domain path string true "Zone domain name" @Produce json @Success 200 {object} MessageResponse @Failure 400 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /bind/zones/{domain} [delete]

func DeleteZoneHandler

func DeleteZoneHandler(c echo.Context) error

@Summary Delete zone @Description Delete a zone and all its records. @ID delete-zone @Tags zones @Security ApiKeyAuth @Produce json @Param zone_id path int true "Zone ID" @Param owner query string false "Require zone to be owned by this owner (returns 404 if not)" @Success 200 {object} MessageResponse @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /zones/{zone_id} [delete]

func DeleteZoneOnSecondary

func DeleteZoneOnSecondary(secondaryURL, token, domain string) error

DeleteZoneOnSecondary removes a zone file on a secondary instance.

func FetchConfigData

func FetchConfigData()

func GetDNSSECStatusHandler

func GetDNSSECStatusHandler(c echo.Context) error

@Summary Get DNSSEC status @Description Return DNSSEC status and DS records for a zone. DS records are generated by BIND asynchronously; the pending field is true while BIND has not yet created the keys. @ID get-dnssec-status @Tags zones @Security ApiKeyAuth @Produce json @Param zone_id path int true "Zone ID" @Param owner query string false "Require zone to be owned by this owner (returns 404 if not)" @Success 200 {object} DNSSECStatusResponse @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /zones/{zone_id}/dnssec [get]

func GetDSRecords

func GetDSRecords(domain string) ([]string, error)

GetDSRecords returns the DS record lines for a domain by examining KSK/CSK key files in config.DNSSECKeyDirectory and computing DS records in pure Go. Returns an empty slice (not an error) when no key files exist yet — BIND generates them asynchronously after the first reload with dnssec-policy enabled.

func GetDatabaseConnection

func GetDatabaseConnection() *gorm.DB

func GetMetricsHandler

func GetMetricsHandler(c echo.Context) error

@Summary Metrics @Description Return prometheus metrics. @ID metrics @Tags default @Produce plain @Success 200 {string} string @Failure 500 {object} ErrorResponse @Router /metrics [get]

func GetRecordHandler

func GetRecordHandler(c echo.Context) error

@Summary Get record @Description Return one record within a zone. @ID get-record @Tags records @Security ApiKeyAuth @Produce json @Param zone_id path int true "Zone ID" @Param record_id path int true "Record ID" @Param owner query string false "Require zone to be owned by this owner (returns 404 if not)" @Success 200 {object} Record @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /zones/{zone_id}/records/{record_id} [get]

func GetRecordsHandler

func GetRecordsHandler(c echo.Context) error

@Summary List records @Description Return all records for a zone. @ID get-records @Tags records @Security ApiKeyAuth @Produce json @Param zone_id path int true "Zone ID" @Param owner query string false "Require zone to be owned by this owner (returns 404 if not)" @Success 200 {array} Record @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /zones/{zone_id}/records/ [get]

func GetZoneHandler

func GetZoneHandler(c echo.Context) error

@Summary Get zone @Description Return one zone including records. @ID get-zone @Tags zones @Security ApiKeyAuth @Produce json @Param zone_id path int true "Zone ID" @Param owner query string false "Require zone to be owned by this owner (returns 404 if not)" @Success 200 {object} Zone @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /zones/{zone_id} [get]

func GetZonesHandler

func GetZonesHandler(c echo.Context) error

@Summary List zones @Description Return all zones including records. Optionally filter by owner using the `owner` query parameter. @ID get-zones @Tags zones @Security ApiKeyAuth @Produce json @Param owner query string false "Filter zones by owner" @Success 200 {array} Zone @Failure 500 {object} ErrorResponse @Router /zones/ [get]

func IsValidDomain

func IsValidDomain(domain string) bool

IsValidDomain returns true when domain looks like a proper DNS zone name.

func NewRecordHandler

func NewRecordHandler(c echo.Context) error

@Summary Create record @Description Create a new record in a zone. Call commit afterwards to write it to bind. @ID create-record @Tags records @Security ApiKeyAuth @Accept json @Produce json @Param zone_id path int true "Zone ID" @Param owner query string false "Require zone to be owned by this owner (returns 404 if not)" @Param record body CreateRecordRequest true "Record payload" @Success 201 {object} Record @Failure 400 {object} ErrorResponse @Failure 404 {object} ErrorResponse @Router /zones/{zone_id}/records/ [post]

func NewZoneHandler

func NewZoneHandler(c echo.Context) error

@Summary Create zone @Description Create a new zone. @ID create-zone @Tags zones @Security ApiKeyAuth @Accept json @Produce json @Param zone body CreateZoneRequest true "Zone payload" @Success 201 {object} Zone @Failure 400 {object} ErrorResponse @Router /zones/ [post]

func PostBindReloadHandler

func PostBindReloadHandler(c echo.Context) error

@Summary Reload bind9 (secondary mode) @Description Reloads bind9 via the configured reload command. @ID post-bind-reload @Tags secondary @Security ApiKeyAuth @Produce json @Success 200 {object} MessageResponse @Failure 500 {object} ErrorResponse @Router /bind/reload [post]

func PostZoneRefreshHandler

func PostZoneRefreshHandler(c echo.Context) error

@Summary Refresh zone (secondary mode) @Description Forces a zone refresh using the configured refresh command. @ID post-zone-refresh @Tags secondary @Security ApiKeyAuth @Param domain path string true "Zone domain name" @Produce json @Success 200 {object} MessageResponse @Failure 400 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /bind/refresh/{domain} [post]

func PostZoneRetransferHandler

func PostZoneRetransferHandler(c echo.Context) error

@Summary Retransfer zone (secondary mode) @Description Forces a secondary zone transfer using the configured retransfer command. @ID post-zone-retransfer @Tags secondary @Security ApiKeyAuth @Param domain path string true "Zone domain name" @Produce json @Success 200 {object} MessageResponse @Failure 400 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /bind/retransfer/{domain} [post]

func PutBindConfigHandler

func PutBindConfigHandler(c echo.Context) error

@Summary Write bind config (secondary mode) @Description Receives a rendered named.conf include file, writes it to disk, and reloads bind9. @ID put-bind-config @Tags secondary @Security ApiKeyAuth @Accept plain @Produce json @Success 200 {object} MessageResponse @Failure 500 {object} ErrorResponse @Router /bind/config [put]

func PutZoneFileHandler

func PutZoneFileHandler(c echo.Context) error

@Summary Write zone file (secondary mode) @Description Receives a zone file and writes it to the bind zone directory. @ID put-zone-file @Tags secondary @Security ApiKeyAuth @Accept plain @Param domain path string true "Zone domain name" @Produce json @Success 200 {object} MessageResponse @Failure 400 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /bind/zones/{domain} [put]

func RefreshZone

func RefreshZone(domain string) error

RefreshZone forces a zone refresh using the configured refresh command.

func RefreshZoneOnSecondary

func RefreshZoneOnSecondary(secondaryURL, token, domain string) error

RefreshZoneOnSecondary asks a secondary instance to run the refresh command for the given zone.

func ReloadBind

func ReloadBind() error

ReloadBind reloads bind9 using the configured reload command.

func RetransferZone

func RetransferZone(domain string) error

RetransferZone forces a secondary zone transfer, bypassing SOA serial comparison.

func RetransferZoneOnSecondary

func RetransferZoneOnSecondary(secondaryURL, token, domain string) error

RetransferZoneOnSecondary asks a secondary instance to force-transfer the given zone.

func Run

func Run()

func SentryMiddleware

func SentryMiddleware(next echo.HandlerFunc) echo.HandlerFunc

func SetDNSSEC

func SetDNSSEC(zoneId uint, enabled bool) error

SetDNSSEC enables or disables DNSSEC for the zone, commits it and rebuilds the primary bind config.

func SetDNSSECHandler

func SetDNSSECHandler(c echo.Context) error

@Summary Set DNSSEC @Description Enable or disable DNSSEC for a zone. When enabled, the zone is committed and BIND generates signing keys automatically using dnssec-policy default (ECDSAP256SHA256 + NSEC3). DS records become available via GET /zones/:zone_id/dnssec once BIND has generated the keys (typically within 30 seconds). @ID set-dnssec @Tags zones @Security ApiKeyAuth @Accept json @Produce json @Param zone_id path int true "Zone ID" @Param owner query string false "Require zone to be owned by this owner (returns 404 if not)" @Param body body SetDNSSECRequest true "DNSSEC toggle" @Success 200 {object} DNSSECStatusResponse @Failure 400 {object} ErrorResponse @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /zones/{zone_id}/dnssec [put]

func SetMasterBindConfig

func SetMasterBindConfig()

SetMasterBindConfig generates the primary bind config from the DB, writes it locally, then reloads bind.

func SetNameServerIPs

func SetNameServerIPs()

If necessary, this takes PrimaryNameServer and NameServers domain names and resolves IP addresses for PrimaryNameServerIP and SecondaryNameServerIPs. Panic in case of fire!

func SetSlavesBindConfig

func SetSlavesBindConfig()

SetSlavesBindConfig generates the secondary bind config from the DB and pushes it to all secondary instances.

func SyncBindConfigToSecondary

func SyncBindConfigToSecondary(secondaryURL, token, content string) error

SyncBindConfigToSecondary pushes a rendered bind config to a secondary instance.

func SyncZoneToSecondary

func SyncZoneToSecondary(secondaryURL, token, domain, content string) error

SyncZoneToSecondary pushes a zone file to a secondary instance.

func TestZoneHandler

func TestZoneHandler(c echo.Context) error

@Summary Test zone DNS @Description Compare zone records in the database against what the primary and secondary nameservers currently serve. @ID test-zone @Tags zones @Security ApiKeyAuth @Produce json @Param zone_id path int true "Zone ID" @Success 200 {object} DNSCheckResponse @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /zones/{zone_id}/test [get]

func TokenMiddleware

func TokenMiddleware(next echo.HandlerFunc) echo.HandlerFunc

Process is the middleware function.

func UpdateRecordHandler

func UpdateRecordHandler(c echo.Context) error

@Summary Update record @Description Update an existing record within a zone. Type cannot be changed; delete and recreate instead. Call commit afterwards. @ID update-record @Tags records @Security ApiKeyAuth @Accept json @Produce json @Param zone_id path int true "Zone ID" @Param record_id path int true "Record ID" @Param owner query string false "Require zone to be owned by this owner (returns 404 if not)" @Param record body UpdateRecordRequest true "Record fields to update" @Success 200 {object} Record @Failure 400 {object} ErrorResponse @Failure 404 {object} ErrorResponse @Router /zones/{zone_id}/records/{record_id} [put]

func UpdateZoneHandler

func UpdateZoneHandler(c echo.Context) error

@Summary Update zone @Description Update zone metadata (tags and abuse email only). Use the records endpoints to manage records. @ID update-zone @Tags zones @Security ApiKeyAuth @Accept json @Produce json @Param zone_id path int true "Zone ID" @Param owner query string false "Require zone to be owned by this owner (returns 404 if not)" @Param zone body UpdateZoneRequest true "Zone metadata to update" @Success 200 {object} Zone @Failure 400 {object} ErrorResponse @Failure 404 {object} ErrorResponse @Router /zones/{zone_id} [put]

func WriteBindConfig

func WriteBindConfig(configPath, content string) error

WriteBindConfig writes content to a named.conf include file at configPath.

func WriteZoneFile

func WriteZoneFile(domain, content string) error

WriteZoneFile writes a zone file to the bind zone directory.

func ZoneStatusHandler

func ZoneStatusHandler(c echo.Context) error

@Summary Zone status @Description Check whether the zone has uncommitted changes and whether it is configured on all nameservers. @ID zone-status @Tags zones @Security ApiKeyAuth @Produce json @Param zone_id path int true "Zone ID" @Success 200 {object} ZoneStatusResponse @Failure 404 {object} ErrorResponse @Failure 500 {object} ErrorResponse @Router /zones/{zone_id}/status [get]

Types

type ChangeOwnerRequest

type ChangeOwnerRequest struct {
	Owner string `json:"owner" example:"company1234"`
}

ChangeOwnerRequest is the body accepted by PATCH /zones/:zone_id/owner.

type Config

type Config struct {
	Mode                   string   `default:"primary" split_words:"true"`                // Runtime mode: primary or secondary
	PrimaryNameServerIP    string   `split_words:"true"`                                  // If not set, automatically resolved from PrimaryNameServer
	SecondaryNameServerIPs []string `envconfig:"SECONDARY_NAME_SERVER_IPS"`               // If not set, automatically resolved from NameServers
	ExtraAllowTransferIPs  []string `envconfig:"EXTRA_ALLOW_TRANSFER_IPS"`                // Additional IPs appended to allow-transfer in every primary zone block
	SecondaryInstances     []string `split_words:"true"`                                  // Secondary dnsapi instances for sync fanout
	PrimaryNameServer      string   `split_words:"true"`                                  // Bind's master server
	NameServers            []string `split_words:"true"`                                  // Bind's slave servers
	AbuseEmail             string   `split_words:"true"`                                  // Abuse email
	TimeToRefresh          int      `default:"300" split_words:"true"`                    // Time to refresh the records on slaves
	TimeToRetry            int      `default:"180" split_words:"true"`                    // Time to waif for another try if connection fails
	TimeToExpire           int      `default:"604800" split_words:"true"`                 // Time to expire when the domain is not available on master
	MinimalTTL             int      `default:"30" split_words:"true"`                     // Minimal TTL
	TTL                    int      `default:"3600"`                                      // Default TTL
	DatabasePath           string   `default:"gorm.sqlite" split_words:"true"`            // Path to the database
	BindReloadCommand      string   `default:"systemctl reload bind9" split_words:"true"` // Command used to reload bind9
	BindRefreshCommand     string   `default:"rndc refresh" split_words:"true"`           // Command used to refresh a zone (domain appended as last argument)
	BindRetransferCommand  string   `split_words:"true"`                                  // Command used to force a secondary zone transfer (domain appended as last argument)
	DNSSECKeyDirectory     string   `default:"/var/cache/bind/keys" split_words:"true"`   // Directory where BIND stores DNSSEC keys (used with dnssec-policy)
	SecondaryZoneSyncMode  string   `default:"transfer" split_words:"true"`               // Secondary zone sync mode: transfer or push
	APIToken               string   `default:"" envconfig:"API_TOKEN"`                    // Token to access the API
	PublicDomain           string   `split_words:"true"`                                  // Public domain for this instance
	HTTPS                  bool     `split_words:"true"`                                  // Serve HTTPS and obtain Let's Encrypt certs
	ACMEEmail              string   `split_words:"true"`                                  // Email for Let's Encrypt
	SentryDSN              string   `split_words:"true"`                                  // Sentry DSN
	SentryENV              string   `default:"dev" split_words:"true"`                    // Sentry environment
	Port                   uint16   `default:"1323"`                                      // Port where the API listens
}

Configuration struct. All input form the maintainer is available through this struct.

func (*Config) IsPrimaryMode

func (c *Config) IsPrimaryMode() bool

func (*Config) IsSecondaryMode

func (c *Config) IsSecondaryMode() bool

func (*Config) RenderEmail

func (c *Config) RenderEmail() string

Reformat the email so it can be used in zone files

func (*Config) SecondaryInstanceList

func (c *Config) SecondaryInstanceList() []string

func (*Config) UsesSecondaryZonePush

func (c *Config) UsesSecondaryZonePush() bool

func (*Config) Validate

func (c *Config) Validate() error

Validates data inside the config struct

type CreateRecordRequest

type CreateRecordRequest struct {
	Name  string `json:"name" example:"www"`
	TTL   int    `json:"ttl" example:"3600"`
	Type  string `json:"type" example:"A"`
	Prio  int    `json:"prio" example:"0"`
	Value string `json:"value" example:"1.2.3.4"`
}

CreateRecordRequest is the body accepted by POST /zones/:id/records/.

type CreateZoneRequest

type CreateZoneRequest struct {
	Domain     string `json:"domain" example:"example.com"`
	Tags       string `json:"tags" example:"tag1,tag2"`
	AbuseEmail string `json:"abuse_email" example:"admin@example.com"`
	Owner      string `json:"owner" example:"alice"`
}

CreateZoneRequest is the body accepted by POST /zones/.

type DNSCheckRecord

type DNSCheckRecord struct {
	RecordID        uint     `json:"record_id"`
	Name            string   `json:"name"`
	FQDN            string   `json:"fqdn"`
	Type            string   `json:"type"`
	DBValue         string   `json:"db_value"`
	PrimaryValues   []string `json:"primary_values"`
	SecondaryValues []string `json:"secondary_values"`
	PrimaryOK       bool     `json:"primary_ok"`
	SecondaryOK     bool     `json:"secondary_ok"`
	Supported       bool     `json:"supported"`
	Error           string   `json:"error,omitempty"`
}

DNSCheckRecord holds the comparison result for one zone record.

type DNSCheckResponse

type DNSCheckResponse struct {
	ZoneID      uint             `json:"zone_id"`
	Domain      string           `json:"domain"`
	PrimaryNS   string           `json:"primary_ns"`
	SecondaryNS []string         `json:"secondary_ns"`
	Records     []DNSCheckRecord `json:"records"`
}

DNSCheckResponse is the response body for TestZoneHandler.

type DNSKEYRecord

type DNSKEYRecord struct {
	Name      string `json:"name"`
	Flags     int    `json:"flags"`
	Protocol  int    `json:"protocol"`
	Algorithm int    `json:"algorithm"`
	Key       string `json:"key"`
	KeyTag    uint16 `json:"key_tag"`
	DNSKEY    string `json:"dnskey"`
}

DNSKEYRecord is a public DNSKEY record returned by DNSSEC status endpoints.

func GetDNSSECKeyRecords

func GetDNSSECKeyRecords(domain string) ([]string, []DNSKEYRecord, error)

GetDNSSECKeyRecords returns DS and DNSKEY records for KSK/CSK key files.

type DNSSECStatusResponse

type DNSSECStatusResponse struct {
	Enabled       bool           `json:"enabled"`
	Pending       bool           `json:"pending"`
	DSRecords     []string       `json:"ds_records"`
	DNSKEYRecords []DNSKEYRecord `json:"dnskey_records"`
}

DNSSECStatusResponse is returned by GET /zones/:zone_id/dnssec.

func GetDNSSECStatus

func GetDNSSECStatus(zoneId uint) (*DNSSECStatusResponse, error)

GetDNSSECStatus returns the current DNSSEC state for the zone, including any DNSSEC records that BIND has already generated. When enabled but keys are not yet available, Pending is true.

type ErrorResponse

type ErrorResponse struct {
	Message string `json:"message"`
}

type MessageResponse

type MessageResponse struct {
	Message string `json:"message"`
}

type Record

type Record struct {
	ID        uint      `json:"id" gorm:"primary_key"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`

	ZoneId uint `json:"-" sql:"index"`

	Name  string `json:"name"`
	TTL   int    `json:"ttl"`
	Type  string `json:"type"` // A, AAAA, CNAME, TXT, SRV
	Prio  int    `json:"prio"`
	Value string `json:"value"`
}

func NewRecord

func NewRecord(zoneId uint, name string, ttl int, recordType string, prio int, value string) (*Record, []error)

Create a new record

func UpdateRecord

func UpdateRecord(zoneId uint, recordId uint, name string, ttl int, prio int, value string) (*Record, []error)

UpdateRecord updates existing record

func (*Record) Render

func (r *Record) Render() string

Render renders one record

func (*Record) Validate

func (r *Record) Validate() error

Validates the record

type SetDNSSECRequest

type SetDNSSECRequest struct {
	Enabled bool `json:"enabled" example:"true"`
}

SetDNSSECRequest is the body accepted by PUT /zones/:zone_id/dnssec.

type UpdateRecordRequest

type UpdateRecordRequest struct {
	Name  string `json:"name" example:"www"`
	TTL   int    `json:"ttl" example:"3600"`
	Prio  int    `json:"prio" example:"0"`
	Value string `json:"value" example:"1.2.3.4"`
}

UpdateRecordRequest is the body accepted by PUT /zones/:id/records/:record_id. Type cannot be changed; delete and recreate the record instead.

type UpdateZoneRequest

type UpdateZoneRequest struct {
	Tags       string `json:"tags" example:"tag1,tag2"`
	AbuseEmail string `json:"abuse_email" example:"admin@example.com"`
	Owner      string `json:"owner" example:"alice"`
}

UpdateZoneRequest is the body accepted by PUT /zones/:id. Only tags, abuse_email and owner can be changed; domain and records are managed separately.

type Zone

type Zone struct {
	ID        uint      `json:"id" gorm:"primary_key"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	Delete    bool      `json:"delete" gorm:"DEFAULT:0"`

	Domain          string   `json:"domain" sql:"index"`
	Serial          string   `json:"serial"`
	CommittedSerial string   `json:"committed_serial"`
	Records         []Record `json:"records" gorm:"foreignkey:ZoneID"`
	Tags            string   `json:"tags"` // Tags separated by comma
	AbuseEmail      string   `json:"abuse_email"`
	Owner           string   `json:"owner"`
	DNSSECEnabled   bool     `json:"dnssec_enabled" gorm:"column:dnssec_enabled;DEFAULT:0"`
}
Example
// A valid zone
zone, errs := NewZone("B-"+TEST_DOMAIN, []string{"test_tag_1", "test_tag_2"}, TEST_ABUSE_EMAIL, "testowner")
if len(errs) != 0 {
	panic(errs)
}
zone.SetNewSerial()

zone.AddRecord("@", 300, "A", 0, "1.2.3.4")
zone.AddRecord("@", 300, "AAAA", 0, "2001::2")
zone.AddRecord("www", 300, "CNAME", 0, "@")
zone.AddRecord("@", 300, "MX", 10, "mail.rosti.cz.")
zone.AddRecord("@", 300, "TXT", 0, "igeeweofeiroomoogokieghaithohthaechoocherohveehiebawuyeixeecoveegoeyohfachainauquaeceetipheivubohmoegheizeelaiquanaokooquiedokaidurahveehoshazaseveitheiyitachudiishaeghaexoovachacaijuyiedeochojingafeexusuquaingeiboovachahlaechahcashoophairohthaghobahjaixieboteixameimohmaedahriebaekoshohpeecueyaoseeveibavaithohquaevoalohreingewiesaijiojiehielahzaelohpechuohiefaeyaetiegengahgatheefaipeimeeviedimibohmoyajefahghaaraehieyiepameegheathaechielixahbeidohyaitionahjaenoshikahbahyaebeachahxalaeghuloochaekuthaiquaedoo")
zone.Serial = "2018053001"
renderedZone := zone.Render()

h := sha256.New()
h.Write([]byte(renderedZone))
fmt.Printf("%x", h.Sum(nil))
Output:
635d2be2a44773e301a0938357b868dbfe5282b2e516e28d21c4b0e41d642333

func ChangeOwner

func ChangeOwner(zoneId uint, owner string) (*Zone, error)

ChangeOwner updates only the owner field of an existing zone.

func NewZone

func NewZone(domain string, tags []string, abuseEmail string, owner string) (*Zone, []error)

Create a new zone

func UpdateZone

func UpdateZone(zoneId uint, tags []string, abuseEmail string, owner string) (*Zone, []error)

Update existing zone

func (*Zone) AddRecord

func (z *Zone) AddRecord(name string, ttl int, recordType string, prio int, value string) (*Record, []error)

func (*Zone) Render

func (z *Zone) Render() string

Renders whole zone

func (*Zone) RenderAbuseEmail

func (z *Zone) RenderAbuseEmail() string

func (*Zone) RenderPrimary

func (z *Zone) RenderPrimary() string
Example
zone, errs := NewZone("C-"+TEST_DOMAIN, []string{"test_tag_1", "test_tag_2"}, TEST_ABUSE_EMAIL, "testowner")
if len(errs) != 0 {
	panic(errs)
}
zone.SetNewSerial()

zone.AddRecord("@", 300, "A", 0, "1.2.3.4")

fmt.Println(zone.RenderPrimary())
Output:
zone "c-ohphiuhi.txt" IN {
        type master;
        masterfile-format text;
        file "c-ohphiuhi.txt.zone";
        allow-query { any; };
        allow-transfer { 5.6.7.8; };
        notify yes;
};

func (*Zone) RenderSecondary

func (z *Zone) RenderSecondary() string
Example
zone, errs := NewZone("D-"+TEST_DOMAIN, []string{"test_tag_1", "test_tag_2"}, TEST_ABUSE_EMAIL, "testowner")
if len(errs) != 0 {
	panic(errs)
}
zone.SetNewSerial()

zone.AddRecord("@", 300, "A", 0, "1.2.3.4")

fmt.Println(zone.RenderSecondary())
Output:
zone "d-ohphiuhi.txt" IN {
    type slave;
    masterfile-format text;
    file "d-ohphiuhi.txt.zone";
    allow-query { any; };
    masters { 1.2.3.4; };
};

func (*Zone) SetNewSerial

func (z *Zone) SetNewSerial()

func (*Zone) Validate

func (z *Zone) Validate() []error

Validates records in the zone

type ZoneNSStatus

type ZoneNSStatus struct {
	IP         string `json:"ip"`
	Configured bool   `json:"configured"`
	Error      string `json:"error,omitempty"`
}

ZoneNSStatus is the NS-reachability result for one nameserver.

type ZoneStatusResponse

type ZoneStatusResponse struct {
	ZoneID          uint           `json:"zone_id"`
	Domain          string         `json:"domain"`
	DBSerial        string         `json:"db_serial"`
	CommittedSerial string         `json:"committed_serial"`
	NeedsCommit     bool           `json:"needs_commit"`
	Primary         ZoneNSStatus   `json:"primary"`
	Secondary       []ZoneNSStatus `json:"secondary"`
	AllConfigured   bool           `json:"all_configured"`
}

ZoneStatusResponse is returned by GET /zones/:zone_id/status.

Jump to

Keyboard shortcuts

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