diff --git a/object_manager.go b/object_manager.go index d45d5ac..711d240 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) - CreateZoneDelegated(fqdn string, delegate_to []NameServer) (*ZoneDelegated, error) - DeleteARecord(ref string) (string, error) + CreateZoneAuth(fqdn string, ea EA) (*ZoneAuth, error) + CreateZoneDelegated(fqdn string, delegate_to []NameServer, NsGroup string) (*ZoneDelegated, 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,11 +90,11 @@ 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) (*ZoneDelegated, error) + UpdateZoneDelegated(ref string, delegate_to []NameServer, ns_group string) (*ZoneDelegated, error) } type ObjectManager struct { @@ -271,10 +275,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 +289,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 @@ -297,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) +} diff --git a/objects.go b/objects.go index 6ed5f2a..2de9192 100644 --- a/objects.go +++ b/objects.go @@ -936,12 +936,30 @@ 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 +} + +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 } diff --git a/objects_test.go b/objects_test.go index 0b03935..8da50fa 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")) }) })