Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 274 lines (230 sloc) 7.016 kb
2083382 Domen Kožar first non-working version
authored
1 (*
2 Module: Bacula
3 Parses: /etc/bacula/*.conf
4
5 Author: Domen Kožar <domen@dev.si>
6
7 About: Reference
8 This lens tries to be ...
9
10 About: License
11 This file is licenced under the LGPL v2+, like the rest of Augeas.
12
13 About: Lens Usage
14 See <lns>.
15
16 About: Configuration files
17 This lens applies to /etc/bacula/*.conf.
18
19 About: Examples
20 The <test_bacula.aug> file contains various examples and tests.
21 *)
22
23
24 module Bacula =
25 autoload xfm
26
b8fab91 Domen Kožar handle more edge cases
authored
27 let indent = Util.del_opt_ws "\t"
28 let equal = del /[ \t]*=[ \t]*/ " = "
9675b46 Domen Kožar refactor a bit
authored
29 let key_name = /[a-zA-Z][a-zA-Z ]+[a-zA-Z]/
9137ad5 Raphaël Pinson Don't allow ; in values
raphink authored
30
3eabf32 Domen Kožar support quoted values
authored
31 let val_quote = [square /"/ (store /([^"#]|\\")+/)]
32 let val = [label "" . store /[^}"#\n\t; ]([^}"#\n;]*[^}"#\n\t; ])?/]
2083382 Domen Kožar first non-working version
authored
33
3eabf32 Domen Kožar support quoted values
authored
34 let keyvalue = key key_name . equal . (val|val_quote)
2a3f372 Raphaël Pinson Add top-level statements
raphink authored
35 let include = label "@include" . Util.del_str "@" . store /[^# \t\n@};]+/
9675b46 Domen Kožar refactor a bit
authored
36
648f707 Raphaël Pinson entry_noindent_noeol maybe contain a semicolon
raphink authored
37 let semicolon = del /([ \t]*;)?/ ""
17a7706 Raphaël Pinson Use Build.block_generic and include semicolon in comment_or_eol
raphink authored
38 let eol = del /[ \t]*(;|(#[ \t]*)?\n)/ "\n"
39 let comment_or_eol = Util.comment_eol | eol
efe3230 Raphaël Pinson entry_noindent_noeol may also contain comment_eol
raphink authored
40 let comment_or_semicolon = Util.comment_eol | semicolon
17a7706 Raphaël Pinson Use Build.block_generic and include semicolon in comment_or_eol
raphink authored
41
42 let line (sto:lens) = [ sto . comment_or_eol ]
efe3230 Raphaël Pinson entry_noindent_noeol may also contain comment_eol
raphink authored
43 let line_noeol (sto:lens) = [ sto . comment_or_semicolon ]
17a7706 Raphaël Pinson Use Build.block_generic and include semicolon in comment_or_eol
raphink authored
44
8ed99bc Raphaël Pinson Support recursive blocks
raphink authored
45 let rec block =
079d3d3 Raphaël Pinson spaces
raphink authored
46 let entry = Util.empty | (indent . (line keyvalue | line include | block))
8ed99bc Raphaël Pinson Support recursive blocks
raphink authored
47 in let entry_noindent = line keyvalue | line include | block
48 in let entry_noindent_noeol = line_noeol keyvalue | line_noeol include | block
17a7706 Raphaël Pinson Use Build.block_generic and include semicolon in comment_or_eol
raphink authored
49 in let entry_noeol = indent . entry_noindent_noeol
197d26d Raphaël Pinson Prepare the way for recursive blocks
raphink authored
50 in [ label "@block" . store /[a-zA-Z]+/
17a7706 Raphaël Pinson Use Build.block_generic and include semicolon in comment_or_eol
raphink authored
51 . Build.block_generic
52 entry (* entry *)
53 entry_noindent (* entry_noindent *)
54 entry_noeol (* entry_noeol *)
55 entry_noindent_noeol (* entry_noindent_noeol *)
56 Util.comment (* comment *)
57 Util.comment_noindent (* comment_noindent *)
c2a2068 Raphaël Pinson Blocks can follow each other without \n
raphink authored
58 /[ \t\n]*\{[ \t\n]*/ (* ldelim_re *)
17a7706 Raphaël Pinson Use Build.block_generic and include semicolon in comment_or_eol
raphink authored
59 Build.block_rdelim_re (* rdelim_re *)
60 " {\n\t" (* ldelim_default *)
61 Build.block_rdelim_default (* rdelim_default *)
c2a2068 Raphaël Pinson Blocks can follow each other without \n
raphink authored
62 ]
2083382 Domen Kožar first non-working version
authored
63
2a3f372 Raphaël Pinson Add top-level statements
raphink authored
64 let statement = Util.indent . (line keyvalue | line include | block)
65
66 let lns = (statement|Util.empty|Util.comment)*
2083382 Domen Kožar first non-working version
authored
67
68 let filter = incl "/etc/bacula/*.conf"
69 . Util.stdexcl
70
71 let xfm = transform lns filter
fb627d1 Domen Kožar add more tests
authored
72
73 (* TODO: put tests *)
2083382 Domen Kožar first non-working version
authored
74
17a7706 Raphaël Pinson Use Build.block_generic and include semicolon in comment_or_eol
raphink authored
75 test (Bacula.line keyvalue) get "Name = kaki-sd\n" =
3eabf32 Domen Kožar support quoted values
authored
76 {"Name"
77 {"" = "kaki-sd"}
78 }
17a7706 Raphaël Pinson Use Build.block_generic and include semicolon in comment_or_eol
raphink authored
79
2a3f372 Raphaël Pinson Add top-level statements
raphink authored
80 test (Bacula.line include) get "@/etc/foo.conf\n" =
81 {"@include" = "/etc/foo.conf"}
17a7706 Raphaël Pinson Use Build.block_generic and include semicolon in comment_or_eol
raphink authored
82
83 test (Bacula.line keyvalue) get "Name = kaki-sd;" =
3eabf32 Domen Kožar support quoted values
authored
84 {"Name"
85 {"" = "kaki-sd"}
86 }
17a7706 Raphaël Pinson Use Build.block_generic and include semicolon in comment_or_eol
raphink authored
87
648f707 Raphaël Pinson entry_noindent_noeol maybe contain a semicolon
raphink authored
88 test (Bacula.line include) get "@foobar ;" =
17a7706 Raphaël Pinson Use Build.block_generic and include semicolon in comment_or_eol
raphink authored
89 {"@include" = "foobar"}
90
c2a2068 Raphaël Pinson Blocks can follow each other without \n
raphink authored
91 test Bacula.lns get "Storage {\n Name = kaki-sd\n}" =
197d26d Raphaël Pinson Prepare the way for recursive blocks
raphink authored
92 {"@block" = "Storage"
3eabf32 Domen Kožar support quoted values
authored
93 {"Name"
94 {"" = "kaki-sd"}
95 }
2083382 Domen Kožar first non-working version
authored
96 }
b8fab91 Domen Kožar handle more edge cases
authored
97
0975c52 Domen Kožar support whitespace in key
authored
98 (* value can have quotes *)
3eabf32 Domen Kožar support quoted values
authored
99 test Bacula.lns get "Storage {\n Name = \"kaki-sd\"\n}" =
197d26d Raphaël Pinson Prepare the way for recursive blocks
raphink authored
100 {"@block" = "Storage"
3eabf32 Domen Kožar support quoted values
authored
101 {"Name"
102 {"\"" = "kaki-sd"}
103 }
b8fab91 Domen Kožar handle more edge cases
authored
104 }
105
0975c52 Domen Kožar support whitespace in key
authored
106 (* whitespace in key *)
c2a2068 Raphaël Pinson Blocks can follow each other without \n
raphink authored
107 test Bacula.lns get "Storage {\n Pid Directory = kaki sd\n}" =
197d26d Raphaël Pinson Prepare the way for recursive blocks
raphink authored
108 {"@block" = "Storage"
3eabf32 Domen Kožar support quoted values
authored
109 {"Pid Directory"
110 {"" = "kaki sd"}
111 }
0975c52 Domen Kožar support whitespace in key
authored
112 }
113
78c548b Domen Kožar support one char values
authored
114 (* one char value *)
1099280 Domen Kožar add new test
authored
115 test Bacula.lns get "Storage {\n Maximum Concurrent Jobs = 1\n}" =
116 {"@block" = "Storage"
3eabf32 Domen Kožar support quoted values
authored
117 {"Maximum Concurrent Jobs"
118 {"" = "1"}
119 }
1099280 Domen Kožar add new test
authored
120 }
121
0975c52 Domen Kožar support whitespace in key
authored
122 (* semicolon *)
c2a2068 Raphaël Pinson Blocks can follow each other without \n
raphink authored
123 test Bacula.lns get "Storage {\n Name = kaki-sd;\n}" =
197d26d Raphaël Pinson Prepare the way for recursive blocks
raphink authored
124 {"@block" = "Storage"
3eabf32 Domen Kožar support quoted values
authored
125 {"Name"
126 {"" = "kaki-sd"}
127 }
b8fab91 Domen Kožar handle more edge cases
authored
128 }
129
0975c52 Domen Kožar support whitespace in key
authored
130 (* inline comment *)
c2a2068 Raphaël Pinson Blocks can follow each other without \n
raphink authored
131 test Bacula.lns get "Storage {\n Name = kaki-sd # just a comment\n}" =
197d26d Raphaël Pinson Prepare the way for recursive blocks
raphink authored
132 {"@block" = "Storage"
3eabf32 Domen Kožar support quoted values
authored
133 {"Name"
134 { "" = "kaki-sd" }
135 { "#comment" = "just a comment"}
136 }
b8fab91 Domen Kožar handle more edge cases
authored
137 }
138
fb627d1 Domen Kožar add more tests
authored
139 (* comment as part of directive *)
d89cf72 Raphaël Pinson merge
raphink authored
140 test Bacula.lns get "Storage {\n Name = kaki-sd\n # just a comment\n}" =
fb627d1 Domen Kožar add more tests
authored
141 {"@block" = "Storage"
3eabf32 Domen Kožar support quoted values
authored
142 {"Name"
143 { "" = "kaki-sd" }
144 }
145 { "#comment" = "just a comment"}
fb627d1 Domen Kožar add more tests
authored
146 }
147
1099280 Domen Kožar add new test
authored
148 (* comment after } *)
963f87b Raphaël Pinson Fix comment with newline
raphink authored
149 test Bacula.lns get "Storage {\n Name = kaki-sd\n}\n # just a comment\n" =
fb627d1 Domen Kožar add more tests
authored
150 {"@block" = "Storage"
3eabf32 Domen Kožar support quoted values
authored
151 {"Name"
152 { "" = "kaki-sd" }
153 }
154 }
963f87b Raphaël Pinson Fix comment with newline
raphink authored
155 { }
156 { "#comment" = "just a comment"}
fb627d1 Domen Kožar add more tests
authored
157
0975c52 Domen Kožar support whitespace in key
authored
158 (* multiple values *)
3eabf32 Domen Kožar support quoted values
authored
159 test Bacula.lns get "Storage {\n Name = kaki-sd\nFoo = moo\n}" =
197d26d Raphaël Pinson Prepare the way for recursive blocks
raphink authored
160 {"@block" = "Storage"
3eabf32 Domen Kožar support quoted values
authored
161 {"Name"
162 { "" = "kaki-sd" }
163 }
164 {"Foo"
165 { "" = "moo" }
166 }
b8fab91 Domen Kožar handle more edge cases
authored
167 }
9675b46 Domen Kožar refactor a bit
authored
168
35d6e43 Domen Kožar test for toplevel key/value
authored
169 (* toplevel key/value for include files *)
3eabf32 Domen Kožar support quoted values
authored
170 test Bacula.lns get "Name = kaki-sd\nFoo = moo\n" =
171 {"Name"
172 { "" = "kaki-sd" }
173 }
174 {"Foo"
175 { "" = "moo" }
176 }
35d6e43 Domen Kožar test for toplevel key/value
authored
177
baa73ce Domen Kožar add a test with quote escaping
authored
178 (* escaping quotes in value *)
3eabf32 Domen Kožar support quoted values
authored
179 test Bacula.lns get "Storage {\nName = \"foo \\" bar\"\n}" =
baa73ce Domen Kožar add a test with quote escaping
authored
180 {"@block" = "Storage"
3eabf32 Domen Kožar support quoted values
authored
181 {"Name"
182 { "\"" = "foo \\" bar" }
183 }
baa73ce Domen Kožar add a test with quote escaping
authored
184 }
185
33febfb Domen Kožar refactor
authored
186 (* newline comment *)
3eabf32 Domen Kožar support quoted values
authored
187 test Bacula.lns get "Storage {\n Name = kaki-sd\n# just a comment\n}" =
197d26d Raphaël Pinson Prepare the way for recursive blocks
raphink authored
188 {"@block" = "Storage"
3eabf32 Domen Kožar support quoted values
authored
189 {"Name"
190 { "" = "kaki-sd" }
191 }
192 {"#comment" = "just a comment" }
33febfb Domen Kožar refactor
authored
193 }
194
1099280 Domen Kožar add new test
authored
195 (* include statements *)
c2a2068 Raphaël Pinson Blocks can follow each other without \n
raphink authored
196 test Bacula.lns get "Storage {\n @/etc/foo.conf\n}" =
197d26d Raphaël Pinson Prepare the way for recursive blocks
raphink authored
197 {"@block" = "Storage"
9675b46 Domen Kožar refactor a bit
authored
198 {"@include" = "/etc/foo.conf"}
199 }
c2a2068 Raphaël Pinson Blocks can follow each other without \n
raphink authored
200
3eabf32 Domen Kožar support quoted values
authored
201 test Bacula.lns get "Storage {\n Name = kaki-sd}" =
c2a2068 Raphaël Pinson Blocks can follow each other without \n
raphink authored
202 {"@block" = "Storage"
3eabf32 Domen Kožar support quoted values
authored
203 {"Name"
204 { "" = "kaki-sd" }
205 }
c2a2068 Raphaël Pinson Blocks can follow each other without \n
raphink authored
206 }
207
8ed99bc Raphaël Pinson Support recursive blocks
raphink authored
208 test Bacula.lns get "FileSet { Include { signature = SHA1 } }" =
209 { "@block" = "FileSet"
210 { "@block" = "Include"
3eabf32 Domen Kožar support quoted values
authored
211 { "signature"
212 { "" = "SHA1" }
213 }
8ed99bc Raphaël Pinson Support recursive blocks
raphink authored
214 }
215 }
9675b46 Domen Kožar refactor a bit
authored
216
33febfb Domen Kožar refactor
authored
217 test Bacula.lns get "FileSet {
218 Name = \"DefaultSet\"
219 Include {
220 Options {
221 signature = SHA1
222 noatime = yes
223 }
224 File = /etc
225 }
226 }" =
8ed99bc Raphaël Pinson Support recursive blocks
raphink authored
227 {"@block" = "FileSet"
3eabf32 Domen Kožar support quoted values
authored
228 { "Name"
229 { "\"" = "DefaultSet" }
230 }
8ed99bc Raphaël Pinson Support recursive blocks
raphink authored
231 {"@block" = "Include"
232 {"@block" = "Options"
3eabf32 Domen Kožar support quoted values
authored
233 { "signature"
234 { "" = "SHA1" }
235 }
236 { "noatime"
237 { "" = "yes" }
238 }
33febfb Domen Kožar refactor
authored
239 }
8ed99bc Raphaël Pinson Support recursive blocks
raphink authored
240 { }
3eabf32 Domen Kožar support quoted values
authored
241 { "File"
242 { "" = "/etc" }
243 }
33febfb Domen Kožar refactor
authored
244 }
245 }
fb627d1 Domen Kožar add more tests
authored
246
1099280 Domen Kožar add new test
authored
247 (* include top level statements *)
963f87b Raphaël Pinson Fix comment with newline
raphink authored
248 test Bacula.lns get "@/etc/foo.conf\n" =
fb627d1 Domen Kožar add more tests
authored
249 {"@include" = "/etc/foo.conf"}
33febfb Domen Kožar refactor
authored
250
1099280 Domen Kožar add new test
authored
251
d89cf72 Raphaël Pinson merge
raphink authored
252 (* Blocks can follow each other without \n *)
253 test Bacula.lns get "Storage{Name = kaki sd}Storage{Name = kaki-sd}" =
254 { "@block" = "Storage"
3eabf32 Domen Kožar support quoted values
authored
255 {"Name"
256 { "" = "kaki sd" }
257 }
d89cf72 Raphaël Pinson merge
raphink authored
258 }
259 { "@block" = "Storage"
3eabf32 Domen Kožar support quoted values
authored
260 {"Name"
261 { "" = "kaki-sd" }
262 }
d89cf72 Raphaël Pinson merge
raphink authored
263 }
33febfb Domen Kožar refactor
authored
264
9ca1843 Raphaël Pinson mergeSupport recursive blocks
raphink authored
265 (* recursive directives *)
266 test Bacula.lns get "FileSet { Include { signature = SHA1 } }" =
267 { "@block" = "FileSet"
268 { "@block" = "Include"
3eabf32 Domen Kožar support quoted values
authored
269 { "signature"
270 { "" = "SHA1" }
271 }
9ca1843 Raphaël Pinson mergeSupport recursive blocks
raphink authored
272 }
273 }
Something went wrong with that request. Please try again.