Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse the event url with Regex not split #167

Merged
merged 1 commit into from
Nov 20, 2024

Conversation

agrare
Copy link
Member

@agrare agrare commented Nov 20, 2024

This isn't the greatest regular expression of all time :D but it passes the specs.

The URLs for events that we get from the specs are:

https://te.st:12443/rest/api/uom/ManagedSystem/e4acf909-6d0b-3c03-b75a-4d8495e5fc49/VirtualSwitch/74CC38E2-C6DD-4B03-A0C6-088F7882EF0E
https://coophmc2:12443/rest/api/uom/ManagedSystem/d47a585d-eaa8-3a54-b4dc-93346276ea37/SharedMemoryPool/557f7755-a4dc-30de-816d-387f42dd8fd3
https://te.st:12443/rest/api/uom/ManagedSystem/977848c8-3bed-360a-c9d2-ae4b7e46b5d1
https://te.st:12443/rest/api/uom/UserTask/1d43a4a6-903c-46f8-865d-a356559bb17f
https://te.st:12443/rest/api/uom/Cluster/c1e50c27-888c-3c4d-8d4a-53a3768ea250
https://coophmc2:12443/rest/api/uom/ManagedSystem/d47a585d-eaa8-3a54-b4dc-93346276ea37/SharedProcessorPool/27aae064-2855-39a0-b4e6-e3c9b5572036
https://te.st:12443/rest/api/uom/ManagedSystem/e4acf909-6d0b-3c03-b75a-4d8495e5fc49/VirtualNetwork/74CC38E2-C6DD-4B03-A0C6-088F7882EF0E
https://te.st:12443/rest/api/uom/ManagedSystem/e4acf909-6d0b-3c03-b75a-4d8495e5fc49/LogicalPartition/74CC38E2-C6DD-4B03-A0C6-088F7882EF0E

Critically we have to handle the optional ManagedSystem/d47a585d-eaa8-3a54-b4dc-93346276ea37 at the start of the url path, but if that is the whole path then we need it to match on type/uuid not manager_uuid

end
when "VirtualSwitch", "VirtualNetwork"
if elems.key?(:manager_uuid)
new_targets << {:assoc => :hosts, :ems_ref => elems[:manager_uuid]}
if elems["manager_uuid"]
Copy link
Member Author

@agrare agrare Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This changed from .key? to truthy because if it isn't matched the payload will have {"manager_uuid" => nil}

@Fryguy
Copy link
Member

Fryguy commented Nov 20, 2024

Is there specs for this? I thought I saw a spec PR come through but I can't find it

@agrare
Copy link
Member Author

agrare commented Nov 20, 2024

Is there specs for this? I thought I saw a spec PR come through but I can't find it

Yes this method is well covered by specs each type has a spec associated with it. I only added a test for the invalid LPAR uuid case.

@Fryguy Fryguy self-assigned this Nov 20, 2024
@agrare
Copy link
Member Author

agrare commented Nov 20, 2024

@Fryguy let me check if there is a spec for an invalid url first

</Metadata>
<EventType kb="ROR" kxe="false">ADD_URI</EventType>
<EventID kb="ROR" kxe="false">1639561179310</EventID>
<EventData kxe="false" kb="ROR">https://te.st:12443/rest/api/uom/ManagedSyste/e4acf909-6d0b-3c03-b75a-4d8495e5fc49/LogicalPartition/</EventData>
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this the regular expression returns nil to exercise that case

(byebug) raw_event[:data].match(%r{/rest/api/uom/(?:ManagedSystem/(?<manager_uuid>[^/]+)/)?(?<type>[^/]+)/(?<uuid>[^/]+)$})
nil

@Fryguy Fryguy merged commit faf08ea into ManageIQ:master Nov 20, 2024
3 of 4 checks passed
@agrare agrare deleted the parse_event_url_regex branch November 20, 2024 21:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants