URL: https://github.com/freeipa/freeipa/pull/182
Author: tiran
 Title: #182: Use env var IPA_CONFDIR to get confdir for 'cli' context
Action: opened

PR body:
"""
For 'cli' contexts, the environment variable IPA_CONFDIR overrides the
default confdir path. The value of the environment variable must be an
absolute path to an existing directory. The new variable simplifies
local configuration. Server and installer contexts do not use it.

Signed-off-by: Christian Heimes <chei...@redhat.com>
"""

To pull the PR as Git branch:
git remote add ghfreeipa https://github.com/freeipa/freeipa
git fetch ghfreeipa pull/182/head:pr182
git checkout pr182
From 3546d394bf4256f8d79e21902d16cc09a18989cb Mon Sep 17 00:00:00 2001
From: Christian Heimes <chei...@redhat.com>
Date: Mon, 24 Oct 2016 10:35:41 +0200
Subject: [PATCH] Use env var IPA_CONFDIR to get confdir for 'cli' context

For 'cli' contexts, the environment variable IPA_CONFDIR overrides the
default confdir path. The value of the environment variable must be an
absolute path to an existing directory. The new variable simplifies
local configuration. Server and installer contexts do not use it.

Signed-off-by: Christian Heimes <chei...@redhat.com>
---
 client/man/ipa.1 | 4 ++++
 ipalib/config.py | 9 ++++++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/client/man/ipa.1 b/client/man/ipa.1
index 9194ca0..b843e7b 100644
--- a/client/man/ipa.1
+++ b/client/man/ipa.1
@@ -186,6 +186,10 @@ The ipa client will determine which server to connect to in this order:
 
 .TP
 If a kerberos error is raised by any of the requests then it will stop processing and display the error message.
+.SH "ENVIRONMENT VARIABLES"
+.TP
+\fBIPA_CONFDIR\fR
+Override path to confdir (default: \fB/etc/ipa\fR).
 .SH "FILES"
 .TP
 \fB/etc/ipa/default.conf\fR
diff --git a/ipalib/config.py b/ipalib/config.py
index cf9e925..350ed77 100644
--- a/ipalib/config.py
+++ b/ipalib/config.py
@@ -461,7 +461,14 @@ def _bootstrap(self, **overrides):
 
         # Set confdir:
         if 'confdir' not in self:
-            if self.in_tree:
+            ipa_confdir = os.environ.get('IPA_CONFDIR')
+            if self.context == 'cli' and ipa_confdir is not None:
+                if not path.isabs(ipa_confdir) or not path.isdir(ipa_confdir):
+                    raise AttributeError(
+                        'IPA_CONFDIR must be an absolute path to an '
+                        'existing directory.')
+                self.confdir = ipa_confdir
+            elif self.in_tree:
                 self.confdir = self.dot_ipa
             else:
                 self.confdir = path.join('/', 'etc', 'ipa')
-- 
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