Bump to 1.14.1
[platform/upstream/augeas.git] / lenses / nginx.aug
1 (* Module: Nginx
2    Nginx module for Augeas
3
4 Authors: Ian Berry <iberry@barracuda.com>
5          Raphael Pinson <raphael.pinson@camptocamp.com>
6
7 About: Reference
8
9    This module was built to support a limited subset of nginx
10    configuration syntax. It works fine with simple blocks and
11    field/value lines.
12
13 About: License
14    This file is licenced under the LGPL v2+, like the rest of Augeas.
15
16 About: Lens Usage
17    To be documented
18
19 About: Configuration files
20    This lens applies to /etc/nginx/nginx.conf. See <filter>.
21
22 About: Examples
23    The <Test_Nginx> file contains various examples and tests.
24
25 About: TODO
26    * Convert statement keyworks for a regex
27    * Support more advanced block syntax (location)
28 *)
29
30 module Nginx =
31
32 autoload xfm
33
34 (* Variable: word *)
35 let word = /[A-Za-z0-9_.:-]+/
36
37 (* Variable: block_re
38      The keywords reserved for block entries *)
39 let block_re = "http" | "events" | "server" | "mail" | "stream"
40
41 (* All block keywords, including the ones we treat specially *)
42 let block_re_all = block_re | "if" | "location" | "geo" | "map"
43   | "split_clients" | "upstream"
44
45 (* View: simple
46      A simple entry *)
47 let simple =
48      let kw = word - block_re_all
49   in let mask = [ label "mask" . Util.del_str "/" . store Rx.integer ]
50   in let sto = store /[^ \t\n;#]([^";#]|"[^"]*\")*/
51   in [ Util.indent .
52        key kw . mask? .
53        (Sep.space . sto)? . Sep.semicolon .
54        (Util.eol|Util.comment_eol) ]
55
56 (* View: server
57      A simple server entry *)
58 let server =
59   let address = /[A-Za-z0-9_.:\/-]+/
60   in [ Util.indent . label "@server" . Util.del_str "server"
61   . [ Sep.space . label "@address" . store address ]
62   . [ Sep.space . key word . (Sep.equal . store word)? ]*
63   . Sep.semicolon
64   . (Util.eol|Util.comment_eol) ]
65
66 let arg (name:string) (rx:regexp) =
67   [ label name . Sep.space . store rx ]
68
69 (* Match any argument (as much as possible) *)
70 let any_rx =
71   let bare_rx = /[^" \t\n{][^ \t\n{]*/ in
72   let dquote_rx = /"([^\"]|\\.)*"/ in
73   bare_rx | dquote_rx
74
75 let any_arg (name:string) = arg name any_rx
76
77 (* 'if' conditions are enclosed in matching parens which we can't match
78    precisely with a regular expression. Instead, we gobble up anything that
79    doesn't contain an opening brace. That can of course lead to trouble if
80    a condition actually contains an opening brace *)
81 let block_if = key "if"
82              . arg "#cond" /\(([^ \t\n{]|[ \t\n][^{])*\)/
83
84 let block_location = key "location"
85   . (arg "#comp" /=|~|~\*|\^~/)?
86   . any_arg "#uri"
87
88 let block_geo = key "geo"
89   . (any_arg "#address")?
90   . any_arg "#geo"
91
92 let block_map = key "map"
93   . any_arg "#source"
94   . any_arg "#variable"
95
96 let block_split_clients = key "split_clients"
97   . any_arg "#string"
98   . any_arg "#variable"
99
100 let block_upstream = key "upstream"
101   . any_arg "#name"
102
103 let block_head = key block_re
104   | block_if
105   | block_location
106   | block_geo
107   | block_map
108   | block_split_clients
109   | block_upstream
110
111 (* View: block
112      A block containing <simple> entries *)
113 let block (entry : lens) =
114   [ Util.indent . block_head
115   . Build.block_newlines entry Util.comment
116   . Util.eol ]
117
118 let rec directive = simple | server | block directive
119
120 (* View: lns *)
121 let lns = ( Util.comment | Util.empty | directive )*
122
123 (* Variable: filter *)
124 let filter = incl "/etc/nginx/nginx.conf"
125            . incl "/etc/nginx/conf.d/*.conf"
126            . incl "/etc/nginx/sites-available/*"
127            . incl "/etc/nginx/sites-enabled/*"
128            . incl "/usr/portage/www-servers/nginx/files/nginx.conf"
129            . incl "/usr/local/etc/nginx/nginx.conf"
130            . incl "/usr/local/etc/nginx/conf.d/*.conf"
131            . incl "/usr/local/etc/nginx/sites-available/*"
132            . incl "/usr/local/etc/nginx/sites-enabled/*"
133
134 let xfm = transform lns filter