Imported Upstream version 0.10.0
[platform/upstream/augeas.git] / lenses / pg_hba.aug
1 (*
2 Module: Pg_Hba
3   Parses PostgreSQL's pg_hba.conf
4
5 Author: Aurelien Bompard <aurelien@bompard.org>
6
7 About: Reference
8   The file format is described in PostgreSQL's documentation:
9   http://www.postgresql.org/docs/current/static/auth-pg-hba-conf.html
10
11 About: License
12   This file is licensed under the LGPLv2+, like the rest of Augeas.
13
14 About: Configuration files
15   This lens applies to pg_hba.conf. See <filter> for exact locations.
16 *)
17
18
19 module Pg_Hba =
20     autoload xfm
21
22     (* Group: Generic primitives *)
23
24     let eol     = Util.eol
25     let word    = Rx.neg1
26     (* Variable: ipaddr
27        CIDR or ip+netmask *)
28     let ipaddr   = /[0-9a-fA-F:.]+(\/[0-9]+|[ \t]+[0-9.]+)/
29
30     let comma_sep_list (l:string) =
31         let lns = [ label l . store word ] in
32             Build.opt_list lns Sep.comma
33
34     (* Group: Columns definitions *)
35
36     (* View: database
37        TODO: support for quoted strings *)
38     let database = comma_sep_list "database"
39     (* View: user
40        TODO: support for quoted strings *)
41     let user = comma_sep_list "user"
42     (* View: address *)
43     let address = [ label "address" . store ipaddr ]
44     (* View: option
45        part of <method> *)
46     let option = [ label "option" . store word ]
47     (* View: method
48        can contain an <option> *)
49     let method = [ label "method" . store Rx.word . ( Sep.tab . option )? ]
50
51     (* Group: Records definitions *)
52
53     (* View: record_local
54        when type is "local", there is no "address" field *)
55     let record_local = [ label "type" . store "local" ] . Sep.tab .
56                        database . Sep.tab . user . Sep.tab . method
57
58     (* Variable: remtypes
59        non-local connection types *)
60     let remtypes = "host" | "hostssl" | "hostnossl"
61
62     (* View: record_remote *)
63     let record_remote = [ label "type" . store remtypes ] . Sep.tab .
64                         database . Sep.tab .  user . Sep.tab .
65                         address . Sep.tab . method
66
67     (* View: record
68         A sequence of <record_local> or <record_remote> entries *)
69     let record = [ seq "entries" . (record_local | record_remote) . eol ]
70
71     (* View: filter
72         The pg_hba.conf conf file *)
73     let filter = (incl "/var/lib/pgsql/data/pg_hba.conf" .
74                   incl "/etc/postgresql/*/*/pg_hba.conf" )
75
76     (* View: lns
77         The pg_hba.conf lens *)
78     let lns = ( record | Util.comment | Util.empty ) *
79
80     let xfm = transform lns filter