Hi,

Here is a new lens to parse /etc/puppet/fileserver.conf.
This file is used to configure mount points in the puppetmasterd daemon.
Its format is a kind of INI files so this lens uses the IniFiles one.

Do not hesitate to send me comments. I hope it can be useful to others.

Regards,
Fred
From 5482ac7d218b1528fd5b14bf494971f04f692e17 Mon Sep 17 00:00:00 2001
From: Fred <[email protected]>
Date: Tue, 18 Jan 2011 17:22:56 +0100
Subject: [PATCH] New lens for /etc/puppet/fileserver.conf file used by Puppet

---
 doc/naturaldocs/conf/lenses/Menu.txt   |    1 +
 lenses/puppetfileserver.aug            |  110 ++++++++++++++++++++++++++++++++
 lenses/tests/test_puppetfileserver.aug |   34 ++++++++++
 tests/Makefile.am                      |    1 +
 4 files changed, 146 insertions(+), 0 deletions(-)
 create mode 100644 lenses/puppetfileserver.aug
 create mode 100644 lenses/tests/test_puppetfileserver.aug

diff --git a/doc/naturaldocs/conf/lenses/Menu.txt b/doc/naturaldocs/conf/lenses/Menu.txt
index 7c5322a..1599fd6 100644
--- a/doc/naturaldocs/conf/lenses/Menu.txt
+++ b/doc/naturaldocs/conf/lenses/Menu.txt
@@ -72,6 +72,7 @@ Group: Specific Modules  {
    File: Nsswitch  (nsswitch.aug)
    File: Pbuilder  (pbuilder.aug)
    File: Pg_Hba  (pg_hba.aug)
+   File: PuppetFileserver  (puppetfileserver.aug)
    File: Resolv  (resolv.aug)
    File: Services  (services.aug)
    File: Shells  (shells.aug)
diff --git a/lenses/puppetfileserver.aug b/lenses/puppetfileserver.aug
new file mode 100644
index 0000000..e7a633a
--- /dev/null
+++ b/lenses/puppetfileserver.aug
@@ -0,0 +1,110 @@
+(*
+Module: PuppetFileserver
+  Parses /etc/puppet/fileserver.conf used by puppetmasterd daemon.
+
+Author: Frédéric Lespez <[email protected]>
+
+About: Reference
+  This lens tries to keep as close as possible to puppet documentation
+  for this file:
+  http://docs.puppetlabs.com/guides/file_serving.html
+
+About: License
+  This file is licensed under the LGPLv2+, like the rest of Augeas.
+
+About: Lens Usage
+  Sample usage of this lens in augtool
+
+    * Create a new mount point
+      > ins test_mount after /files/etc/puppet/fileserver.conf/*[last()]
+      > defvar test_mount /files/etc/puppet/fileserver.conf/test_mount
+      > set $test_mount/path /etc/puppet/files
+      > set $test_mount/allow *.example.com
+      > ins allow after $test_mount/*[last()]
+      > set $test_mount/allow[last()] server.domain.com
+      > set $test_mount/deny dangerous.server.com
+    * List the definition of a mount point
+      > print /files/etc/puppet/fileserver.conf/files
+    * Remove a mount point
+      > rm /files/etc/puppet/fileserver.conf/test_mount
+
+About: Configuration files
+  This lens applies to /etc/puppet/fileserver.conf. See <filter>.
+*)
+
+
+module PuppetFileserver =
+  autoload xfm
+
+(************************************************************************
+ * Group:                 USEFUL PRIMITIVES
+ *************************************************************************)
+
+(* Group: INI File settings *)
+
+(* Variable: sep_tab *)
+let eol = IniFile.eol
+
+(*
+Variable: comment
+  Only supports "#" as commentary
+*)
+let comment = IniFile.comment "#" "#"
+
+(*
+Variable: entry_re
+  Regexp for possible <entry> keyword (path, allow, deny)
+*)
+let entry_re = /path|allow|deny/
+
+
+(************************************************************************
+ * Group:                 ENTRY
+ *************************************************************************)
+
+(*
+View: entry
+  Non standard INI File entry:
+  - It might be indented with an arbitrary amount of whitespace
+  - It does not have any separator between keywords and their values
+  - It cannot contain a comment after a value (on the same line)
+  - It can only have keywords with the following values (path, allow, deny)
+*)
+let entry = [ Util.del_opt_ws "" . key entry_re .
+              Util.del_ws_spc . store /[^# \n\t]+/ .
+              eol ] | comment
+
+
+(************************************************************************
+ * Group:                      RECORD
+ *************************************************************************)
+
+(* Group: Title definition *)
+
+(*
+View: title
+  Uses standard INI File title
+*)
+let title = IniFile.indented_title IniFile.record_re
+
+(*
+View: title
+  Uses standard INI File record
+*)
+let record = IniFile.record title entry
+
+
+(************************************************************************
+ * Group:                      LENS
+ *************************************************************************)
+
+(*
+View: lns
+  Uses standard INI File lens
+*)
+let lns = IniFile.lns record comment
+
+(* Variable: filter *)
+let filter = (incl "/etc/puppet/fileserver.conf")
+
+let xfm = transform lns filter
diff --git a/lenses/tests/test_puppetfileserver.aug b/lenses/tests/test_puppetfileserver.aug
new file mode 100644
index 0000000..126f1be
--- /dev/null
+++ b/lenses/tests/test_puppetfileserver.aug
@@ -0,0 +1,34 @@
+(* Tests for the PuppetFileserver module *)
+
+module Test_puppetfileserver =
+
+let fileserver = "# This a comment
+
+[mount1]
+  # Mount1 options
+  path /etc/puppet/files/%h
+  allow host.domain1.com
+  allow *.domain2.com
+  deny badhost.domain2.com
+[mount2]
+  allow *
+  deny *.evil.example.com
+  deny badhost.domain2.com
+"
+
+test PuppetFileserver.lns get fileserver =
+	{ "#comment" = "This a comment" }
+	{ }
+	{ "mount1"
+		{ "#comment" = "Mount1 options" }
+		{ "path" = "/etc/puppet/files/%h" }
+		{ "allow" = "host.domain1.com" }
+		{ "allow" = "*.domain2.com" }
+		{ "deny" = "badhost.domain2.com" }
+	}
+	{ "mount2"
+		{ "allow" = "*" }
+		{ "deny" = "*.evil.example.com" }
+		{ "deny" = "badhost.domain2.com" }
+	}
+
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 8578ffa..db4172f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -71,6 +71,7 @@ lens_tests =			\
   lens-postfix_main.sh		\
   lens-postfix_master.sh	\
   lens-puppet.sh		\
+  lens-puppetfileserver.sh		\
   lens-resolv.sh		\
   lens-rsyncd.sh		\
   lens-rx.sh			\
-- 
1.7.1

_______________________________________________
augeas-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/augeas-devel

Reply via email to