Skip to content

Commit

Permalink
Allow creation and deletion of auth zones (#109)
Browse files Browse the repository at this point in the history
* Add creation, deletion and lookup of zones

* Add unit test for creation of auth zone

* Add unit test for Delete ZoneAuth

* add unit test for GetZoneAuthByRef

* Add DeleteZoneAuth and CreateZoneAuth to IBObjectManager
  • Loading branch information
alanplatt authored Nov 20, 2020
1 parent 0c61c1a commit 107472b
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 0 deletions.
36 changes: 36 additions & 0 deletions object_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type IBObjectManager interface {
AllocateIP(netview string, cidr string, ipAddr string, macAddress string, name string, ea EA) (*FixedAddress, error)
AllocateNetwork(netview string, cidr string, prefixLen uint, name string) (network *Network, err error)
CreateARecord(netview string, dnsview string, recordname string, cidr string, ipAddr string, ea EA) (*RecordA, error)
CreateZoneAuth(fqdn string, ea EA) (*ZoneAuth, error)
CreateCNAMERecord(canonical string, recordname string, dnsview string, ea EA) (*RecordCNAME, error)
CreateDefaultNetviews(globalNetview string, localNetview string) (globalNetviewRef string, localNetviewRef string, err error)
CreateEADefinition(eadef EADefinition) (*EADefinition, error)
Expand All @@ -20,6 +21,7 @@ type IBObjectManager interface {
CreateNetworkView(name string) (*NetworkView, error)
CreatePTRRecord(netview string, dnsview string, recordname string, cidr string, ipAddr string, ea EA) (*RecordPTR, error)
DeleteARecord(ref string) (string, error)
DeleteZoneAuth(ref string) (string, error)
DeleteCNAMERecord(ref string) (string, error)
DeleteFixedAddress(ref string) (string, error)
DeleteHostRecord(ref string) (string, error)
Expand All @@ -38,6 +40,7 @@ type IBObjectManager interface {
GetNetworkContainer(netview string, cidr string) (*NetworkContainer, error)
GetNetworkView(name string) (*NetworkView, error)
GetPTRRecordByRef(ref string) (*RecordPTR, error)
GetZoneAuthByRef(ref string) (*ZoneAuth, error)
ReleaseIP(netview string, cidr string, ipAddr string, macAddr string) (string, error)
UpdateFixedAddress(fixedAddrRef string, matchclient string, macAddress string, vmID string, vmName string) (*FixedAddress, error)
UpdateHostRecord(hostRref string, ipAddr string, macAddress string, vmID string, vmName string) (string, error)
Expand Down Expand Up @@ -752,6 +755,39 @@ func (objMgr *ObjectManager) GetGridInfo() ([]Grid, error) {
return res, err
}

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

eas := objMgr.extendEA(ea)

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) {
var res ZoneAuth

if ref == "" {
return res, nil
}
zoneAuth := NewZoneAuth(ZoneAuth{})

err := objMgr.connector.GetObject(zoneAuth, ref, &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
91 changes: 91 additions & 0 deletions object_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ func (c *fakeConnector) GetObject(obj IBObject, ref string, res interface{}) (er
}
} else {
switch obj.(type) {
case *ZoneAuth:
*res.(*ZoneAuth) = c.resultObject.(ZoneAuth)
case *NetworkView:
*res.(*NetworkView) = c.resultObject.(NetworkView)
}
Expand Down Expand Up @@ -1626,6 +1628,95 @@ var _ = Describe("Object Manager", func() {
})
})

Describe("Create Zone Auth", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
fqdn := "azone.example.com"
fakeRefReturn := "zone_auth/ZG5zLnpvbmUkLl9kZWZhdWx0LnphLmNvLmFic2EuY2Fhcy5vaG15Z2xiLmdzbGJpYmNsaWVudA:dzone.example.com/default"
zaFakeConnector := &fakeConnector{
createObjectObj: NewZoneAuth(ZoneAuth{Fqdn: fqdn}),
resultObject: NewZoneAuth(ZoneAuth{Fqdn: fqdn, Ref: fakeRefReturn}),
fakeRefReturn: fakeRefReturn,
}

objMgr := NewObjectManager(zaFakeConnector, cmpType, tenantID)

ea := objMgr.getBasicEA(true)

zaFakeConnector.createObjectObj.(*ZoneAuth).Ea = ea
zaFakeConnector.createObjectObj.(*ZoneAuth).Ea["Tenant ID"] = tenantID
zaFakeConnector.createObjectObj.(*ZoneAuth).Ea["CMP Type"] = cmpType

zaFakeConnector.resultObject.(*ZoneAuth).Ea = ea
zaFakeConnector.resultObject.(*ZoneAuth).Ea["Tenant ID"] = tenantID
zaFakeConnector.resultObject.(*ZoneAuth).Ea["CMP Type"] = cmpType

var actualZoneAuth *ZoneAuth
var err error
It("should pass expected ZoneAuth Object to CreateObject", func() {
actualZoneAuth, err = objMgr.CreateZoneAuth(fqdn, ea)
})
It("should return expected ZoneAuth Object", func() {
Expect(actualZoneAuth).To(Equal(zaFakeConnector.resultObject))
Expect(err).To(BeNil())
})
})

Describe("Get AuthZone by ref", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
fqdn := "azone.example.com"
fakeRefReturn := "zone_delegated/ZG5zLnpvbmUkLl9kZWZhdWx0LnphLmNvLmFic2EuY2Fhcy5vaG15Z2xiLmdzbGJpYmNsaWVudA:azone.example.com/default"
zdFakeConnector := &fakeConnector{
getObjectObj: NewZoneAuth(ZoneAuth{}),
getObjectRef: fakeRefReturn,
resultObject: *NewZoneAuth(ZoneAuth{Fqdn: fqdn}),
}

objMgr := NewObjectManager(zdFakeConnector, cmpType, tenantID)

var actualZoneAuth ZoneAuth
var err error
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())
})
It("should return empty ZoneAuth and nil error if ref is empty", func() {
zdFakeConnector.getObjectObj.(*ZoneAuth).IBBase.objectType = ""
zdFakeConnector.getObjectObj.(*ZoneAuth).IBBase.returnFields = nil
actualZoneAuth, err = objMgr.GetZoneAuthByRef("")
Expect(actualZoneAuth).To(Equal(*zdFakeConnector.getObjectObj.(*ZoneAuth)))
Expect(err).To(BeNil())
})
})

Describe("Delete ZoneAuth", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
deleteRef := "zone_auth/ZG5zLnpvbmUkLl9kZWZhdWx0LnphLmNvLmFic2EuY2Fhcy5vaG15Z2xiLmdzbGJpYmNsaWVudA:dzone.example.com/default"
fakeRefReturn := deleteRef
zaFakeConnector := &fakeConnector{
deleteObjectRef: deleteRef,
fakeRefReturn: fakeRefReturn,
}

objMgr := NewObjectManager(zaFakeConnector, cmpType, tenantID)

var actualRef string
var err error
It("should pass expected ZoneAuth Ref to DeleteObject", func() {
actualRef, err = objMgr.DeleteZoneAuth(deleteRef)
})
It("should return expected ZoneAuth Ref", func() {
Expect(actualRef).To(Equal(fakeRefReturn))
Expect(err).To(BeNil())
})
})

Describe("Get Zone Delegated", func() {
cmpType := "Docker"
tenantID := "01234567890abcdef01234567890abcdef"
Expand Down

0 comments on commit 107472b

Please sign in to comment.