libUCL / UCL as FreeBSD config question

Allan Jude allanjude at freebsd.org
Fri Nov 20 19:39:57 UTC 2015


On 2015-11-20 14:36, Michael B. Eichorn wrote:
> On Fri, 2015-11-20 at 13:06 -0500, Allan Jude wrote:
>>  
>> Although some limitation in libucl mean that, if you have a config
>> that
>> has comments in it, the comments are lost, as they are not
>> represented
>> in the in-memory version of the object that then gets serialized for
>> output. If you treat the config files as a database, then this is
>> fine,
>> but if the user expects to still hand edit them with an editor, this
>> is
>> a fairly big POLA violation.
>>
> 
> Even if someday we stop editing by hand, comments are far to useful
> IMHO to drop yet. Context is very important to what we do, and
> sometimes keys are just to cryptic.
> 
> I think I see two ways to avoid the POLA violation (but I am still
> rather new at this so be gentle)
> 
> 1) Add special keys for use in memory 'value' and 'comment' such that
> the file:
> 
> FreeBSD: {
>   url: "pkg+http://pkg.FreeBSD.org/${ABI}/latest",
>   mirror_type: "srv",
>   signature_type: "fingerprints",
>   # A comment about fingerprints
>   # More comments
>   fingerprints: "/usr/share/keys/pkg", # an inline comment
>   enabled: yes
> }
> 
> becomes in memory:
> 
> FreeBSD: {
>   url: "pkg+http://pkg.FreeBSD.org/${ABI}/latest",
>  
> mirror_type: "srv",
>   signature_type: "fingerprints",
>   fingerprints: {
>  
>   value: "/usr/share/keys/pkg"
>     comment: {
>       above: "A comment
> about fingerprints\nMore comments"
>       inline: "an inline comment"
>    
> }
>   }
>   enabled: yes
> }
> 
> uclcmd should just return value like:
> 
> # uclcmd get -f /etc/pkg/FreeBSD.conf FreeBSD.fingerprints
> 
> returns
> /usr/share/keys/pkg
> 
> unless the comment (C?) flag is used:
> # uclcmd get -f -C /etc/pkg/FreeBSD.conf FreeBSD.fingerprints
> 
> returns
> # A comment about fingerprints
> # More comments
> /usr/share/keys/pkg	# an inline comment
> 
> Finally if uclcmd set is used, if the session is interactive, ask the user what to do about the existing comment. If not append a note of the change to the comment so that the file becomes:
> 
> FreeBSD: {
>   url: "pkg+http://pkg.FreeBSD.org/${ABI}/latest",
>   mirror_type: "srv",
>   signature_type: "fingerprints",
>   # A comment about fingerprints
>   # More comments
>   ## Comments may be outdated, non-interactive edit 20151120T1400
>   ## /usr/share/keys/pkg -> /root/keys/pkg
>   fingerprints: "/root/keys/pkg", # an inline comment
>   enabled: yes
> }
> 
> 2) Assume everything can be commented, everything gets an extra pointer for a potential comment string. Output all comments as the 'above' style (bonus: comments become predictible in style). Same uclcmd behavior as described above.
> 
> The above are just ideas (and I know next to nothing about the guts of libucl), but I think comments are important, if this or something else works I am willing to help with the implementation.
> 
> Regards,
> Ike
> 

This was discussed at the developer summit at BSDCan, sadly the video is
not online yet.

The issue is that UCL allows comments anywhere, for example:

#above
FreeBSD: {
   /* before */ url: "pkg+http://pkg.FreeBSD.org/${ABI}/latest",
   mirror_type: /* middle */ "srv",
   signature_type: "fingerprints", /* after */
   # under
   fingerprints: "/root/keys/pkg", # inline-after
   enabled: yes
}

Etc. So the solution that was discussed was changing libucl to use an
Abstract Syntax Tree, but that is a lot of work. So for now, I am not
sure what the best approach is.



-- 
Allan Jude

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 834 bytes
Desc: OpenPGP digital signature
URL: <http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20151120/8cc19e31/attachment.bin>


More information about the freebsd-hackers mailing list