3 Parses Trapperkeeper configuration files
5 Author: Raphael Pinson <raphael.pinson@camptocamp.com>
8 This file is licenced under the LGPL v2+, like the rest of Augeas.
13 About: Configuration files
14 This lens applies to Trapperkeeper webservice configuration files. See <filter>.
17 The <Test_Trapperkeeper> file contains various examples and tests.
19 module Trapperkeeper =
23 (************************************************************************
24 * Group: USEFUL PRIMITIVES
25 *************************************************************************)
28 let empty = Util.empty
31 let comment = Util.comment
34 let sep = del /[ \t]*[:=]/ ":"
36 (* View: sep_with_spc *)
37 let sep_with_spc = sep . Sep.opt_space
39 (************************************************************************
40 * Group: BLOCKS (FROM 1.2, FOR 0.10 COMPATIBILITY)
41 *************************************************************************)
43 (* Variable: block_ldelim_newlines_re *)
44 let block_ldelim_newlines_re = /[ \t\n]+\{([ \t\n]*\n)?/
46 (* Variable: block_rdelim_newlines_re *)
47 let block_rdelim_newlines_re = /[ \t]*\}/
49 (* Variable: block_ldelim_newlines_default *)
50 let block_ldelim_newlines_default = "\n{\n"
52 (* Variable: block_rdelim_newlines_default *)
53 let block_rdelim_newlines_default = "}"
55 (************************************************************************
57 * A block enclosed in brackets, with newlines forced
58 * and indentation defaulting to a tab.
61 * entry:lens - the entry to be stored inside the block.
62 * This entry should not include <Util.empty>,
63 * <Util.comment> or <Util.comment_noindent>,
64 * should be indented and finish with an eol.
65 ************************************************************************)
66 let block_newlines (entry:lens) (comment:lens) =
67 del block_ldelim_newlines_re block_ldelim_newlines_default
68 . ((entry | comment) . (Util.empty | entry | comment)*)?
69 . del block_rdelim_newlines_re block_rdelim_newlines_default
71 (************************************************************************
73 *************************************************************************)
75 let opt_dquot (lns:lens) = del /"?/ "" . lns . del /"?/ ""
78 let simple = [ Util.indent . label "@simple" . opt_dquot (store /[A-Za-z0-9_.\/-]+/) . sep_with_spc
79 . [ label "@value" . opt_dquot (store /[^,"\[ \t\n]+/) ]
84 let lbrack = Util.del_str "["
85 in let rbrack = Util.del_str "]"
86 in let opt_space = del /[ \t]*/ ""
87 in let comma = opt_space . Util.del_str "," . opt_space
88 in let elem = [ seq "elem" . opt_dquot (store /[^,"\[ \t\n]+/) ]
89 in let elems = counter "elem" . Build.opt_list elem comma
90 in [ Util.indent . label "@array" . store Rx.word
91 . sep_with_spc . lbrack . Sep.opt_space
92 . (elems . Sep.opt_space)?
96 let hash (lns:lens) = [ Util.indent . label "@hash" . store Rx.word . sep
97 . block_newlines lns Util.comment
101 (************************************************************************
103 *************************************************************************)
105 (* Just for typechecking *)
106 let entry_no_rec = hash (simple|array)
109 let rec entry = hash (entry|simple|array)
111 (************************************************************************
112 * Group: LENS AND FILTER
113 *************************************************************************)
116 let lns = (empty|comment)* . (entry . (empty|comment)*)*
118 (* Variable: filter *)
119 let filter = incl "/etc/puppetserver/conf.d/*"
120 . incl "/etc/puppetlabs/puppetserver/conf.d/*"
123 let xfm = transform lns filter