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

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 703a8e7c36cc0d9c4005681436a5cdba7d0bff47 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 contexts

For 'cli' and 'cli_installer' 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 makes it much simpler to use the 'ipa'
command and ipalib with a local configuration directory.

Server and server installer contexts do not use the env var.

Signed-off-by: Christian Heimes <chei...@redhat.com>
---
 client/man/ipa.1 |  4 ++++
 ipalib/config.py | 10 +++++++++-
 2 files changed, 13 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..b55a524 100644
--- a/ipalib/config.py
+++ b/ipalib/config.py
@@ -461,7 +461,15 @@ def _bootstrap(self, **overrides):
 
         # Set confdir:
         if 'confdir' not in self:
-            if self.in_tree:
+            ipa_confdir = os.environ.get('IPA_CONFDIR')
+            env_contexts = {'cli', 'cli_installer'}
+            if ipa_confdir is not None and self.context in env_contests:
+                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