I’m trying to build a plugin to validate host parameters, based on https://github.com/theforeman/foreman_host_extra_validator.
I’m using a couple of special host parameters on install to facilitate integration with other systems via foreman-hooks. One such example is a parameter to hold the ticket number from our ticketing system. I would like to validate this parameter but my ruby skills cant figure out how to do it. Any help would be appreciated!
I can access the parameter value the same way I access it in templates:
ticket = params['provision-ticket']
(where ‘provision-ticket’ is the name of my host parameter).
But I cant figure out how to reference this parameter so it is marked red in the UI. In the original plugin, this line is used:
errors.add(:name, _('must match regex /%s/') % validate_name_regex) unless shortname =~ /#{validate_name_regex}/
where I guess the symbol ‘:name’ makes the plugin magically signal the UI to mark that form red if validation fails. What do I use instead of ‘:name’ when validating host parameters?
The parameter is represented like this in an api call to /api/hosts:
...
"parameters": [
{
"priority": 70,
"created_at": "2017-09-22 09:52:23 UTC",
"updated_at": "2017-09-22 09:52:23 UTC",
"id": 606,
"name": "provision-ticket",
"value": "cXXXXX"
}
],
...
Any pointers?