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 1 commit
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
34 changes: 1 addition & 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(fqdn string, nsGroup string, restartIfNeeded bool, comment string, SoaDefaultTtl int, SoaExpire int, SoaNegativeTtl int, SoaRefresh int, SoaRetry int, ea EA) (*ZoneAuth, error)
bsmithtm marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -194,38 +194,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
19 changes: 14 additions & 5 deletions object_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,22 @@ var _ = Describe("Object Manager", func() {
Describe("Create Zone Auth", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
nsGroup := "mynameservers"
restartIfNeeded := true
fqdn := "azone.example.com"
comment := "test comment"
soaDefaultTtl := 3600
soaExpire := 2419200
soaNegativeTtl := 900
soaRefresh := 10800
soaRetry := 3600
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{Fqdn: fqdn, NsGroup: nsGroup, RestartIfNeeded: restartIfNeeded, Comment: comment,
SoaDefaultTtl: soaDefaultTtl, SoaExpire: soaExpire, SoaNegativeTtl: soaNegativeTtl, SoaRefresh: soaRefresh, SoaRetry: soaRetry}),
resultObject: NewZoneAuth(ZoneAuth{Fqdn: fqdn, NsGroup: nsGroup, RestartIfNeeded: restartIfNeeded, Comment: comment,
SoaDefaultTtl: soaDefaultTtl, SoaExpire: soaExpire, SoaNegativeTtl: soaNegativeTtl, SoaRefresh: soaRefresh, SoaRetry: soaRetry, Ref: fakeRefReturn}),
fakeRefReturn: fakeRefReturn,
}

objMgr := NewObjectManager(zaFakeConnector, cmpType, tenantID)
Expand All @@ -333,7 +343,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(fqdn, nsGroup, restartIfNeeded, comment, soaDefaultTtl, soaExpire, soaNegativeTtl, soaRefresh, soaRetry, ea)
})
It("should return expected ZoneAuth Object", func() {
Expect(actualZoneAuth).To(Equal(zaFakeConnector.resultObject))
Expand Down Expand Up @@ -361,7 +371,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 Down
50 changes: 50 additions & 0 deletions object_manager_zone_auth.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package ibclient

import "fmt"

func (objMgr *ObjectManager) CreateZoneAuth(
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,
eas EA) (*ZoneAuth, error) {

zoneAuth := NewZoneAuth(ZoneAuth{
Fqdn: fqdn,
NsGroup: nsGroup,
RestartIfNeeded: restartIfNeeded,
Comment: comment,
SoaDefaultTtl: soaDefaultTtl,
SoaExpire: soaExpire,
SoaNegativeTtl: soaNegativeTtl,
SoaRefresh: soaRefresh,
SoaRetry: soaRetry,
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)
}
24 changes: 18 additions & 6 deletions objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -824,17 +824,29 @@ 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,omitempty"`
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"`
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{
"extattrs", "fqdn", "view", "ns_group", "comment",
"soa_default_ttl", "soa_expire", "soa_negative_ttl", "soa_refresh", "soa_retry",
}

return &res
}
Expand Down
34 changes: 31 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,47 @@ 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
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,
View: view})

It("should set fields correctly", func() {
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.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",
))
})
})

Expand Down