Imported Upstream version 1.7.0
[platform/upstream/augeas.git] / lenses / redis.aug
1 (*
2 Module: Redis
3   Parses Redis's configuration files
4
5 Author: Marc Fournier <marc.fournier@camptocamp.com>
6
7 About: Reference
8     This lens is based on Redis's default redis.conf
9
10 About: Usage Example
11 (start code)
12 augtool> set /augeas/load/Redis/incl "/etc/redis/redis.conf"
13 augtool> set /augeas/load/Redis/lens "Redis.lns"
14 augtool> load
15
16 augtool> get /files/etc/redis/redis.conf/vm-enabled
17 /files/etc/redis/redis.conf/vm-enabled = no
18 augtool> print /files/etc/redis/redis.conf/rename-command[1]/
19 /files/etc/redis/redis.conf/rename-command
20 /files/etc/redis/redis.conf/rename-command/from = "CONFIG"
21 /files/etc/redis/redis.conf/rename-command/to = "CONFIG2"
22
23 augtool> set /files/etc/redis/redis.conf/activerehashing no
24 augtool> save
25 Saved 1 file(s)
26 augtool> set /files/etc/redis/redis.conf/save[1]/seconds 123
27 augtool> set /files/etc/redis/redis.conf/save[1]/keys 456
28 augtool> save
29 Saved 1 file(s)
30 (end code)
31    The <Test_Redis> file also contains various examples.
32
33 About: License
34   This file is licensed under the LGPL v2+, like the rest of Augeas.
35 *)
36
37 module Redis =
38 autoload xfm
39
40 let k = Rx.word
41 let v = /[^ \t\n'"]+/
42 let comment = Util.comment
43 let empty = Util.empty
44 let indent = Util.indent
45 let eol = Util.eol
46 let del_ws_spc = Util.del_ws_spc
47 let dquote = Util.del_str "\""
48
49 (* View: standard_entry
50 A standard entry is a key-value pair, separated by blank space, with optional
51 blank spaces at line beginning & end. The value part can be optionnaly enclosed
52 in single or double quotes. Comments at end-of-line ar NOT allowed by
53 redis-server.
54 *)
55 let standard_entry =
56      let reserved_k = "save" | "rename-command" | "slaveof"
57                     | "client-output-buffer-limit"
58   in let entry_noempty = [ indent . key k . del_ws_spc
59                          . Quote.do_quote_opt_nil (store v) . eol ]
60   in let entry_empty = [ indent . key (k - reserved_k) . del_ws_spc
61                          . dquote . store "" . dquote . eol ]
62   in entry_noempty | entry_empty
63
64 let save = /save/
65 let seconds = [ label "seconds" . Quote.do_quote_opt_nil (store Rx.integer) ]
66 let keys = [ label "keys" . Quote.do_quote_opt_nil (store Rx.integer) ]
67 (* View: save_entry
68 Entries identified by the "save" keyword can be found more than once. They have
69 2 mandatory parameters, both integers. The same rules as standard_entry apply
70 for quoting, comments and whitespaces.
71 *)
72 let save_entry = [ indent . key save . del_ws_spc . seconds . del_ws_spc . keys . eol ]
73
74 let slaveof = /slaveof/
75 let ip = [ label "ip" . Quote.do_quote_opt_nil (store Rx.ip) ]
76 let port = [ label "port" . Quote.do_quote_opt_nil (store Rx.integer) ]
77 (* View: slaveof_entry
78 Entries identified by the "slaveof" keyword can be found more than once. They
79 have 2 mandatory parameters, the 1st one is an IP address, the 2nd one is a
80 port number. The same rules as standard_entry apply for quoting, comments and
81 whitespaces.
82 *)
83 let slaveof_entry = [ indent . key slaveof . del_ws_spc . ip . del_ws_spc . port . eol ]
84
85 let renamecmd = /rename-command/
86 let from = [ label "from" . Quote.do_quote_opt_nil (store Rx.word) ]
87 let to = [ label "to" . Quote.do_quote_opt_nil (store Rx.word) ]
88 (* View: save_entry
89 Entries identified by the "rename-command" keyword can be found more than once.
90 They have 2 mandatory parameters, both strings. The same rules as
91 standard_entry apply for quoting, comments and whitespaces.
92 *)
93 let renamecmd_entry = [ indent . key renamecmd . del_ws_spc . from . del_ws_spc . to . eol ]
94
95 let cobl_cmd = /client-output-buffer-limit/
96 let class = [ label "class" . Quote.do_quote_opt_nil (store Rx.word) ]
97 let hard_limit = [ label "hard_limit" . Quote.do_quote_opt_nil (store Rx.word) ]
98 let soft_limit = [ label "soft_limit" . Quote.do_quote_opt_nil (store Rx.word) ]
99 let soft_seconds = [ label "soft_seconds" . Quote.do_quote_opt_nil (store Rx.integer) ]
100 (* View: client_output_buffer_limit_entry
101 Entries identified by the "client-output-buffer-limit" keyword can be found
102 more than once. They have four mandatory paramters, of which the first is a
103 string, the last one is an integer and the others are either integers or words,
104 although redis is very liberal and takes "4242yadayadabytes" as a valid limit.
105 The same rules as standard_entry apply for quoting, comments and whitespaces.
106 *)
107 let client_output_buffer_limit_entry =
108   [ indent . key cobl_cmd . del_ws_spc . class . del_ws_spc . hard_limit .
109     del_ws_spc . soft_limit . del_ws_spc . soft_seconds . eol ]
110
111 let entry = standard_entry
112           | save_entry
113           | renamecmd_entry
114           | slaveof_entry
115           | client_output_buffer_limit_entry
116
117 (* View: lns
118 The Redis lens
119 *)
120 let lns = (comment | empty | entry )*
121
122 let filter = incl "/etc/redis/redis.conf"
123
124 let xfm = transform lns filter