Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ns_group to Delegated Zones and add access to NS Groups for delegation #210

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 79 additions & 19 deletions object_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -25,35 +24,41 @@ 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)
DeleteMXRecord(ref string) (string, error)
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)
Expand All @@ -64,33 +69,32 @@ 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)
UpdateMXRecord(ref string, dnsView string, fqdn string, mx string, preference uint32, ttl uint32, useTtl bool, comment string, eas EA) (*RecordMX, error)
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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
}
20 changes: 19 additions & 1 deletion objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion objects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
})
})

Expand Down