semaphore
semaphore copied to clipboard
Enhancement: Various override/merge strategies of the environment JSON for API call POST /project/{project_id}/tasks
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... )))
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:
- [Default/current] task's JSON environment overrides API request JSON environment
- API request JSON environment overrides task's JSON environment
- The same for 1) with recursive merge strategy
- The same for 2) with recursive merge strategy