dblessing / rundeck-ruby

Rundeck Ruby Client - A Ruby wrapper around the Rundeck API
http://blessing.io/rundeck-ruby/
BSD 2-Clause "Simplified" License
17 stars 11 forks source link

Support receiving YAML (and JSON) #32

Open rveznaver opened 9 years ago

rveznaver commented 9 years ago

RunDeck may return YAML or JSON data depending on the request header. However, although the gem supports data export via yaml, internally it does everything via xml, including getting jobs. This poses a problem as jobs are mapped differently depending on the output format which makes comparing two jobs (one from yaml, the other one from the hash made via xml) extremely difficult. It would be best if the gem supported receiving data in other formats. In addition, for this to work a custom parser needs to be added to httparty as yaml parsing was removed from the latest version. Note that RunDeck always specifies the format sent in the http header, so this should be handled automatically based on that (httparty already does this) as error codes are always sent in xml.

dblessing commented 9 years ago

@rveznaver Can you please explain a little more what you mean here? The gem supports import and export of jobs via YAML or XML format. Most other endpoints in Rundeck only return XML or JSON, not YAML. I do see an endpoint I don't currently have in this gem - http://rundeck.org/2.2.2/api/index.html#getting-a-job-definition however it looks largely similar to the export endpoint. In that case I would likely return raw YAML, just like the export function.

Please let me know more about what you're describing and maybe point me to the Rundeck API docs for an example.

rveznaver commented 9 years ago

Hi @dblessing, I was mostly referring to the job endpoint and the fact that httparty + objectified hash do not parse YAML. As far as I have understood the design behind the gem, one should be able to do everything just by accessing the objectified hash (which should be an abstraction of the format). However, since the hash is quite different based on the response format, it should be possible to set this default to yaml as well.

dblessing commented 9 years ago

@rveznaver I can see the usefulness in having a clean objectified hash for a job definition. Let me think about it a bit more and see what I can do.

For now your best bet might be to use the job export endpoint as that will return raw YAML to you. You can easily parse that using Ruby and accomplish a similar result. What do you think?

dblessing commented 9 years ago

Does the following sound like it would solve your problem?

Currently job definitions can be exported/retrieved via XML or YAML. It could be useful to have the option to get an objectified hash of the definition (but not from XML, because it has the funky structure). Parsing the raw YAML definition shouldn't be too hard. This endpoint might be the best place http://rundeck.org/docs/api/index.html#getting-a-job-definition

rveznaver commented 9 years ago

@dblessing, I have only now seen that I can specify the job id in job_exports (i have thought previously it was not possible to get only one job via that endpoint). As for the latter comment, I believe you could generalise it more, but it would solve my problem. Also, please use the latest link to docs: http://rundeck.org/docs/api/index.html#getting-a-job-definition

dblessing commented 9 years ago

Thanks.