Skip to content

Commit

Permalink
Added comparison for the fetched internal id from the response by ref…
Browse files Browse the repository at this point in the history
… with the provided internal id.
  • Loading branch information
sdas-infoblox committed Mar 1, 2024
1 parent d044ce3 commit a2f801f
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion object_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,10 @@ func (objMgr *ObjectManager) SearchDnsObjectByAltId(
return nil, err
}
}
if res != nil {
success, err := validateObjByRef(res, internalId, eaNameForInternalId)
if err != nil {
return nil, err
} else if success {
return res, nil
}
}
Expand Down Expand Up @@ -589,3 +592,28 @@ func (objMgr *ObjectManager) SearchDnsObjectByAltId(

return &res, nil
}

func validateObjByRef(res interface{}, internalId, eaNameForInternalId string) (bool, error) {
var success bool
if res == nil {
return success, nil
}
byteObj, err := json.Marshal(res)
if err != nil {
return success, fmt.Errorf("error marshaling JSON: %v", err)
}
obj := make(map[string]interface{})
err = json.Unmarshal(byteObj, &obj)
if err != nil {
return success, fmt.Errorf("error unmarshaling JSON: %v", err)
}
extAttrs, found := obj["extattrs"].(map[string]interface{})
if found {
resInternalId := extAttrs[eaNameForInternalId].(map[string]interface{})["value"]
if resInternalId != nil && resInternalId.(string) == internalId {
success = true
return success, nil
}
}
return success, nil
}

0 comments on commit a2f801f

Please sign in to comment.