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 useful fields for Authoritative Zone resource #186

Open
wants to merge 2 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
35 changes: 2 additions & 33 deletions object_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type IBObjectManager interface {
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)
CreateZoneAuth(dnsview string, fqdn string, nsGroup string, restartIfNeeded bool, comment string, soaDefaultTtl int, soaExpire int, soaNegativeTtl int, soaRefresh int, soaRetry int, zoneFormat string, ea EA) (*ZoneAuth, 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 Down Expand Up @@ -79,6 +79,7 @@ type IBObjectManager interface {
UpdatePTRRecord(ref string, netview string, ptrdname string, name string, cidr string, ipAddr string, useTtl bool, ttl uint32, comment string, setEas EA) (*RecordPTR, 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)
UpdateZoneAuth(ref string, dnsview string, nsGroup string, restartIfNeeded bool, comment string, soaDefaultTtl int, soaExpire int, soaNegativeTtl int, soaRefresh int, soaRetry int, ea EA) (*ZoneAuth, error)
UpdateZoneDelegated(ref string, delegate_to []NameServer) (*ZoneDelegated, error)
}

Expand Down Expand Up @@ -194,38 +195,6 @@ func (objMgr *ObjectManager) GetGridInfo() ([]Grid, error) {
return res, err
}

// CreateZoneAuth creates zones and subs by passing fqdn
func (objMgr *ObjectManager) CreateZoneAuth(
fqdn string,
eas EA) (*ZoneAuth, error) {

zoneAuth := NewZoneAuth(ZoneAuth{
Fqdn: fqdn,
Ea: eas})

ref, err := objMgr.connector.CreateObject(zoneAuth)
zoneAuth.Ref = ref
return zoneAuth, err
}

// Retreive a authortative zone by ref
func (objMgr *ObjectManager) GetZoneAuthByRef(ref string) (*ZoneAuth, error) {
res := NewZoneAuth(ZoneAuth{})

if ref == "" {
return nil, fmt.Errorf("empty reference to an object is not allowed")
}

err := objMgr.connector.GetObject(
res, ref, NewQueryParams(false, nil), res)
return res, err
}

// DeleteZoneAuth deletes an auth zone
func (objMgr *ObjectManager) DeleteZoneAuth(ref string) (string, error) {
return objMgr.connector.DeleteObject(ref)
}

// GetZoneAuth returns the authoritatives zones
func (objMgr *ObjectManager) GetZoneAuth() ([]ZoneAuth, error) {
var res []ZoneAuth
Expand Down
63 changes: 57 additions & 6 deletions object_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,24 @@ var _ = Describe("Object Manager", func() {
Describe("Create Zone Auth", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
dnsview := "default"
nsGroup := "mynameservers"
restartIfNeeded := true
fqdn := "azone.example.com"
comment := "test comment"
soaDefaultTtl := 3600
soaExpire := 2419200
soaNegativeTtl := 900
soaRefresh := 10800
soaRetry := 3600
zoneFormat := "FORWARD"
fakeRefReturn := "zone_auth/ZG5zLnpvbmUkLl9kZWZhdWx0LnphLmNvLmFic2EuY2Fhcy5vaG15Z2xiLmdzbGJpYmNsaWVudA:dzone.example.com/default"
zaFakeConnector := &fakeConnector{
createObjectObj: NewZoneAuth(ZoneAuth{Fqdn: fqdn}),
resultObject: NewZoneAuth(ZoneAuth{Fqdn: fqdn, Ref: fakeRefReturn}),
fakeRefReturn: fakeRefReturn,
createObjectObj: NewZoneAuth(ZoneAuth{View: dnsview, Fqdn: fqdn, NsGroup: nsGroup, RestartIfNeeded: restartIfNeeded, Comment: comment,
SoaDefaultTtl: soaDefaultTtl, SoaExpire: soaExpire, SoaNegativeTtl: soaNegativeTtl, SoaRefresh: soaRefresh, SoaRetry: soaRetry, ZoneFormat: zoneFormat}),
resultObject: NewZoneAuth(ZoneAuth{View: dnsview, Fqdn: fqdn, NsGroup: nsGroup, RestartIfNeeded: restartIfNeeded, Comment: comment,
SoaDefaultTtl: soaDefaultTtl, SoaExpire: soaExpire, SoaNegativeTtl: soaNegativeTtl, SoaRefresh: soaRefresh, SoaRetry: soaRetry, ZoneFormat: zoneFormat, Ref: fakeRefReturn}),
fakeRefReturn: fakeRefReturn,
}

objMgr := NewObjectManager(zaFakeConnector, cmpType, tenantID)
Expand All @@ -333,7 +345,7 @@ var _ = Describe("Object Manager", func() {
var actualZoneAuth *ZoneAuth
var err error
It("should pass expected ZoneAuth Object to CreateObject", func() {
actualZoneAuth, err = objMgr.CreateZoneAuth(fqdn, ea)
actualZoneAuth, err = objMgr.CreateZoneAuth(dnsview, fqdn, nsGroup, restartIfNeeded, comment, soaDefaultTtl, soaExpire, soaNegativeTtl, soaRefresh, soaRetry, zoneFormat, ea)
})
It("should return expected ZoneAuth Object", func() {
Expect(actualZoneAuth).To(Equal(zaFakeConnector.resultObject))
Expand All @@ -344,13 +356,14 @@ var _ = Describe("Object Manager", func() {
Describe("Get AuthZone by ref", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
dnsview := "default"
fqdn := "azone.example.com"
fakeRefReturn := "zone_delegated/ZG5zLnpvbmUkLl9kZWZhdWx0LnphLmNvLmFic2EuY2Fhcy5vaG15Z2xiLmdzbGJpYmNsaWVudA:azone.example.com/default"
zdFakeConnector := &fakeConnector{
getObjectObj: NewZoneAuth(ZoneAuth{}),
getObjectRef: fakeRefReturn,
getObjectQueryParams: NewQueryParams(false, nil),
resultObject: NewZoneAuth(ZoneAuth{Fqdn: fqdn}),
resultObject: NewZoneAuth(ZoneAuth{View: dnsview, Fqdn: fqdn}),
}

objMgr := NewObjectManager(zdFakeConnector, cmpType, tenantID)
Expand All @@ -361,7 +374,6 @@ var _ = Describe("Object Manager", func() {
It("should pass expected ZoneAuth Object to GetObject", func() {
actualZoneAuth, err = objMgr.GetZoneAuthByRef(fakeRefReturn)
})
fmt.Printf("doodo %s", actualZoneAuth)
It("should return expected ZoneAuth Object", func() {
Expect(actualZoneAuth).To(Equal(zdFakeConnector.resultObject))
Expect(err).To(BeNil())
Expand All @@ -375,6 +387,45 @@ var _ = Describe("Object Manager", func() {
})
})

Describe("Update ZoneAuth", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
dnsview := "default"
// fqdn := "azone.example.com"
nsGroup := "mynameservers"
restartIfNeeded := true
comment := "test comment"
soaDefaultTtl := 3600
soaExpire := 2419200
soaNegativeTtl := 900
soaRefresh := 10800
soaRetry := 3600
// zoneFormat := "FORWARD"
ea := make(EA)

fakeRefReturn := "zone_auth/ZG5zLnpvbmUkLl9kZWZhdWx0LnphLmNvLmFic2EuY2Fhcy5vaG15Z2xiLmdzbGJpYmNsaWVudA:dzone.example.com/default"

zaFakeConnector := &fakeConnector{
updateObjectObj: NewZoneAuth(ZoneAuth{Ref: fakeRefReturn, View: dnsview, NsGroup: nsGroup, RestartIfNeeded: restartIfNeeded, Comment: comment,
SoaDefaultTtl: soaDefaultTtl, SoaExpire: soaExpire, SoaNegativeTtl: soaNegativeTtl, SoaRefresh: soaRefresh, SoaRetry: soaRetry, Ea: ea}),
updateObjectRef: fakeRefReturn,
resultObject: NewZoneAuth(ZoneAuth{Ref: fakeRefReturn, View: dnsview, NsGroup: nsGroup, RestartIfNeeded: restartIfNeeded, Comment: comment,
SoaDefaultTtl: soaDefaultTtl, SoaExpire: soaExpire, SoaNegativeTtl: soaNegativeTtl, SoaRefresh: soaRefresh, SoaRetry: soaRetry, Ea: ea}),
fakeRefReturn: fakeRefReturn,
}

objMgr := NewObjectManager(zaFakeConnector, cmpType, tenantID)

var actualZoneAuth *ZoneAuth
var err error
It("should pass expected ZoneAuth fields to UpdateObject and receive updated ZoneAuth Object", func() {
actualZoneAuth, err = objMgr.UpdateZoneAuth(fakeRefReturn, dnsview, nsGroup, restartIfNeeded, comment,
soaDefaultTtl, soaExpire, soaNegativeTtl, soaRefresh, soaRetry, ea)
Expect(err).To(BeNil())
Expect(actualZoneAuth).To(Equal(zaFakeConnector.resultObject))
})
})

Describe("Delete ZoneAuth", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
Expand Down
94 changes: 94 additions & 0 deletions object_manager_zone_auth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package ibclient

import (
"fmt"
)

func (objMgr *ObjectManager) CreateZoneAuth(
dnsview string,
fqdn string,
bsmithtm marked this conversation as resolved.
Show resolved Hide resolved
nsGroup string,
restartIfNeeded bool,
comment string,
soaDefaultTtl int,
soaExpire int,
soaNegativeTtl int,
soaRefresh int,
soaRetry int,
zoneFormat string,
ea EA) (*ZoneAuth, error) {

zoneAuth := NewZoneAuth(ZoneAuth{
View: dnsview,
Fqdn: fqdn,
NsGroup: nsGroup,
RestartIfNeeded: restartIfNeeded,
Comment: comment,
SoaDefaultTtl: soaDefaultTtl,
SoaExpire: soaExpire,
SoaNegativeTtl: soaNegativeTtl,
SoaRefresh: soaRefresh,
SoaRetry: soaRetry,
ZoneFormat: zoneFormat,
Ea: ea})

ref, err := objMgr.connector.CreateObject(zoneAuth)
zoneAuth.Ref = ref
return zoneAuth, err
}

// Retrieve a authoritative zone by ref
func (objMgr *ObjectManager) GetZoneAuthByRef(ref string) (*ZoneAuth, error) {
res := NewZoneAuth(ZoneAuth{})

if ref == "" {
return nil, fmt.Errorf("empty reference to an object is not allowed")
}

err := objMgr.connector.GetObject(
res, ref, NewQueryParams(false, nil), res)
return res, err
}

// UpdateZoneAuth updates an auth zone, except fields that can't be updated
func (objMgr *ObjectManager) UpdateZoneAuth(
ref string,
dnsview string,
// fqdn string, CANNOT BE UPDATED IN WAPI
nsGroup string,
restartIfNeeded bool,
comment string,
soaDefaultTtl int,
soaExpire int,
soaNegativeTtl int,
soaRefresh int,
soaRetry int,
// zoneFormat string, CANNOT BE UPDATED IN WAPI
ea EA) (*ZoneAuth, error) {

inputZoneAuth := NewZoneAuth(ZoneAuth{
Ref: ref,
View: dnsview,
NsGroup: nsGroup,
RestartIfNeeded: restartIfNeeded,
Comment: comment,
SoaDefaultTtl: soaDefaultTtl,
SoaExpire: soaExpire,
SoaNegativeTtl: soaNegativeTtl,
SoaRefresh: soaRefresh,
SoaRetry: soaRetry,
Ea: ea})

updatedRef, err := objMgr.connector.UpdateObject(inputZoneAuth, ref)
if err != nil {
fmt.Printf("failed to update object with this ref '%s': %s", updatedRef, err)
return nil, err
}
inputZoneAuth.Ref = updatedRef
return inputZoneAuth, err
}

// DeleteZoneAuth deletes an auth zone
func (objMgr *ObjectManager) DeleteZoneAuth(ref string) (string, error) {
return objMgr.connector.DeleteObject(ref)
}
26 changes: 20 additions & 6 deletions objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -824,17 +824,31 @@ func NewRecordTXT(
}

type ZoneAuth struct {
IBBase `json:"-"`
Ref string `json:"_ref,omitempty"`
Fqdn string `json:"fqdn,omitempty"`
View string `json:"view,omitempty"`
Ea EA `json:"extattrs"`
IBBase `json:"-"`
Ref string `json:"_ref,omitempty"`
Fqdn string `json:"fqdn,omitempty"`
View string `json:"view"`
NsGroup string `json:"ns_group,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about setting no NS groups for this zone (in UI: 'None' for 'Name Servers')? 'omitempty' option can prevent this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand correctly, you mean a case where the end user would like to send empty string "" as the ns_group to explicitly set this field to nothing; if we omit this from marshaling when it is empty, on the Infoblox side it will attempt to set the default NS Group instead. Is that correct?

RestartIfNeeded bool `json:"restart_if_needed"`
Comment string `json:"comment"`
SoaDefaultTtl int `json:"soa_default_ttl"`
SoaExpire int `json:"soa_expire"`
SoaNegativeTtl int `json:"soa_negative_ttl"`
SoaRefresh int `json:"soa_refresh"`
SoaRetry int `json:"soa_retry"`
ZoneFormat string `json:"zone_format,omitempty"`
Ea EA `json:"extattrs"`
}

func NewZoneAuth(za ZoneAuth) *ZoneAuth {
res := za
res.objectType = "zone_auth"
res.returnFields = []string{"extattrs", "fqdn", "view"}
// restart_if_needed not included here because it is not readable
res.returnFields = []string{
"view", "fqdn", "ns_group", "comment",
"soa_default_ttl", "soa_expire", "soa_negative_ttl", "soa_refresh", "soa_retry",
"zone_format", "extattrs",
}

return &res
}
Expand Down
38 changes: 35 additions & 3 deletions objects_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ibclient

import (
"encoding/json"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
Expand Down Expand Up @@ -628,20 +629,51 @@ var _ = Describe("Objects", func() {

Context("ZoneAuth object", func() {
fqdn := "domain.com"
ns_group := "mynameservers"
restart_if_needed := true
comment := "test comment"
soa_default_ttl := 3600
soa_expire := 2419200
soa_negative_ttl := 900
soa_refresh := 10800
soa_retry := 3600
zone_format := "FORWARD"
view := "default"

za := NewZoneAuth(ZoneAuth{
Fqdn: fqdn,
View: view})
Fqdn: fqdn,
NsGroup: ns_group,
RestartIfNeeded: restart_if_needed,
Comment: comment,
SoaDefaultTtl: soa_default_ttl,
SoaExpire: soa_expire,
SoaNegativeTtl: soa_negative_ttl,
SoaRefresh: soa_refresh,
SoaRetry: soa_retry,
ZoneFormat: zone_format,
View: view})

It("should set fields correctly", func() {
Expect(za.View).To(Equal(view))
Expect(za.Fqdn).To(Equal(fqdn))
Expect(za.NsGroup).To(Equal(ns_group))
Expect(za.RestartIfNeeded).To(Equal(restart_if_needed))
Expect(za.Comment).To(Equal(comment))
Expect(za.SoaDefaultTtl).To(Equal(soa_default_ttl))
Expect(za.SoaExpire).To(Equal(soa_expire))
Expect(za.SoaNegativeTtl).To(Equal(soa_negative_ttl))
Expect(za.SoaRefresh).To(Equal(soa_refresh))
Expect(za.SoaRetry).To(Equal(soa_retry))
Expect(za.ZoneFormat).To(Equal(zone_format))
Expect(za.View).To(Equal(view))
})

It("should set base fields correctly", func() {
Expect(za.ObjectType()).To(Equal("zone_auth"))
Expect(za.ReturnFields()).To(ConsistOf("extattrs", "fqdn", "view"))
Expect(za.ReturnFields()).To(ConsistOf(
"extattrs", "fqdn", "view", "ns_group", "comment",
"soa_default_ttl", "soa_expire", "soa_negative_ttl", "soa_refresh", "soa_retry", "zone_format",
))
})
})

Expand Down