diff --git a/object_manager.go b/object_manager.go index ee09709a..977390f4 100644 --- a/object_manager.go +++ b/object_manager.go @@ -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) @@ -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) } @@ -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 diff --git a/object_manager_test.go b/object_manager_test.go index 92ee6ac0..ef146032 100644 --- a/object_manager_test.go +++ b/object_manager_test.go @@ -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) @@ -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)) @@ -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) @@ -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()) @@ -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" diff --git a/object_manager_zone_auth.go b/object_manager_zone_auth.go new file mode 100644 index 00000000..b789d451 --- /dev/null +++ b/object_manager_zone_auth.go @@ -0,0 +1,94 @@ +package ibclient + +import ( + "fmt" +) + +func (objMgr *ObjectManager) 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) { + + 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) +} diff --git a/objects.go b/objects.go index f0310870..f956b411 100644 --- a/objects.go +++ b/objects.go @@ -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"` + 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 } diff --git a/objects_test.go b/objects_test.go index eeb645a2..64cce92e 100644 --- a/objects_test.go +++ b/objects_test.go @@ -2,6 +2,7 @@ package ibclient import ( "encoding/json" + . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" ) @@ -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", + )) }) })