Skip to content

Commit

Permalink
Added another scenario where we would return the objectByRef if the i…
Browse files Browse the repository at this point in the history
…nternal id is missing.
  • Loading branch information
sdas-infoblox committed Mar 7, 2024
1 parent 89dca16 commit f3cce51
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions object_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,11 @@ func (objMgr *ObjectManager) SearchObjectByAltId(
// validateObjByInternalId validates the object by comparing the given internal with the object's internal id
func validateObjByInternalId(res interface{}, internalId, eaNameForInternalId string) (bool, error) {
var success bool
if res == nil || strings.TrimSpace(internalId) == "" {
if res == nil {
return success, nil
} else if strings.TrimSpace(internalId) == "" {
// return object if internal id is empty
success = true
return success, nil
}
byteObj, err := json.Marshal(res)
Expand All @@ -607,14 +611,16 @@ func validateObjByInternalId(res interface{}, internalId, eaNameForInternalId st
return success, fmt.Errorf("error unmarshaling JSON: %v", err)
}
extAttrs, err := getInterfaceValueFromMap(obj, "extattrs")
if err != nil {
if err == nil {
resInternalId, err := getInterfaceValueFromMap(extAttrs, eaNameForInternalId)
if err != nil && resInternalId["value"] != nil && resInternalId["value"].(string) == internalId {
if err == nil && resInternalId["value"] != nil && resInternalId["value"].(string) == internalId {
// return object if object's internal id matches with the given internal id
success = true
return success, nil
}
return success, err
}
return success, nil
return success, err
}

// getInterfaceValueFromMap returns the value, after converting it into a map[string]interface{}, of the given key from the map
Expand Down

0 comments on commit f3cce51

Please sign in to comment.