diff options
author | Christian Heimes <cheimes@redhat.com> | 2016-10-24 10:35:41 +0200 |
---|---|---|
committer | Jan Cholasta <jcholast@redhat.com> | 2016-12-02 15:05:33 +0100 |
commit | d4916254e995be1118ab8dbce5b60091305f97fe (patch) | |
tree | ff6daf4da6512d84c135822ec512aedc5021023f /ipalib | |
parent | 64a4be26febf19e427760115912a858a804208a0 (diff) | |
download | freeipa-d4916254e995be1118ab8dbce5b60091305f97fe.tar.gz freeipa-d4916254e995be1118ab8dbce5b60091305f97fe.tar.xz freeipa-d4916254e995be1118ab8dbce5b60091305f97fe.zip |
Use env var IPA_CONFDIR to get confdir
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.
Some scripts (e.g. servers, installers, and upgrades) set the confdir
explicitly and do not support the env var.
Signed-off-by: Christian Heimes <cheimes@redhat.com>
Reviewed-By: Jan Cholasta <jcholast@redhat.com>
Diffstat (limited to 'ipalib')
-rw-r--r-- | ipalib/config.py | 12 | ||||
-rw-r--r-- | ipalib/plugable.py | 9 |
2 files changed, 20 insertions, 1 deletions
diff --git a/ipalib/config.py b/ipalib/config.py index 1075d627a..9d877828f 100644 --- a/ipalib/config.py +++ b/ipalib/config.py @@ -43,6 +43,7 @@ from ipapython.dn import DN from ipalib.base import check_name from ipalib.constants import CONFIG_SECTION from ipalib.constants import OVERRIDE_ERROR, SET_ERROR, DEL_ERROR +from ipapython.admintool import ScriptError if six.PY3: unicode = str @@ -460,8 +461,17 @@ class Env(object): self.context = 'default' # Set confdir: + self.env_confdir = os.environ.get('IPA_CONFDIR') if 'confdir' not in self: - if self.in_tree: + if self.env_confdir is not None: + if (not path.isabs(self.env_confdir) + or not path.isdir(self.env_confdir)): + raise ScriptError( + "IPA_CONFDIR env var must be an absolute path to an " + "existing directory, got '{}'.".format( + self.env_confdir)) + self.confdir = self.env_confdir + elif self.in_tree: self.confdir = self.dot_ipa else: self.confdir = path.join('/', 'etc', 'ipa') diff --git a/ipalib/plugable.py b/ipalib/plugable.py index 503534f9f..142b3e60d 100644 --- a/ipalib/plugable.py +++ b/ipalib/plugable.py @@ -713,6 +713,15 @@ class API(ReadOnly): self.__doing('finalize') self.__do_if_not_done('load_plugins') + if self.env.env_confdir is not None: + if self.env.env_confdir == self.env.confdir: + self.log.info( + "IPA_CONFDIR env sets confdir to '%s'.", self.env.confdir) + else: + self.log.warn( + "IPA_CONFDIR env is overridden by an explicit confdir " + "argument.") + for plugin in self.__plugins: if not self.env.validate_api: if plugin.full_name not in DEFAULT_PLUGINS: |