Settings
The Settings resource is a key-value store with several use cases.
Keys have to be strings and values are interpreted as a YAML document. Settings can be manipulated via the user interface, via the REST API, and via flow scripts. The examples in this document are limited to one method per use case. The method described is interchangeable with any of the other methods.
To manipulate Settings using the command line you need an authorization token. Please see the Authentication documentation on how to obtain an authorization token.
Examples
Here are some common examples of how the Settings resource can be used.
Storing Configuration Parameters
Let’s assume you use a system user to authenticate to your servers. You can store the name of the system user in a setting record:
$ curl -s 'https://<my-workspace-name>.cloudomation.com/api/latest/setting' -d '{"name":"system_user","value":"user123"}' -H "Authorization: $TOKEN"
Your flow scripts can then read the setting value whenever they want to authenticate:
import flow_apidef handler(system: flow_api.System, this: flow_api.Execution):user = system.setting('system_user').get('value')this.task('SSH',hostname='test.example.com',login=user,script='systemctl restart httpd')
If you choose to change the user name you only need to update it in one place: the setting value:
$ curl -s -X PATCH 'https://<my-workspace-name>.cloudomation.com/api/latest/setting/system_user?by=name' -d '{"value":"user789"}' -H "Authorization: $TOKEN"
and with the next execution your flow scripts will read and use the new value.
Storing Output
Your flow scripts can write the value of a setting to represent the current status of the execution:
import flow_apidef handler(system: flow_api.System, this: flow_api.Execution):system.setting('occurrences_found').save(value=42)return this.success('all done')
Other flow scripts can read the value and adapt their behaviour accordingly:
import flow_apidef handler(system: flow_api.System, this: flow_api.Execution):count = system.setting('occurrences_found').get('value')if count > 32:this.task('SMTP',smtp_host='mail.example.com',from='no-reply@example.com',to='kevin@example.com',subject='counter alert',text=f'found {count} occurrences')return this.success('all done')
The value can also be retrieved using the REST API:
$ curl -s 'https://<my-workspace-name>.cloudomation.com/api/latest/setting/occurrences_found?by=name' -H "Authorization: $TOKEN" | jq .{"setting": {"client_id": "...","created_at": "2020-01-09T10:59:20.862215+00:00","created_by": "...","id": "...","lock_id": null,"modified_at": "2020-02-18T08:34:15.050446+00:00","modified_by": "...","name": "occurences_found","size_bytes": 49,"value": 42}}