Repository: certbot/certbot

Issue:
parsing cups printers.conf? wat?
I installed as described in the README on Ubuntu 14.04 and after starting letsencrypt from the venv, it shows the disclaimer and after I agree, it shows:

   There has been an error in parsing the file: /etc/cups/printers.conf  
   Parse error: mismatched in square lens, expecting "DefaultPrinter"  
   but got "Printer"  
   No domain names were found in your installation  
   Either specify which names you would like letsencrypt to validate  
   or add server names to your virtual hosts                         

Why is it parsing my cups printers.conf???

(the rest is ok, I have no hostnames, apache2 was freshly installed on this machine)



Discussion:
It is related to this...
https://github.com/letsencrypt/lets-encrypt-preview/blob/master/letsencrypt/client/augeas_configurator.py#L39

Augeas by default tries to load up everything... I know there is a way to load up only specific modules, but I haven't gotten around to it yet.

The warning statement is from here...
https://github.com/letsencrypt/lets-encrypt-preview/blob/master/letsencrypt/client/augeas_configurator.py#L45

It shouldn't affect the actual running of the program, but I am surprised that it got past the "only print out the relevant (httpd) lens filter.

The code hasn't been hit yet with review yet... I am making the rounds though and cleaning up the augeas_configurator in the "reverter branch".

If you would like to currently ignore the problem... I think it would be fine, or if you would like to investigate the Augeas module loading... that would be great!

If no one posts on this thread regarding it, I will attempt to figure it out towards the end of the "reverter" branch development.


Resolving patch:
diff --git a/letsencrypt/client/apache/parser.py b/letsencrypt/client/apache/parser.py
--- a/letsencrypt/client/apache/parser.py
+++ b/letsencrypt/client/apache/parser.py
@@ -240,27 +240,47 @@ def fnmatch_to_re(self, clean_fn_match):  # pylint: disable=no-self-use
                 regex = regex + letter
         return regex
 
-    def _parse_file(self, file_path):
+    def _parse_file(self, filepath):
         """Parse file with Augeas
 
         Checks to see if file_path is parsed by Augeas
-        If file_path isn't parsed, the file is added and Augeas is reloaded
+        If filepath isn't parsed, the file is added and Augeas is reloaded
 
-        :param str file_path: Apache config file path
+        :param str filepath: Apache config file path
 
         """
         # Test if augeas included file for Httpd.lens
         # Note: This works for augeas globs, ie. *.conf
         inc_test = self.aug.match(
-            "/augeas/load/Httpd/incl [. ='%s']" % file_path)
+            "/augeas/load/Httpd/incl [. ='%s']" % filepath)
         if not inc_test:
             # Load up files
-            # self.httpd_incl.append(file_path)
-            # self.aug.add_transform("Httpd.lns",
-            #                       self.httpd_incl, None, self.httpd_excl)
-            self._add_httpd_transform(file_path)
+            # This doesn't seem to work on TravisCI
+            # self.aug.add_transform("Httpd.lns", [filepath])
+            self._add_httpd_transform(filepath)
             self.aug.load()
 
+    def _add_httpd_transform(self, incl):
+        """Add a transform to Augeas.
+
+        This function will correctly add a transform to augeas
+        The existing augeas.add_transform in python doesn't seem to work for
+        Travis CI as it loads in libaugeas.so.0.10.0
+
+        :param str incl: filepath to include for transform
+
+        """
+        last_include = self.aug.match("/augeas/load/Httpd/incl [last()]")
+        if last_include:
+            # Insert a new node immediately after the last incl
+            self.aug.insert(last_include[0], "incl", False)
+            self.aug.set("/augeas/load/Httpd/incl[last()]", incl)
+        # On first use... must load lens and add file to incl
+        else:
+            # Augeas uses base 1 indexing... insert at beginning...
+            self.aug.set("/augeas/load/Httpd/lens", "Httpd.lns")
+            self.aug.set("/augeas/load/Httpd/incl", incl)
+
     def standardize_excl(self):
         """Standardize the excl arguments for the Httpd lens in Augeas.
 
@@ -293,19 +313,6 @@ def standardize_excl(self):
 
         self.aug.load()
 
-    def _add_httpd_transform(self, incl):
-        """Add a transform to Augeas.
-
-        This function will correctly add a transform to augeas
-        The existing augeas.add_transform in python is broken.
-
-        :param str incl: TODO
-
-        """
-        last_include = self.aug.match("/augeas/load/Httpd/incl [last()]")
-        self.aug.insert(last_include[0], "incl", False)
-        self.aug.set("/augeas/load/Httpd/incl[last()]", incl)
-
     def _set_locations(self, ssl_options):
         """Set default location for directives.
 
diff --git a/letsencrypt/client/augeas_configurator.py b/letsencrypt/client/augeas_configurator.py
--- a/letsencrypt/client/augeas_configurator.py
+++ b/letsencrypt/client/augeas_configurator.py
@@ -36,10 +36,11 @@ def __init__(self, direc=None):
                      "progress": CONFIG.IN_PROGRESS_DIR}
 
         self.direc = direc
-        # TODO: this instantiation can be optimized to only load
-        #       relevant files - I believe -> NO_MODL_AUTOLOAD
-        # Set Augeas flags to save backup
-        self.aug = augeas.Augeas(flags=augeas.Augeas.NONE)
+
+        # Set Augeas flags to not save backup (we do it ourselves)
+        # Set Augeas to not load anything by default
+        my_flags = augeas.Augeas.NONE | augeas.Augeas.NO_MODL_AUTOLOAD
+        self.aug = augeas.Augeas(flags=my_flags)
         self.save_notes = ""
 
     def check_parsing_errors(self, lens):
@@ -187,7 +188,7 @@ def rollback_checkpoints(self, rollback=1):
 
         self.aug.load()
 
-    def show_config_changes(self):
+    def view_config_changes(self):
         """Displays all saved checkpoints.
 
         All checkpoints are printed to the console.


Test patch: