fix: extract UUID from HATEOAS resource refs in custom_id fields#132
fix: extract UUID from HATEOAS resource refs in custom_id fields#132rajivmucheli wants to merge 1 commit intomasterfrom
Conversation
67cb3ac to
ed09e1f
Compare
notque
left a comment
There was a problem hiding this comment.
Thanks @rajivmucheli — this is a real problem and I want to get it merged.
I'd been considering a mapping-driven approach (something like an id_transform directive in the YAML spec), but that's a larger effort and shouldn't block this fix. Let's get this in.
One change needed:
Replace if '/' in s with if '://' in s (line 62)
The bare / check is too broad — it would strip path segments from any custom_id value containing a slash (e.g. Swift object names can legitimately contain /). The :// check targets actual HATEOAS URLs specifically, which is what we want.
if '://' in s:
s = s.rstrip('/').rsplit('/', 1)[-1]Everything else looks good — tests are solid and the pycadf warning assertion is a nice verification technique.
Longer-term, I think an id_transform directive in the mapping spec is the right architectural solution (so services declare their own ID extraction rules declaratively). But this fix is correct and pragmatic for now.
ed09e1f to
1600273
Compare
notque
left a comment
There was a problem hiding this comment.
LGTM thanks, please mention in team core the open stack audit middleware is updated with the PR link just so people are aware when they see it in their diffs. Thanks!
Problem
Services like Barbican return full HATEOAS URLs in response fields configured as
custom_id(e.g.secret_ref,container_ref):The
barbican_audit_map.yamlmapscustom_id: secret_refandcustom_id: container_ref, so_create_target_resourceextracts the full URL asrid. This flows into_make_uuidunchanged and is set as the CADFtarget.id.pycadf then emits:
Root cause
_make_uuidonly handled integer-string IDs; everything else was passed through verbatim, including full URLs.Fix
Strip the URL prefix in
_make_uuid: if the value contains/, take the last path segment (the bare UUID):Safe for all existing cases: bare UUIDs pass through unchanged, integer strings are handled before this check, full URLs yield just the trailing UUID.
Tests
Added
BarbicanAuditMappingTestwith two cases:test_post_create_secret_extracts_uuid_from_ref- verifiessecret_refURL strips to bare UUID and no pycadf warnings firetest_post_create_container_extracts_uuid_from_ref- same forcontainer_ref