Skip to content

Commit a12834a

Browse files
committed
feat: add NS record support
- support NS record creation Signed-off-by: Brian Richardson <[email protected]>
1 parent 1a4a305 commit a12834a

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

internal/infoblox/common.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,21 @@ func ToCNAMEResponseMap(res []ibclient.RecordCNAME) *ResponseMap {
6767
return rm
6868
}
6969

70+
func ToNSResponseMap(res []ibclient.RecordNS) *ResponseMap {
71+
rm := &ResponseMap{
72+
Map: make(map[string]ResponseDetails),
73+
RecordType: ibclient.ZoneDelegatedConst,
74+
}
75+
for _, record := range res {
76+
if _, ok := rm.Map[record.Name]; !ok {
77+
rm.Map[record.Name] = ResponseDetails{{Target: AsString(record.Nameserver)}}
78+
continue
79+
}
80+
rm.Map[record.Name] = append(rm.Map[record.Name], ResponseDetail{Target: AsString(record.Nameserver)})
81+
}
82+
return rm
83+
}
84+
7085
func ToTXTResponseMap(res []ibclient.RecordTXT) *ResponseMap {
7186
rm := &ResponseMap{
7287
Map: make(map[string]ResponseDetails),

internal/infoblox/infoblox.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,17 @@ func (p *Provider) Records(_ context.Context) (endpoints []*endpoint.Endpoint, e
241241
endpointsTXT := ToTXTResponseMap(resT).ToEndpoints()
242242
endpoints = append(endpoints, endpointsTXT...)
243243

244+
var resNS []ibclient.RecordNS
245+
objNS := ibclient.NewEmptyRecordNS()
246+
objNS.View = p.config.View
247+
objNS.Zone = zone.Fqdn
248+
err = PagingGetObject(p.client, objNS, "", searchParams, &resNS)
249+
if err != nil && !isNotFoundError(err) {
250+
return nil, fmt.Errorf("could not fetch NS records from zone '%s': %w", zone.Fqdn, err)
251+
}
252+
endpointsNS := ToNSResponseMap(resNS).ToEndpoints()
253+
endpoints = append(endpoints, endpointsNS...)
254+
244255
if p.config.CreatePTR {
245256
arpaZone, err := rfc2317.CidrToInAddr(zone.Fqdn)
246257
if err == nil {
@@ -451,6 +462,13 @@ func getRefID(record *infobloxRecordSet) (string, log.Fields, error) {
451462
return r.Ref, l, nil
452463
}
453464
return "", l, nil
465+
case "RecordNS":
466+
l["record"] = record.obj.(*ibclient.RecordNS).Name
467+
l["target"] = AsString(record.obj.(*ibclient.RecordNS).Nameserver)
468+
for _, r := range *record.res.(*[]ibclient.RecordNS) {
469+
return r.Ref, l, nil
470+
}
471+
return "", l, nil
454472
}
455473
return "", l, fmt.Errorf("unknown type '%s'", t)
456474
}
@@ -758,6 +776,26 @@ func (p *Provider) recordSet(ep *endpoint.Endpoint, getObject bool) (recordSet i
758776
obj: obj,
759777
res: &res,
760778
}
779+
case endpoint.RecordTypeNS:
780+
var res []ibclient.RecordNS
781+
obj := ibclient.NewEmptyRecordNS()
782+
obj.Name = ep.DNSName
783+
obj.Nameserver = &ep.Targets[0]
784+
if getObject {
785+
queryParams := ibclient.NewQueryParams(false, map[string]string{"name": obj.Name})
786+
err = p.client.GetObject(obj, "", queryParams, &res)
787+
if err != nil && !isNotFoundError(err) {
788+
return
789+
}
790+
} else {
791+
// If getObject is not set (action == create), we need to set the View for Infoblox to find the parent zone
792+
// If View is set for the other actions, Infoblox will complain that the view field is not allowed
793+
obj.View = p.config.View
794+
}
795+
recordSet = infobloxRecordSet{
796+
obj: obj,
797+
res: &res,
798+
}
761799
case endpoint.RecordTypeTXT:
762800
var res []ibclient.RecordTXT
763801
// The Infoblox API strips enclosing double quotes from TXT records lacking whitespace.

0 commit comments

Comments
 (0)