libUCL / UCL as FreeBSD config question

Michael B. Eichorn ike at michaeleichorn.com
Fri Nov 20 19:36:49 UTC 2015


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 5729 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/freebsd-hackers/attachments/20151120/de8df558/attachment.bin>


More information about the freebsd-hackers mailing list