File tree Expand file tree Collapse file tree 4 files changed +82
-2
lines changed Expand file tree Collapse file tree 4 files changed +82
-2
lines changed Original file line number Diff line number Diff line change @@ -90,6 +90,11 @@ func createNs(w http.ResponseWriter, r *http.Request) {
90
90
if gNs , ok := logic .GlobalNsList [req .Name ]; ok {
91
91
req .Servers = gNs .IPs
92
92
}
93
+ if ! servercfg .IsPro {
94
+ req .Tags = datatypes.JSONMap {
95
+ "*" : struct {}{},
96
+ }
97
+ }
93
98
ns := schema.Nameserver {
94
99
ID : uuid .New ().String (),
95
100
Name : req .Name ,
@@ -222,6 +227,7 @@ func updateNs(w http.ResponseWriter, r *http.Request) {
222
227
}
223
228
ns .Servers = updateNs .Servers
224
229
ns .Tags = updateNs .Tags
230
+ ns .MatchDomain = updateNs .MatchDomain
225
231
ns .Description = updateNs .Description
226
232
ns .Name = updateNs .Name
227
233
ns .Status = updateNs .Status
Original file line number Diff line number Diff line change @@ -394,6 +394,44 @@ func ValidateUpdateNameserverReq(updateNs schema.Nameserver) error {
394
394
return nil
395
395
}
396
396
397
+ func GetNameserversForNode (node * models.Node ) (returnNsLi []models.Nameserver ) {
398
+ ns := & schema.Nameserver {
399
+ NetworkID : node .Network ,
400
+ }
401
+ nsLi , _ := ns .ListByNetwork (db .WithContext (context .TODO ()))
402
+ for _ , nsI := range nsLi {
403
+ if ! nsI .Status {
404
+ continue
405
+ }
406
+ _ , all := nsI .Tags ["*" ]
407
+ if all {
408
+ returnNsLi = append (returnNsLi , models.Nameserver {
409
+ IPs : nsI .Servers ,
410
+ MatchDomain : nsI .MatchDomain ,
411
+ })
412
+ continue
413
+ }
414
+ for tagI := range node .Tags {
415
+ if _ , ok := nsI .Tags [tagI .String ()]; ok {
416
+ returnNsLi = append (returnNsLi , models.Nameserver {
417
+ IPs : nsI .Servers ,
418
+ MatchDomain : nsI .MatchDomain ,
419
+ })
420
+ }
421
+ }
422
+ }
423
+ if node .IsInternetGateway {
424
+ globalNs := models.Nameserver {
425
+ MatchDomain : "." ,
426
+ }
427
+ for _ , nsI := range GlobalNsList {
428
+ globalNs .IPs = append (globalNs .IPs , nsI .IPs ... )
429
+ }
430
+ returnNsLi = append (returnNsLi , globalNs )
431
+ }
432
+ return
433
+ }
434
+
397
435
func GetNameserversForHost (h * models.Host ) (returnNsLi []models.Nameserver ) {
398
436
if h .DNS != "yes" {
399
437
return
Original file line number Diff line number Diff line change @@ -1328,7 +1328,7 @@ func getUserRemoteAccessGwsV1(w http.ResponseWriter, r *http.Request) {
1328
1328
Addresses : utils .NoEmptyStringToCsv (node .Address .String (), node .Address6 .String ()),
1329
1329
}
1330
1330
if ! node .IsInternetGateway {
1331
- hNs := logic .GetNameserversForHost ( host )
1331
+ hNs := logic .GetNameserversForNode ( & node )
1332
1332
for _ , nsI := range hNs {
1333
1333
gw .MatchDomains = append (gw .MatchDomains , nsI .MatchDomain )
1334
1334
}
@@ -1379,7 +1379,7 @@ func getUserRemoteAccessGwsV1(w http.ResponseWriter, r *http.Request) {
1379
1379
Addresses : utils .NoEmptyStringToCsv (node .Address .String (), node .Address6 .String ()),
1380
1380
}
1381
1381
if ! node .IsInternetGateway {
1382
- hNs := logic .GetNameserversForHost ( host )
1382
+ hNs := logic .GetNameserversForNode ( & node )
1383
1383
for _ , nsI := range hNs {
1384
1384
gw .MatchDomains = append (gw .MatchDomains , nsI .MatchDomain )
1385
1385
}
Original file line number Diff line number Diff line change
1
+ package logic
2
+
3
+ import (
4
+ "errors"
5
+
6
+ "github.com/gravitl/netmaker/logic"
7
+ "github.com/gravitl/netmaker/models"
8
+ "github.com/gravitl/netmaker/schema"
9
+ )
10
+
11
+ func ValidateNameserverReq (ns schema.Nameserver ) error {
12
+ if ns .Name == "" {
13
+ return errors .New ("name is required" )
14
+ }
15
+ if ns .NetworkID == "" {
16
+ return errors .New ("network is required" )
17
+ }
18
+ if len (ns .Servers ) == 0 {
19
+ return errors .New ("atleast one nameserver should be specified" )
20
+ }
21
+ if ! logic .IsValidMatchDomain (ns .MatchDomain ) {
22
+ return errors .New ("invalid match domain" )
23
+ }
24
+ if len (ns .Tags ) > 0 {
25
+ for tagI := range ns .Tags {
26
+ if tagI == "*" {
27
+ continue
28
+ }
29
+ _ , err := GetTag (models .TagID (tagI ))
30
+ if err != nil {
31
+ return errors .New ("invalid tag" )
32
+ }
33
+ }
34
+ }
35
+ return nil
36
+ }
You can’t perform that action at this time.
0 commit comments