package api import "gorm.io/gorm" const ( keyPrincipalContextID key = iota ) type key int // ZoneRequest represents a new zone file request. // // Inside it is a pointer to the zone struct, which contains zone file information, and a User field to keep track of whom owns the file/request. type ZoneRequest struct { *Zone User string `json:"user,omitempty" gorm:"foreignKey:username;references:User"` } // Zone struct represents a zone file. type Zone struct { gorm.Model // FileName is the file name for an uploaded zone file how it is expected to show up on the filesystem FileName string `json:"name"` // Body is the bytes array of a zone files body for copying and moving it around Body []byte `json:"body,omitempty"` } // GenericResponse is a generics wrapper to send responses for API Errors. type GenericResponse[T map[string]any] struct { Response map[string]any `json:"response,omitempty"` } // instead of calling map[string]any{...} you can call genericResponseFields{...} when making a generic response above. type genericResponseFields map[string]any // ndr is an interface for new DNS requests. It's methods can be used with a ZoneRequest object. type ndr interface { // parse() is a wrapper around miekg's NewZoneParser, which is used to validate uploaded zone files // // if no error is raised the zone file can be saved. parse() error // save() is a wrapper around internal.makeLocal() which will save a valid non-empty zone file to the filesystem // // the file is saved to a location the user sets up in their config.yaml file, // once saved it can be consumed by something like NSD. save() error } var _ ndr = (*ZoneRequest)(nil)