mirror of
https://github.com/gravitl/netmaker.git
synced 2026-01-20 18:17:30 +08:00
* NM-195: add key tags info to posture check on join * NM-195: add network user grps to posture check * NM-195: add posture checks to middleware * fix: return error when group network roles are set for specific networks and all networks; * add all posture check to rsrc permission check func * NM-202: fix egress domain routing * fix: add username filter; * feat: add fallback nameserver support; * fix: add validation for pro as well; * fix: skip fallback domains for user gws; * fix: don't set domains for fallback dns servers; * fix: validation fixes; * fix: empty match domains for fallback nameservers; --------- Co-authored-by: VishalDalwadi <dalwadivishal26@gmail.com>
77 lines
3.1 KiB
Go
77 lines
3.1 KiB
Go
package schema
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/gravitl/netmaker/db"
|
|
"gorm.io/datatypes"
|
|
)
|
|
|
|
type Nameserver struct {
|
|
ID string `gorm:"primaryKey" json:"id"`
|
|
Name string `gorm:"name" json:"name"`
|
|
NetworkID string `gorm:"network_id" json:"network_id"`
|
|
Description string `gorm:"description" json:"description"`
|
|
Default bool `gorm:"column:default" json:"default"`
|
|
Fallback bool `gorm:"fallback" json:"fallback"`
|
|
Servers datatypes.JSONSlice[string] `gorm:"servers" json:"servers"`
|
|
MatchAll bool `gorm:"match_all" json:"match_all"`
|
|
Domains datatypes.JSONSlice[NameserverDomain] `gorm:"domains" json:"domains"`
|
|
// TODO: deprecate
|
|
MatchDomains datatypes.JSONSlice[string] `gorm:"match_domains" json:"match_domains"`
|
|
Tags datatypes.JSONMap `gorm:"tags" json:"tags"`
|
|
Nodes datatypes.JSONMap `gorm:"nodes" json:"nodes"`
|
|
Status bool `gorm:"status" json:"status"`
|
|
CreatedBy string `gorm:"created_by" json:"created_by"`
|
|
CreatedAt time.Time `gorm:"created_at" json:"created_at"`
|
|
UpdatedAt time.Time `gorm:"updated_at" json:"updated_at"`
|
|
}
|
|
|
|
type NameserverDomain struct {
|
|
Domain string `json:"domain"`
|
|
IsSearchDomain bool `json:"is_search_domain"`
|
|
}
|
|
|
|
func (ns *Nameserver) Get(ctx context.Context) error {
|
|
return db.FromContext(ctx).Model(&Nameserver{}).First(&ns).Where("id = ?", ns.ID).Error
|
|
}
|
|
|
|
func (ns *Nameserver) Update(ctx context.Context) error {
|
|
return db.FromContext(ctx).Model(&Nameserver{}).Where("id = ?", ns.ID).Updates(&ns).Error
|
|
}
|
|
|
|
func (ns *Nameserver) Create(ctx context.Context) error {
|
|
return db.FromContext(ctx).Model(&Nameserver{}).Create(&ns).Error
|
|
}
|
|
|
|
func (ns *Nameserver) ListByNetwork(ctx context.Context) (dnsli []Nameserver, err error) {
|
|
err = db.FromContext(ctx).Model(&Nameserver{}).Where("network_id = ?", ns.NetworkID).Find(&dnsli).Error
|
|
return
|
|
}
|
|
|
|
func (ns *Nameserver) Delete(ctx context.Context) error {
|
|
return db.FromContext(ctx).Model(&Nameserver{}).Where("id = ?", ns.ID).Delete(&ns).Error
|
|
}
|
|
|
|
func (ns *Nameserver) DeleteByNetwork(ctx context.Context) error {
|
|
return db.FromContext(ctx).Model(&Nameserver{}).Where("network_id = ?", ns.NetworkID).Delete(&ns).Error
|
|
}
|
|
|
|
func (ns *Nameserver) UpdateStatus(ctx context.Context) error {
|
|
return db.FromContext(ctx).Model(&Nameserver{}).Where("id = ?", ns.ID).Updates(map[string]any{
|
|
"status": ns.Status,
|
|
}).Error
|
|
}
|
|
|
|
func (ns *Nameserver) UpdateMatchAll(ctx context.Context) error {
|
|
return db.FromContext(ctx).Model(&Nameserver{}).Where("id = ?", ns.ID).Updates(map[string]any{
|
|
"match_all": ns.MatchAll,
|
|
}).Error
|
|
}
|
|
|
|
func (ns *Nameserver) UpdateFallback(ctx context.Context) error {
|
|
return db.FromContext(ctx).Model(&Nameserver{}).Where("id = ?", ns.ID).Updates(map[string]any{
|
|
"fallback": ns.Fallback,
|
|
}).Error
|
|
}
|