Feature #32366
openIncorrect ERB in the webhook URL is hard to debug
Description
Many REST APIs have paths like /api/hosts/:id/play_roles. The :id is a dynamic attribute. While I could create a shellhook that allows me to make the target URL dynamic, in many cases I know the id based on the @object, e.g. it's a host name and I'd prefer to simply put that into the target URL field.
If we don't want to go to full ERB, perhaps we could have some custom syntax, such as /api/hosts/:object.name/play_roles, but having the ERB there seems more expected since we use it everywhere else.
Updated by Oleh Fedorenko almost 3 years ago
Have you tried this on the latest version? I think we support it already: https://github.com/theforeman/foreman_webhooks/commit/8dd5f6f5ea14815d7f1242c1b11e69b135758162
The URL could look like: https://fqdn/api/hosts/<%= @object.id %>/play_roles
Updated by Marek Hulán almost 3 years ago
- Subject changed from Add ERB rendering for the target URL to Incorrect ERB in the webhook URL is hard to debug
Ah, it works fine! The only issue is, if I have an error in the erb, e.g. using @object.fqdn it fails and the log does not contain much information in production setup:
2021-05-25T14:44:59 [I|app|116982eb] Processed 1 tasks from queue 'Host::Managed Main', completed 2/2 2021-05-25T14:44:59 [I|app|116982eb] ForemanWebhooks::EventSubscriber: host_destroyed.event.foreman event received 2021-05-25T14:44:59 [E|app|116982eb] Failed to save: 2021-05-25T14:44:59 [I|app|116982eb] Redirected to https://foreman-nuc2.usersys.redhat.com/hosts
When I fixed that to @object.name, it worked nicely! I'm changing the subject of this, if we could add some more information to the log, that would be great