<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Aug 11, 2016 at 7:09 AM, Raphaël Pinson <span dir="ltr"><<a href="mailto:raphael.pinson@camptocamp.com" target="_blank">raphael.pinson@camptocamp.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Hello,</div><div><br></div><div>Most of you know the Augeasproviders project, which features Ruby-based providers for Puppet using the Augeas library. At the heart of the Augeasproviders project, the augeasproviders_core library provides methods to map between the Augeas tree and the Puppet type parameters and properties.</div><div><br></div><div>In the same kind of idea, I have started playing with a project using go reflection to map the Augeas tree to go structures.</div><div><br></div><div>The project can be found on GitHub[0]. It is still very fresh (I started it this morning), but it features a few built-in structures for basic files:</div><div><br></div><div>  * Hosts</div><div>  * Passwd</div><div>  * Services</div><div><br></div><div>For now, only parsing (Augeas -> Struct) is supported, but I plan to add writing (Struct -> Augeas) to reflect the structure to the Augeas tree and save the tree.</div><div><br></div><div>Feedback, issues & PRs are welcome!</div></div></blockquote><div><br></div><div>I've been meaning to comment on this for a long time - I think this is really awesome. And I am wondering if this could be turned into something that Augeas supports natively, i.e., a way to retrieve and write parts of the tree in a data structure that's more convenient than the actual tree. Let's say, the data structure should roughly be whatever can be described with JSON (i.e., hashes, arrays, and a handful of scalar types).<br><br>One of the things I always get hung up on when I think about this: how do you describe writing such data and cover both the case of updating existing data and adding new data ? For example, if you read a host record as<br><br><div style="margin-left:40px">"host": {<br></div><div style="margin-left:40px">  "canonical": "<a href="http://host.example.com">host.example.com</a>",<br></div><div style="margin-left:40px">  "ipaddr": "192.168.0.1",<br></div><div style="margin-left:40px">  "alias": [ "a1", "a2" ]<br>}<br><br></div>and then change that and write back<br><br><div style="margin-left:40px">"host": {<br></div><div style="margin-left:40px">  "canonical": "<a href="http://host.example.com">host.example.com</a>",<br></div><div style="margin-left:40px">  "ipaddr": "10.0.0.1",<br></div><div style="margin-left:40px">  "alias": [ "a1_new", "a2", "a3" ]<br>}</div><br></div><div>How do you describe the tree <-> data transformation so that the above roughly leads to the sequence of commands<br><br><div style="margin-left:40px">set ipaddr 10.0.0.1<br></div><div style="margin-left:40px">set alias[1] a1_new<br></div><div style="margin-left:40px">set alias[3] a3<br></div><br></div><div>For something as simple as the hosts file, that's probably doable; but how would you handle something like ssh_config where you can't just blindly append new entries ?<br><br></div><div>This would be incredibly powerful as it would give you a desired-state API to manipulate config rather than the current imperative model that Augeas follows. Are there any lessons from Augeasproviders that could help ?<br><br></div><div>David<br><br></div><div><br> <br></div></div></div></div>