Blame lenses/pagekite.aug

Packit Service a2ae7a
(*
Packit Service a2ae7a
Module: Pagekite
Packit Service a2ae7a
  Parses /etc/pagekite.d/
Packit Service a2ae7a
Packit Service a2ae7a
Author: Michael Pimmer <blubb@fonfon.at>
Packit Service a2ae7a
Packit Service a2ae7a
About: License
Packit Service a2ae7a
   This file is licenced under the LGPL v2+, like the rest of Augeas.
Packit Service a2ae7a
*)
Packit Service a2ae7a
Packit Service a2ae7a
module Pagekite =
Packit Service a2ae7a
autoload xfm
Packit Service a2ae7a
Packit Service a2ae7a
(* View: lns *)
Packit Service a2ae7a
Packit Service a2ae7a
(* Variables *)
Packit Service a2ae7a
let equals = del /[ \t]*=[ \t]*/ "="
Packit Service a2ae7a
let neg2 = /[^# \n\t]+/
Packit Service a2ae7a
let neg3 = /[^# \:\n\t]+/
Packit Service a2ae7a
let eol = del /\n/ "\n"
Packit Service a2ae7a
(* Match everything from here to eol, cropping whitespace at both ends *)
Packit Service a2ae7a
let to_eol  = /[^ \t\n](.*[^ \t\n])?/
Packit Service a2ae7a
Packit Service a2ae7a
(* A key followed by comma-separated values 
Packit Service a2ae7a
  k: name of the key
Packit Service a2ae7a
  key_sep: separator between key and values
Packit Service a2ae7a
  value_sep: separator between values
Packit Service a2ae7a
  sto: store for values
Packit Service a2ae7a
*)
Packit Service a2ae7a
let key_csv_line (k:string) (key_sep:lens) (value_sep:lens) (sto:lens) = 
Packit Service a2ae7a
  [ key k . key_sep . [ seq k . sto ] .
Packit Service a2ae7a
    [ seq k . value_sep . sto ]* . Util.eol ]
Packit Service a2ae7a
Packit Service a2ae7a
(* entries for pagekite.d/10_account.rc *)
Packit Service a2ae7a
let domain = [ key "domain" . equals . store neg2 . Util.comment_or_eol ]
Packit Service a2ae7a
let frontend = Build.key_value_line ("frontend" | "frontends") 
Packit Service a2ae7a
                                       equals (store Rx.neg1)
Packit Service a2ae7a
let host = Build.key_value_line "host" equals (store Rx.ip)
Packit Service a2ae7a
let ports = key_csv_line "ports" equals Sep.comma (store Rx.integer)
Packit Service a2ae7a
let protos = key_csv_line "protos" equals Sep.comma (store Rx.word)
Packit Service a2ae7a
Packit Service a2ae7a
(* entries for pagekite.d/20_frontends.rc *)
Packit Service a2ae7a
let kitesecret = Build.key_value_line "kitesecret" equals (store Rx.space_in)
Packit Service a2ae7a
let kv_frontend = Build.key_value_line ( "kitename" | "fe_certname" | 
Packit Service a2ae7a
                                         "ca_certs" | "tls_endpoint" ) 
Packit Service a2ae7a
                                       equals (store Rx.neg1)
Packit Service a2ae7a
Packit Service a2ae7a
(* entries for services like 80_httpd.rc *)
Packit Service a2ae7a
let service_colon = del /[ \t]*:[ \t]*/ " : "
Packit Service a2ae7a
let service_on = [ key "service_on" . [ seq "service_on" . equals .
Packit Service a2ae7a
                   [ label "protocol" . store neg3 ] . service_colon .
Packit Service a2ae7a
                   [ label "kitename" . (store neg3) ] . service_colon .
Packit Service a2ae7a
                   [ label "backend_host" . (store neg3) ] . service_colon .
Packit Service a2ae7a
                   [ label "backend_port" . (store neg3) ] . service_colon . (
Packit Service a2ae7a
                     [ label "secret" . (store Rx.no_spaces) . Util.eol ] | eol
Packit Service a2ae7a
                   ) ] ]
Packit Service a2ae7a
Packit Service a2ae7a
let service_cfg = [ key "service_cfg" . equals . store to_eol . eol ]
Packit Service a2ae7a
Packit Service a2ae7a
let flags = ( "defaults" | "isfrontend" | "abort_not_configured" | "insecure" )
Packit Service a2ae7a
Packit Service a2ae7a
let entries = Build.flag_line flags
Packit Service a2ae7a
        | domain
Packit Service a2ae7a
        | frontend
Packit Service a2ae7a
        | host
Packit Service a2ae7a
        | ports
Packit Service a2ae7a
        | protos
Packit Service a2ae7a
        | kv_frontend
Packit Service a2ae7a
        | kitesecret
Packit Service a2ae7a
        | service_on
Packit Service a2ae7a
        | service_cfg
Packit Service a2ae7a
Packit Service a2ae7a
let lns = ( entries | Util.empty | Util.comment )*
Packit Service a2ae7a
Packit Service a2ae7a
(* View: filter *)
Packit Service a2ae7a
let filter = incl "/etc/pagekite.d/*.rc"
Packit Service a2ae7a
        . Util.stdexcl
Packit Service a2ae7a
Packit Service a2ae7a
let xfm = transform lns filter