Skip to content

Commit

Permalink
Merge pull request #97 from DMTF/Fix93-Harden-Inventory-Property-Mapping
Browse files Browse the repository at this point in the history
Enhanced system inventory logic to ensure properties are of the expected format instead of throwing an exception when malformed
  • Loading branch information
mraineri authored Dec 2, 2022
2 parents 4e57e48 + bf3fb7e commit 5a60fc5
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions redfish_utilities/inventory.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,23 @@ def catalog_resource( context, resource, inventory, chassis_id ):
"Model": resource.get( "Model", None ),
"SKU": resource.get( "SKU", None ),
"AssetTag": resource.get( "AssetTag", None ),
"Label": resource.get( location_prop, {} ).get( "PartLocation", {} ).get( "ServiceLabel", None ),
"State": resource.get( "Status", {} ).get( "State", None ),
"Label": None,
"State": None,
"Description": None
}
# For nested properties, need to protect against malformed payloads to avoid exceptions
try:
catalog["Label"] = resource.get( location_prop, {} ).get( "PartLocation", {} ).get( "ServiceLabel", None )
except:
pass
try:
catalog["State"] = resource.get( "Status", {} ).get( "State", None )
except:
pass
# Ensure all fields are strings
for item in catalog:
if not isinstance( catalog[item], str ):
catalog[item] = None

# If no label was found, build a default name
if catalog["Label"] is None:
Expand Down

0 comments on commit 5a60fc5

Please sign in to comment.