From cb5f4f94ed04ecf910d44c68474566fbc235d08a Mon Sep 17 00:00:00 2001 From: Pieter Lexis Date: Mon, 3 Jul 2023 14:48:39 +0200 Subject: [PATCH 1/4] Add NS Group to zone_delegated object --- objects.go | 3 ++- objects_test.go | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/objects.go b/objects.go index 6ed5f2a8..c5ac8a1b 100644 --- a/objects.go +++ b/objects.go @@ -936,12 +936,13 @@ type ZoneDelegated struct { DelegateTo []NameServer `json:"delegate_to,omitempty"` View string `json:"view,omitempty"` Ea EA `json:"extattrs"` + NsGroup string `json:"ns_group,omitempty"` } func NewZoneDelegated(za ZoneDelegated) *ZoneDelegated { res := za res.objectType = "zone_delegated" - res.returnFields = []string{"extattrs", "fqdn", "view", "delegate_to"} + res.returnFields = []string{"extattrs", "fqdn", "view", "delegate_to", "ns_group"} return &res } diff --git a/objects_test.go b/objects_test.go index 0b039357..8da50fac 100644 --- a/objects_test.go +++ b/objects_test.go @@ -743,7 +743,7 @@ var _ = Describe("Objects", func() { It("should set base fields correctly", func() { Expect(za.ObjectType()).To(Equal("zone_delegated")) - Expect(za.ReturnFields()).To(ConsistOf("extattrs", "fqdn", "view", "delegate_to")) + Expect(za.ReturnFields()).To(ConsistOf("extattrs", "fqdn", "view", "delegate_to", "ns_group")) }) }) From 7fa142b1d6fbe1028d4beca82f426528bbf453c2 Mon Sep 17 00:00:00 2001 From: Pieter Lexis Date: Mon, 3 Jul 2023 14:51:51 +0200 Subject: [PATCH 2/4] Hook up ns_group to ZoneDelegated Create and Update --- object_manager.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/object_manager.go b/object_manager.go index d45d5aca..82a12b1d 100644 --- a/object_manager.go +++ b/object_manager.go @@ -28,7 +28,7 @@ type IBObjectManager interface { CreatePTRRecord(networkView string, dnsView string, ptrdname string, recordName string, cidr string, ipAddr string, useTtl bool, ttl uint32, comment string, eas EA) (*RecordPTR, error) CreateSRVRecord(dnsView string, name string, priority uint32, weight uint32, port uint32, target string, ttl uint32, useTtl bool, comment string, eas EA) (*RecordSRV, error) CreateTXTRecord(dnsView string, recordName string, text string, ttl uint32, useTtl bool, comment string, eas EA) (*RecordTXT, error) - CreateZoneDelegated(fqdn string, delegate_to []NameServer) (*ZoneDelegated, error) + CreateZoneDelegated(fqdn string, delegate_to []NameServer, NsGroup string) (*ZoneDelegated, error) DeleteARecord(ref string) (string, error) DeleteAAAARecord(ref string) (string, error) DeleteZoneAuth(ref string) (string, error) @@ -90,7 +90,7 @@ type IBObjectManager interface { UpdateSRVRecord(ref string, name string, priority uint32, weight uint32, port uint32, target string, ttl uint32, useTtl bool, comment string, eas EA) (*RecordSRV, error) UpdateTXTRecord(ref string, recordName string, text string, ttl uint32, useTtl bool, comment string, eas EA) (*RecordTXT, error) UpdateARecord(ref string, name string, ipAddr string, cidr string, netview string, ttl uint32, useTTL bool, comment string, eas EA) (*RecordA, error) - UpdateZoneDelegated(ref string, delegate_to []NameServer) (*ZoneDelegated, error) + UpdateZoneDelegated(ref string, delegate_to []NameServer, ns_group string) (*ZoneDelegated, error) } type ObjectManager struct { @@ -271,10 +271,12 @@ func (objMgr *ObjectManager) GetZoneDelegated(fqdn string) (*ZoneDelegated, erro } // CreateZoneDelegated creates delegated zone -func (objMgr *ObjectManager) CreateZoneDelegated(fqdn string, delegate_to []NameServer) (*ZoneDelegated, error) { +func (objMgr *ObjectManager) CreateZoneDelegated(fqdn string, delegate_to []NameServer, ns_group string) (*ZoneDelegated, error) { zoneDelegated := NewZoneDelegated(ZoneDelegated{ Fqdn: fqdn, - DelegateTo: delegate_to}) + DelegateTo: delegate_to, + NsGroup: ns_group, + }) ref, err := objMgr.connector.CreateObject(zoneDelegated) zoneDelegated.Ref = ref @@ -283,10 +285,12 @@ func (objMgr *ObjectManager) CreateZoneDelegated(fqdn string, delegate_to []Name } // UpdateZoneDelegated updates delegated zone -func (objMgr *ObjectManager) UpdateZoneDelegated(ref string, delegate_to []NameServer) (*ZoneDelegated, error) { +func (objMgr *ObjectManager) UpdateZoneDelegated(ref string, delegate_to []NameServer, ns_group string) (*ZoneDelegated, error) { zoneDelegated := NewZoneDelegated(ZoneDelegated{ Ref: ref, - DelegateTo: delegate_to}) + DelegateTo: delegate_to, + NsGroup: ns_group, + }) refResp, err := objMgr.connector.UpdateObject(zoneDelegated, ref) zoneDelegated.Ref = refResp From 954ffa9452dc249b26b3d45480516e7ebfeaa48a Mon Sep 17 00:00:00 2001 From: Pieter Lexis Date: Mon, 3 Jul 2023 15:08:48 +0200 Subject: [PATCH 3/4] Add NSGroup Delegation object --- objects.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/objects.go b/objects.go index c5ac8a1b..2de91922 100644 --- a/objects.go +++ b/objects.go @@ -947,6 +947,23 @@ func NewZoneDelegated(za ZoneDelegated) *ZoneDelegated { return &res } +type NsGroupDelegation struct { + IBBase `json:"-"` + Ref string `json:"_ref,omitempty"` + Name string `json:"name"` + Comment string `json:"commend,omitempty"` + Ea EA `json:"extattrs"` + DelegateTo []NameServer `json:"delegate_to,omitempty"` +} + +func NewNsGroupDelegation(ngd NsGroupDelegation) *NsGroupDelegation { + res := ngd + res.objectType = "nsgroup:delegation" + res.returnFields = []string{"extattrs", "name", "comment", "delegate_to"} + + return &res +} + func (ea EA) Count() int { return len(ea) } From 53de73ddb3097472a7e7a407e5af41a72c6de7ea Mon Sep 17 00:00:00 2001 From: Pieter Lexis Date: Mon, 3 Jul 2023 15:11:34 +0200 Subject: [PATCH 4/4] Add Delegation NSGroup to object manager --- object_manager.go | 82 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 69 insertions(+), 13 deletions(-) diff --git a/object_manager.go b/object_manager.go index 82a12b1d..711d2403 100644 --- a/object_manager.go +++ b/object_manager.go @@ -14,9 +14,8 @@ type IBObjectManager interface { AllocateIP(netview string, cidr string, ipAddr string, isIPv6 bool, macOrDuid string, name string, comment string, eas EA) (*FixedAddress, error) AllocateNetwork(netview string, cidr string, isIPv6 bool, prefixLen uint, comment string, eas EA) (network *Network, err error) AllocateNetworkContainer(netview string, cidr string, isIPv6 bool, prefixLen uint, comment string, eas EA) (netContainer *NetworkContainer, err error) - CreateARecord(netView string, dnsView string, name string, cidr string, ipAddr string, ttl uint32, useTTL bool, comment string, ea EA) (*RecordA, error) CreateAAAARecord(netView string, dnsView string, recordName string, cidr string, ipAddr string, useTtl bool, ttl uint32, comment string, eas EA) (*RecordAAAA, error) - CreateZoneAuth(fqdn string, ea EA) (*ZoneAuth, error) + CreateARecord(netView string, dnsView string, name string, cidr string, ipAddr string, ttl uint32, useTTL bool, comment string, ea EA) (*RecordA, error) CreateCNAMERecord(dnsview string, canonical string, recordname string, useTtl bool, ttl uint32, comment string, eas EA) (*RecordCNAME, error) CreateDefaultNetviews(globalNetview string, localNetview string) (globalNetviewRef string, localNetviewRef string, err error) CreateEADefinition(eadef EADefinition) (*EADefinition, error) @@ -25,13 +24,14 @@ type IBObjectManager interface { CreateNetwork(netview string, cidr string, isIPv6 bool, comment string, eas EA) (*Network, error) CreateNetworkContainer(netview string, cidr string, isIPv6 bool, comment string, eas EA) (*NetworkContainer, error) CreateNetworkView(name string, comment string, setEas EA) (*NetworkView, error) + CreateNsGroupDelegation(name string, delegate_to []NameServer) (*NsGroupDelegation, error) CreatePTRRecord(networkView string, dnsView string, ptrdname string, recordName string, cidr string, ipAddr string, useTtl bool, ttl uint32, comment string, eas EA) (*RecordPTR, error) CreateSRVRecord(dnsView string, name string, priority uint32, weight uint32, port uint32, target string, ttl uint32, useTtl bool, comment string, eas EA) (*RecordSRV, error) CreateTXTRecord(dnsView string, recordName string, text string, ttl uint32, useTtl bool, comment string, eas EA) (*RecordTXT, error) + CreateZoneAuth(fqdn string, ea EA) (*ZoneAuth, error) CreateZoneDelegated(fqdn string, delegate_to []NameServer, NsGroup string) (*ZoneDelegated, error) - DeleteARecord(ref string) (string, error) DeleteAAAARecord(ref string) (string, error) - DeleteZoneAuth(ref string) (string, error) + DeleteARecord(ref string) (string, error) DeleteCNAMERecord(ref string) (string, error) DeleteFixedAddress(ref string) (string, error) DeleteHostRecord(ref string) (string, error) @@ -39,21 +39,26 @@ type IBObjectManager interface { DeleteNetwork(ref string) (string, error) DeleteNetworkContainer(ref string) (string, error) DeleteNetworkView(ref string) (string, error) + DeleteNsGroupDelegation(ref string) (string, error) DeletePTRRecord(ref string) (string, error) DeleteSRVRecord(ref string) (string, error) DeleteTXTRecord(ref string) (string, error) + DeleteZoneAuth(ref string) (string, error) DeleteZoneDelegated(ref string) (string, error) - GetARecordByRef(ref string) (*RecordA, error) - GetARecord(dnsview string, recordName string, ipAddr string) (*RecordA, error) GetAAAARecord(dnsview string, recordName string, ipAddr string) (*RecordAAAA, error) GetAAAARecordByRef(ref string) (*RecordAAAA, error) + GetARecord(dnsview string, recordName string, ipAddr string) (*RecordA, error) + GetARecordByRef(ref string) (*RecordA, error) + GetAllMembers() ([]Member, error) GetCNAMERecord(dnsview string, canonical string, recordName string) (*RecordCNAME, error) GetCNAMERecordByRef(ref string) (*RecordCNAME, error) + GetCapacityReport(name string) ([]CapacityReport, error) GetEADefinition(name string) (*EADefinition, error) GetFixedAddress(netview string, cidr string, ipAddr string, isIPv6 bool, macOrDuid string) (*FixedAddress, error) GetFixedAddressByRef(ref string) (*FixedAddress, error) + GetGridInfo() ([]Grid, error) + GetGridLicense() ([]License, error) GetHostRecord(netview string, dnsview string, recordName string, ipv4addr string, ipv6addr string) (*HostRecord, error) - SearchHostRecordByAltId(internalId string, ref string, eaNameForInternalId string) (*HostRecord, error) GetHostRecordByRef(ref string) (*HostRecord, error) GetIpAddressFromHostRecord(host HostRecord) (string, error) GetMXRecord(dnsView string, fqdn string, mx string, preference uint32) (*RecordMX, error) @@ -64,21 +69,20 @@ type IBObjectManager interface { GetNetworkContainerByRef(ref string) (*NetworkContainer, error) GetNetworkView(name string) (*NetworkView, error) GetNetworkViewByRef(ref string) (*NetworkView, error) + GetNsGroupDelegation(name string) (*NsGroupDelegation, error) GetPTRRecord(dnsview string, ptrdname string, recordName string, ipAddr string) (*RecordPTR, error) GetPTRRecordByRef(ref string) (*RecordPTR, error) GetSRVRecord(dnsView string, name string, target string, port uint32) (*RecordSRV, error) GetSRVRecordByRef(ref string) (*RecordSRV, error) GetTXTRecord(dnsview string, name string) (*RecordTXT, error) GetTXTRecordByRef(ref string) (*RecordTXT, error) + GetUpgradeStatus(statusType string) ([]UpgradeStatus, error) GetZoneAuthByRef(ref string) (*ZoneAuth, error) GetZoneDelegated(fqdn string) (*ZoneDelegated, error) - GetCapacityReport(name string) ([]CapacityReport, error) - GetUpgradeStatus(statusType string) ([]UpgradeStatus, error) - GetAllMembers() ([]Member, error) - GetGridInfo() ([]Grid, error) - GetGridLicense() ([]License, error) ReleaseIP(netview string, cidr string, ipAddr string, isIPv6 bool, macAddr string) (string, error) + SearchHostRecordByAltId(internalId string, ref string, eaNameForInternalId string) (*HostRecord, error) UpdateAAAARecord(ref string, netView string, recordName string, cidr string, ipAddr string, useTtl bool, ttl uint32, comment string, setEas EA) (*RecordAAAA, error) + UpdateARecord(ref string, name string, ipAddr string, cidr string, netview string, ttl uint32, useTTL bool, comment string, eas EA) (*RecordA, error) UpdateCNAMERecord(ref string, canonical string, recordName string, useTtl bool, ttl uint32, comment string, setEas EA) (*RecordCNAME, error) UpdateFixedAddress(fixedAddrRef string, netview string, name string, cidr string, ipAddr string, matchclient string, macOrDuid string, comment string, eas EA) (*FixedAddress, error) UpdateHostRecord(hostRref string, enabledns bool, enabledhcp bool, name string, netview string, dnsView string, ipv4cidr string, ipv6cidr string, ipv4Addr string, ipv6Addr string, macAddress string, duid string, useTtl bool, ttl uint32, comment string, eas EA, aliases []string) (*HostRecord, error) @@ -86,10 +90,10 @@ type IBObjectManager interface { UpdateNetwork(ref string, setEas EA, comment string) (*Network, error) UpdateNetworkContainer(ref string, setEas EA, comment string) (*NetworkContainer, error) UpdateNetworkView(ref string, name string, comment string, setEas EA) (*NetworkView, error) + UpdateNsGroupDelegation(ref string, delegate_to []NameServer, ns_group string) (*NsGroupDelegation, error) UpdatePTRRecord(ref string, netview string, ptrdname string, name string, cidr string, ipAddr string, useTtl bool, ttl uint32, comment string, setEas EA) (*RecordPTR, error) UpdateSRVRecord(ref string, name string, priority uint32, weight uint32, port uint32, target string, ttl uint32, useTtl bool, comment string, eas EA) (*RecordSRV, error) UpdateTXTRecord(ref string, recordName string, text string, ttl uint32, useTtl bool, comment string, eas EA) (*RecordTXT, error) - UpdateARecord(ref string, name string, ipAddr string, cidr string, netview string, ttl uint32, useTTL bool, comment string, eas EA) (*RecordA, error) UpdateZoneDelegated(ref string, delegate_to []NameServer, ns_group string) (*ZoneDelegated, error) } @@ -301,3 +305,55 @@ func (objMgr *ObjectManager) UpdateZoneDelegated(ref string, delegate_to []NameS func (objMgr *ObjectManager) DeleteZoneDelegated(ref string) (string, error) { return objMgr.connector.DeleteObject(ref) } + +// GetNsGroupDelegation returns the Delegation NSGroup +func (objMgr *ObjectManager) GetNsGroupDelegation(name string) (*NsGroupDelegation, error) { + if len(name) == 0 { + return nil, nil + } + var res []NsGroupDelegation + + zoneDelegated := NewNsGroupDelegation(NsGroupDelegation{}) + + sf := map[string]string{ + "name": name, + } + queryParams := NewQueryParams(false, sf) + err := objMgr.connector.GetObject(zoneDelegated, "", queryParams, &res) + + if err != nil || res == nil || len(res) == 0 { + return nil, err + } + + return &res[0], nil +} + +// CreateNsGroupDelegation creates delegated zone +func (objMgr *ObjectManager) CreateNsGroupDelegation(name string, delegate_to []NameServer) (*NsGroupDelegation, error) { + zoneDelegated := NewNsGroupDelegation(NsGroupDelegation{ + Name: name, + DelegateTo: delegate_to, + }) + + ref, err := objMgr.connector.CreateObject(zoneDelegated) + zoneDelegated.Ref = ref + + return zoneDelegated, err +} + +// UpdateNsGroupDelegation updates delegated zone +func (objMgr *ObjectManager) UpdateNsGroupDelegation(ref string, delegate_to []NameServer, ns_group string) (*NsGroupDelegation, error) { + zoneDelegated := NewNsGroupDelegation(NsGroupDelegation{ + Ref: ref, + DelegateTo: delegate_to, + }) + + refResp, err := objMgr.connector.UpdateObject(zoneDelegated, ref) + zoneDelegated.Ref = refResp + return zoneDelegated, err +} + +// DeleteNsGroupDelegation deletes delegated zone +func (objMgr *ObjectManager) DeleteNsGroupDelegation(ref string) (string, error) { + return objMgr.connector.DeleteObject(ref) +}