Bump to 1.14.1
[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" | "replicaof" | "slaveof"
57                     | "bind" | "client-output-buffer-limit"
58                     | "sentinel"
59   in let entry_noempty = [ indent . key (k - reserved_k) . del_ws_spc
60                          . Quote.do_quote_opt_nil (store v) . eol ]
61   in let entry_empty = [ indent . key (k - reserved_k) . del_ws_spc
62                          . dquote . store "" . dquote . eol ]
63   in entry_noempty | entry_empty
64
65 let save = /save/
66 let seconds = [ label "seconds" . Quote.do_quote_opt_nil (store Rx.integer) ]
67 let keys = [ label "keys" . Quote.do_quote_opt_nil (store Rx.integer) ]
68 let save_val =
69      let save_val_empty = del_ws_spc . dquote . store "" . dquote
70   in let save_val_sec_keys = del_ws_spc . seconds . del_ws_spc . keys
71   in save_val_sec_keys | save_val_empty
72
73 (* View: save_entry
74 Entries identified by the "save" keyword can be found more than once. They have
75 2 mandatory parameters, both integers or a single parameter that is empty double quoted
76 string. The same rules as standard_entry apply for quoting, comments and whitespaces.
77 *)
78 let save_entry = [ indent . key save . save_val . eol ]
79
80 let replicaof = /replicaof|slaveof/
81 let ip = [ label "ip" . Quote.do_quote_opt_nil (store Rx.ip) ]
82 let port = [ label "port" . Quote.do_quote_opt_nil (store Rx.integer) ]
83 (* View: replicaof_entry
84 Entries identified by the "replicaof" keyword can be found more than once. They
85 have 2 mandatory parameters, the 1st one is an IP address, the 2nd one is a
86 port number. The same rules as standard_entry apply for quoting, comments and
87 whitespaces.
88 *)
89 let replicaof_entry = [ indent . key replicaof . del_ws_spc . ip . del_ws_spc . port . eol ]
90
91 let sentinel_global_entry =
92      let keys  = "deny-scripts-reconfig" | "current-epoch" | "myid"
93   in store keys .
94        del_ws_spc . [ label "value" . store ( Rx.word | Rx.integer ) ]
95
96 let sentinel_cluster_setup =
97      let keys = "config-epoch" | "leader-epoch"
98   in store keys .
99        del_ws_spc . [ label "cluster" . store Rx.word ] .
100        del_ws_spc . [ label "epoch" . store Rx.integer ]
101
102 let sentinel_cluster_instance_setup = 
103      let keys = "monitor" | "known-replica"
104   in store keys .
105        del_ws_spc . [ label "cluster" . store Rx.word ] .
106        del_ws_spc. [ label "ip" . store Rx.ip ] .
107        del_ws_spc . [ label "port" . store Rx.integer ] .
108        (del_ws_spc .  [ label "quorum" . store Rx.integer ])?
109
110 let sentinel_clustering =
111      let keys = "known-sentinel"
112   in store keys .
113        del_ws_spc . [ label "cluster" . store Rx.word ] .
114        del_ws_spc . [ label "ip" . store Rx.ip ] .
115        del_ws_spc . [ label "port" . store Rx.integer ] .
116        del_ws_spc . [ label "id" . store Rx.word ]
117
118 (* View: sentinel_entry
119 *)
120 let sentinel_entry =
121   indent . [ key "sentinel" . del_ws_spc .
122     (sentinel_global_entry | sentinel_cluster_setup | sentinel_cluster_instance_setup | sentinel_clustering)
123   ] . eol
124
125 (* View: bind_entry
126 The "bind" entry can be passed one or several ip addresses. A bind
127 statement "bind ip1 ip2 .. ipn" results in a tree
128 { "bind" { "ip" = ip1 } { "ip" = ip2 } ... { "ip" = ipn } }
129 *)
130 let bind_entry =
131   let ip = del_ws_spc . Quote.do_quote_opt_nil (store Rx.ip) in
132   indent . [ key "bind" . [ label "ip" . ip ]+ ] . eol
133
134 let renamecmd = /rename-command/
135 let from = [ label "from" . Quote.do_quote_opt_nil (store Rx.word) ]
136 let to = [ label "to" . Quote.do_quote_opt_nil (store Rx.word) ]
137 (* View: save_entry
138 Entries identified by the "rename-command" keyword can be found more than once.
139 They have 2 mandatory parameters, both strings. The same rules as
140 standard_entry apply for quoting, comments and whitespaces.
141 *)
142 let renamecmd_entry = [ indent . key renamecmd . del_ws_spc . from . del_ws_spc . to . eol ]
143
144 let cobl_cmd = /client-output-buffer-limit/
145 let class = [ label "class" . Quote.do_quote_opt_nil (store Rx.word) ]
146 let hard_limit = [ label "hard_limit" . Quote.do_quote_opt_nil (store Rx.word) ]
147 let soft_limit = [ label "soft_limit" . Quote.do_quote_opt_nil (store Rx.word) ]
148 let soft_seconds = [ label "soft_seconds" . Quote.do_quote_opt_nil (store Rx.integer) ]
149 (* View: client_output_buffer_limit_entry
150 Entries identified by the "client-output-buffer-limit" keyword can be found
151 more than once. They have four mandatory parameters, of which the first is a
152 string, the last one is an integer and the others are either integers or words,
153 although redis is very liberal and takes "4242yadayadabytes" as a valid limit.
154 The same rules as standard_entry apply for quoting, comments and whitespaces.
155 *)
156 let client_output_buffer_limit_entry =
157   [ indent . key cobl_cmd . del_ws_spc . class . del_ws_spc . hard_limit .
158     del_ws_spc . soft_limit . del_ws_spc . soft_seconds . eol ]
159
160 let entry = standard_entry
161           | save_entry
162           | renamecmd_entry
163           | replicaof_entry
164           | bind_entry
165     | sentinel_entry
166           | client_output_buffer_limit_entry
167
168 (* View: lns
169 The Redis lens
170 *)
171 let lns = (comment | empty | entry )*
172
173 let filter =
174     incl "/etc/redis.conf"
175   . incl "/etc/redis/redis.conf"
176
177 let xfm = transform lns filter