URL: https://github.com/freeipa/freeipa/pull/492 Author: HonzaCholasta Title: #492: [WIP] config: remove meaningless defaults Action: opened
PR body: """ **ipalib.constants: Remove default domain, realm, basedn, xmlrpc_uri, ldap_uri** Domain, realm, basedn, xmlrpc_uri, ldap_uri do not have any reasonable default. This patch removes hardcoded default so the so the code which depends on these values blows up early and does not do crazy stuff with default values instead of real ones. This should help to uncover issues caused by improper ipalib initialization. **config: provide defaults for `xmlrpc_uri`, `ldap_uri` and `basedn`** Derive the default value of `xmlrpc_uri` and `ldap_uri` from `server`. Derive the default value of `basedn` from `domain`. This supersedes @pspacek's PR #113. """ To pull the PR as Git branch: git remote add ghfreeipa https://github.com/freeipa/freeipa git fetch ghfreeipa pull/492/head:pr492 git checkout pr492
From e7731e30d5cd3cd541cb9aac10647dadd2bea468 Mon Sep 17 00:00:00 2001 From: Petr Spacek <pspa...@redhat.com> Date: Tue, 10 May 2016 14:20:15 +0200 Subject: [PATCH 1/2] ipalib.constants: Remove default domain, realm, basedn, xmlrpc_uri, ldap_uri Domain, realm, basedn, xmlrpc_uri, ldap_uri do not have any reasonable default. This patch removes hardcoded default so the so the code which depends on these values blows up early and does not do crazy stuff with default values instead of real ones. This should help to uncover issues caused by improper ipalib initialization. --- ipalib/constants.py | 16 +++++++++++----- makeaci | 3 +++ makeapi | 6 ++++++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/ipalib/constants.py b/ipalib/constants.py index 81643da..1f9bd92 100644 --- a/ipalib/constants.py +++ b/ipalib/constants.py @@ -67,9 +67,12 @@ ('version', VERSION), # Domain, realm, basedn: - ('domain', 'example.com'), - ('realm', 'EXAMPLE.COM'), - ('basedn', DN(('dc', 'example'), ('dc', 'com'))), + # Following values do not have any reasonable default. + # Do not initialize them so the code which depends on them blows up early + # and does not do crazy stuff with default values instead of real ones. + # ('domain', 'example.com'), + # ('realm', 'EXAMPLE.COM'), + # ('basedn', DN(('dc', 'example'), ('dc', 'com'))), # LDAP containers: ('container_accounts', DN(('cn', 'accounts'))), @@ -124,9 +127,12 @@ ('container_sysaccounts', DN(('cn', 'sysaccounts'), ('cn', 'etc'))), # Ports, hosts, and URIs: - ('xmlrpc_uri', 'http://localhost:8888/ipa/xml'), + # Following values do not have any reasonable default. + # Do not initialize them so the code which depends on them blows up early + # and does not do crazy stuff with default values instead of real ones. + # ('xmlrpc_uri', 'http://localhost:8888/ipa/xml'), # jsonrpc_uri is set in Env._finalize_core() - ('ldap_uri', 'ldap://localhost:389'), + # ('ldap_uri', 'ldap://localhost:389'), ('rpc_protocol', 'jsonrpc'), diff --git a/makeaci b/makeaci index 98b199c..813ecc7 100755 --- a/makeaci +++ b/makeaci @@ -98,6 +98,9 @@ def main(options): plugins_on_demand=False, basedn=DN('dc=ipa,dc=example'), realm='IPA.EXAMPLE', + domain="example.com", + xmlrpc_uri="http://localhost:8888/ipa/xml", + ldap_uri="ldap://localhost:389", ) from ipaserver.install.plugins import update_managed_permissions diff --git a/makeapi b/makeapi index d0a7295..729b922 100755 --- a/makeapi +++ b/makeapi @@ -40,6 +40,7 @@ from ipalib.parameters import Param from ipalib.output import Output from ipalib.text import Gettext, NGettext, ConcatenatedLazyText from ipalib.capabilities import capabilities +from ipapython.dn import DN API_FILE='API.txt' @@ -513,6 +514,11 @@ def main(): enable_ra=True, mode='developer', plugins_on_demand=False, + basedn=DN(('dc', 'example'), ('dc', 'com')), + realm="EXAMPLE.COM", + domain="example.com", + xmlrpc_uri="http://localhost:8888/ipa/xml", + ldap_uri="ldap://localhost:389", ) api.bootstrap(**cfg) From 4ebf4b907213c9951eb9cbd276e0460552563fb1 Mon Sep 17 00:00:00 2001 From: Jan Cholasta <jchol...@redhat.com> Date: Tue, 21 Feb 2017 13:24:51 +0000 Subject: [PATCH 2/2] config: provide defaults for `xmlrpc_uri`, `ldap_uri` and `basedn` Derive the default value of `xmlrpc_uri` and `ldap_uri` from `server`. Derive the default value of `basedn` from `domain`. --- ipalib/config.py | 9 +++++++++ ipalib/constants.py | 5 ++--- makeaci | 2 -- makeapi | 4 ---- pylint_plugins.py | 4 +++- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/ipalib/config.py b/ipalib/config.py index 20591db..a9d72f5 100644 --- a/ipalib/config.py +++ b/ipalib/config.py @@ -554,6 +554,15 @@ def _finalize_core(self, **defaults): if 'log' not in self: self.log = self._join('logdir', '%s.log' % self.context) + if 'basedn' not in self and 'domain' in self: + self.basedn = DN(*(('dc', dc) for dc in self.domain.split('.'))) + + if 'xmlrpc_uri' not in self and 'server' in self: + self.xmlrpc_uri = 'https://{}/ipa/xml'.format(self.server) + + if 'ldap_uri' not in self and 'server' in self: + self.ldap_uri = 'ldap://{}'.format(self.server) + # Derive jsonrpc_uri from xmlrpc_uri if 'jsonrpc_uri' not in self: if 'xmlrpc_uri' in self: diff --git a/ipalib/constants.py b/ipalib/constants.py index 1f9bd92..cad047a 100644 --- a/ipalib/constants.py +++ b/ipalib/constants.py @@ -130,8 +130,9 @@ # Following values do not have any reasonable default. # Do not initialize them so the code which depends on them blows up early # and does not do crazy stuff with default values instead of real ones. + # ('server', 'localhost'), # ('xmlrpc_uri', 'http://localhost:8888/ipa/xml'), - # jsonrpc_uri is set in Env._finalize_core() + # ('jsonrpc_uri', 'http://localhost:8888/ipa/json'), # ('ldap_uri', 'ldap://localhost:389'), ('rpc_protocol', 'jsonrpc'), @@ -237,8 +238,6 @@ ('in_server', object), # Whether or not running in-server (bool) ('logdir', object), # Directory containing log files ('log', object), # Path to context specific log file - ('jsonrpc_uri', object), # derived from xmlrpc_uri in Env._finalize_core() - ('server', object), # derived from jsonrpc_uri in Env._finalize_core() ) diff --git a/makeaci b/makeaci index 813ecc7..57622fe 100755 --- a/makeaci +++ b/makeaci @@ -99,8 +99,6 @@ def main(options): basedn=DN('dc=ipa,dc=example'), realm='IPA.EXAMPLE', domain="example.com", - xmlrpc_uri="http://localhost:8888/ipa/xml", - ldap_uri="ldap://localhost:389", ) from ipaserver.install.plugins import update_managed_permissions diff --git a/makeapi b/makeapi index 729b922..2b1d154 100755 --- a/makeapi +++ b/makeapi @@ -40,7 +40,6 @@ from ipalib.parameters import Param from ipalib.output import Output from ipalib.text import Gettext, NGettext, ConcatenatedLazyText from ipalib.capabilities import capabilities -from ipapython.dn import DN API_FILE='API.txt' @@ -514,11 +513,8 @@ def main(): enable_ra=True, mode='developer', plugins_on_demand=False, - basedn=DN(('dc', 'example'), ('dc', 'com')), realm="EXAMPLE.COM", domain="example.com", - xmlrpc_uri="http://localhost:8888/ipa/xml", - ldap_uri="ldap://localhost:389", ) api.bootstrap(**cfg) diff --git a/pylint_plugins.py b/pylint_plugins.py index fc2ce9b..ffecd79 100644 --- a/pylint_plugins.py +++ b/pylint_plugins.py @@ -94,7 +94,9 @@ def fake_class(name_or_class_obj, members=()): 'xmlrpc_uri', 'validate_api', 'startup_traceback', - 'verbose' + 'verbose', + 'server', + {'domain': dir(str)}, ] + LOGGING_ATTRS, 'ipalib.errors.ACIError': [ 'info',
-- 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