semaphore icon indicating copy to clipboard operation
semaphore copied to clipboard

Enhancement: Various override/merge strategies of the environment JSON for API call POST /project/{project_id}/tasks

Open fivaldi opened this issue 3 years ago • 1 comments
trafficstars

I tried passing additional environment variables (override(s)) via

curl -k -X 'POST' \                                                                                                                                                                                            
  'https://<semaphore>/api/project/1/tasks' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' -H 'Authorization: Bearer <token>' \
  -d '{
  "template_id": 7,
  "debug": false,
  "dry_run": false,
  "playbook": "",
  "environment": "{\"some_var\": \"override_value\"}" }'

The task is created, appears correctly in the database with the environment passed in the POST request. All looks good. BUT: The value wasn't reflected in the running task. I would expect this to work as an override (recursive merge of the JSONs) of the pre-set environment.

((( Maybe other strategies (other than recursive merge) could be defined on the templates' level ? This is another story... )))

fivaldi avatar Jun 15 '22 18:06 fivaldi

UPDATE: I checked a bit deeper against the code of services/tasks/runner.go that it actually overrides the environment from the API request. If the variable is not defined in the task's environment, it gets loaded from the API request. I agree that this is a secure solution for untrusted API requests..

So, I am modifying this "bug" issue to a feature request for what I described in the first comment: Provide other strategies on task's level:

  1. [Default/current] task's JSON environment overrides API request JSON environment
  2. API request JSON environment overrides task's JSON environment
  3. The same for 1) with recursive merge strategy
  4. The same for 2) with recursive merge strategy

fivaldi avatar Jun 16 '22 06:06 fivaldi