URL: https://github.com/freeipa/freeipa/pull/115
Author: tomaskrizek
 Title: #115: Don't show traceback when ipa config file is not an absolute path
Action: synchronized

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/115/head:pr115
git checkout pr115
From f445e300e4098da8ab10fd7952f57e421bc79f59 Mon Sep 17 00:00:00 2001
From: Tomas Krizek <tkri...@redhat.com>
Date: Tue, 27 Sep 2016 17:05:48 +0200
Subject: [PATCH 1/2] ipa: check if provided config file exists

Add a parser check to verify config file supplied to the ipa
command exists. Previously, invalid file paths would not results
in any error and would just silently proceed with default config.

https://fedorahosted.org/freeipa/ticket/6114
---
 ipalib/plugable.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index af35f5b..d45e9ee 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -494,6 +494,12 @@ def build_global_parser(self, parser=None, context=None):
         """
         Add global options to an optparse.OptionParser instance.
         """
+        def config_file_callback(option, opt, value, parser):
+            if not os.path.isfile(value):
+                raise optparse.OptionValueError(
+                    "%s option '%s' is not a file" % (opt, value))
+            parser.values.conf = value
+
         if parser is None:
             parser = optparse.OptionParser(
                 add_help_option=False,
@@ -517,8 +523,9 @@ def build_global_parser(self, parser=None, context=None):
         parser.add_option('-e', dest='env', metavar='KEY=VAL', action='append',
             help='Set environment variable KEY to VAL',
         )
-        parser.add_option('-c', dest='conf', metavar='FILE',
-            help='Load configuration from FILE',
+        parser.add_option('-c', dest='conf', metavar='FILE', action='callback',
+            callback=config_file_callback, type='string',
+            help='Load configuration from FILE.',
         )
         parser.add_option('-d', '--debug', action='store_true',
             help='Produce full debuging output',

From add8f1898c321d5b3bc1de86b14c75a8903ecf5e Mon Sep 17 00:00:00 2001
From: Tomas Krizek <tkri...@redhat.com>
Date: Tue, 27 Sep 2016 17:09:55 +0200
Subject: [PATCH 2/2] ipa: allow relative paths for config file

Remove unnecessary check for absolute file paths for config file.

https://fedorahosted.org/freeipa/ticket/6114
---
 ipalib/config.py | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)

diff --git a/ipalib/config.py b/ipalib/config.py
index eb6c3ae..a273e3d 100644
--- a/ipalib/config.py
+++ b/ipalib/config.py
@@ -352,23 +352,10 @@ def _merge_from_file(self, config_file):
         containing first the number of variables that were actually set, and
         second the total number of variables found in ``config_file``.
 
-        This method will raise a ``ValueError`` if ``config_file`` is not an
-        absolute path.  For example:
-
-        >>> env = Env()
-        >>> env._merge_from_file('my/config.conf')
-        Traceback (most recent call last):
-          ...
-        ValueError: config_file must be an absolute path; got 'my/config.conf'
-
         Also see `Env._merge()`.
 
-        :param config_file: Absolute path of the configuration file to load.
+        :param config_file: Path of the configuration file to load.
         """
-        if path.abspath(config_file) != config_file:
-            raise ValueError(
-                'config_file must be an absolute path; got %r' % config_file
-            )
         if not path.isfile(config_file):
             return
         parser = RawConfigParser()
-- 
Manage your subscription for the Freeipa-devel mailing list:
https://www.redhat.com/mailman/listinfo/freeipa-devel
Contribute to FreeIPA: http://www.freeipa.org/page/Contribute/Code

Reply via email to