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: opened

PR body:
"""
When using the ipa command with the '-c' flag, the user provides
a configuration file. If this path is not absolute, an error
without a traceback should be displayed.

https://fedorahosted.org/freeipa/ticket/6114
"""

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 60b57bb178a0c4e7f35fc5c4794cdc5668448538 Mon Sep 17 00:00:00 2001
From: Tomas Krizek <tkri...@redhat.com>
Date: Mon, 26 Sep 2016 10:38:36 +0200
Subject: [PATCH 1/2] Don't show traceback when ipa config file is not an
 absolute path

When using the ipa command with the '-c' flag, the user provides
a configuration file. If this path is not absolute, an error
without a traceback should be displayed.

https://fedorahosted.org/freeipa/ticket/6114
---
 ipalib/config.py | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/ipalib/config.py b/ipalib/config.py
index 55a95bb..737b462 100644
--- a/ipalib/config.py
+++ b/ipalib/config.py
@@ -38,6 +38,7 @@
 from six.moves.configparser import RawConfigParser, ParsingError
 
 from ipapython.dn import DN
+from ipapython.ipa_log_manager import root_logger
 from ipalib.base import check_name
 from ipalib.constants import CONFIG_SECTION
 from ipalib.constants import OVERRIDE_ERROR, SET_ERROR, DEL_ERROR
@@ -367,7 +368,7 @@ def _merge_from_file(self, config_file):
         """
         if path.abspath(config_file) != config_file:
             raise ValueError(
-                'config_file must be an absolute path; got %r' % config_file
+                "config_file must be an absolute path; got '%s'" % config_file
             )
         if not path.isfile(config_file):
             return
@@ -532,8 +533,12 @@ def _finalize_core(self, **defaults):
 
         # Merge in context config file and then default config file:
         if self.__d.get('mode', None) != 'dummy':
-            self._merge_from_file(self.conf)
-            self._merge_from_file(self.conf_default)
+            try:
+                self._merge_from_file(self.conf)
+                self._merge_from_file(self.conf_default)
+            except ValueError as e:
+                root_logger.error(e)
+                sys.exit(1)
 
         # Determine if in_server:
         if 'in_server' not in self:

From bd2a7059012098f2baeccf78b3cf98da1a7cf1b1 Mon Sep 17 00:00:00 2001
From: Tomas Krizek <tkri...@redhat.com>
Date: Mon, 26 Sep 2016 12:12:50 +0200
Subject: [PATCH 2/2] Update help for ipa config file parameter

Help and man page should mention that configuration
file in ipa command requires absolute path.

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

diff --git a/ipa.1 b/ipa.1
index 9194ca0..5f81ecc 100644
--- a/ipa.1
+++ b/ipa.1
@@ -32,7 +32,7 @@ More information about the project is available on its homepage located at http:
 .SH "OPTIONS"
 .TP
 \fB\-c\fR \fIFILE\fR
-Load configuration from \fIFILE\fR.
+Load configuration from \fIFILE\fR. This must be an absolute path.
 .TP
 \fB\-d\fR, \fB\-\-debug\fR
 Produce full debugging output.
diff --git a/ipalib/plugable.py b/ipalib/plugable.py
index af35f5b..4b232a8 100644
--- a/ipalib/plugable.py
+++ b/ipalib/plugable.py
@@ -518,7 +518,7 @@ def build_global_parser(self, parser=None, context=None):
             help='Set environment variable KEY to VAL',
         )
         parser.add_option('-c', dest='conf', metavar='FILE',
-            help='Load configuration from FILE',
+            help='Load configuration from FILE. This must be an absolute path',
         )
         parser.add_option('-d', '--debug', action='store_true',
             help='Produce full debuging output',
-- 
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