Project

General

Profile

Actions

Feature #31299

open

Support for additional request with xpath

Added by Lukas Zapletal over 3 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Target version:
-
Difficulty:
Triaged:
No
Fixed in Releases:
Found in Releases:

Description

Webhooks plugin could be used to directly connect to some backend services which are simple enough (e.g. HTTP REST) to do CRUD. Creating resources is straightforward, but to update and delete additional request usually needs to be done to find out resource ID.

For that, we can implement a helpers: http_request and json_xpath, user should be able to use them in URL ERB to generate. For example for Ansible Tower (AWX):

JSON.parse(::ForemanWebhooks::WebhookService.request(url: "https://tower.virt/api/v2/hosts/?name=localhost", user: "admin", password: "admin").body)["results"][0]["id"]

The helper will only be able to connect to the webhook service itself, so credentials, URL, SSL info all is already known and helper cannot change that, but it can change: HTTP method, path and payload:

http_request(:GET, '/api/v2/hosts/?name=localhost', '')

This can be chained with an "xpath-like" library (https://github.com/joshbuddy/jsonpath) for complete solution:

json_xpath("//results/[0]/id", http_request(:GET, '/api/v2/hosts/?name=localhost', '')) => 42

The request will be done during request in Rails, not in the background job. This is the only drawback, an optional (short) timeout will be present to solve this issue.


Related issues 1 (1 open0 closed)

Related to Foreman - Tracker #30290: Foreman webhooks integration storyNewLukas Zapletal

Actions
Actions #1

Updated by Lukas Zapletal over 3 years ago

Actions

Also available in: Atom PDF