summaryrefslogtreecommitdiffstats
path: root/ipalib/plugins/baseldap.py
diff options
context:
space:
mode:
authorMartin Kosek <mkosek@redhat.com>2011-05-26 09:55:53 +0200
committerMartin Kosek <mkosek@redhat.com>2011-06-02 09:00:35 +0200
commit585083c1d7a0069579d45b17adb39ad8f522c3f6 (patch)
tree0695c93b80c3d304e2e748cf9d24b4b02263491d /ipalib/plugins/baseldap.py
parentc0f155bbfe5c5448af1b38b9da9bb75e9cdac9b4 (diff)
downloadfreeipa-585083c1d7a0069579d45b17adb39ad8f522c3f6.tar.gz
freeipa-585083c1d7a0069579d45b17adb39ad8f522c3f6.tar.xz
freeipa-585083c1d7a0069579d45b17adb39ad8f522c3f6.zip
Improve interactive mode for DNS plugin
Interactive mode for commands manipulating with DNS records (dnsrecord-add, dnsrecord-del) is not usable. This patch enhances the server framework with new callback for interactive mode, which can be used by commands to inject their own interactive handling. The callback is then used to improve aforementioned commands' interactive mode. https://fedorahosted.org/freeipa/ticket/1018
Diffstat (limited to 'ipalib/plugins/baseldap.py')
-rw-r--r--ipalib/plugins/baseldap.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/ipalib/plugins/baseldap.py b/ipalib/plugins/baseldap.py
index 3908dfe3e..7d4552576 100644
--- a/ipalib/plugins/baseldap.py
+++ b/ipalib/plugins/baseldap.py
@@ -482,12 +482,17 @@ class CallbackInterface(Method):
self.__class__.POST_CALLBACKS = []
if not hasattr(self.__class__, 'EXC_CALLBACKS'):
self.__class__.EXC_CALLBACKS = []
+ if not hasattr(self.__class__, 'INTERACTIVE_PROMPT_CALLBACKS'):
+ self.__class__.INTERACTIVE_PROMPT_CALLBACKS = []
if hasattr(self, 'pre_callback'):
self.register_pre_callback(self.pre_callback, True)
if hasattr(self, 'post_callback'):
self.register_post_callback(self.post_callback, True)
if hasattr(self, 'exc_callback'):
self.register_exc_callback(self.exc_callback, True)
+ if hasattr(self, 'interactive_prompt_callback'):
+ self.register_interactive_prompt_callback(
+ self.interactive_prompt_callback, True) #pylint: disable=E1101
super(Method, self).__init__()
@classmethod
@@ -520,6 +525,16 @@ class CallbackInterface(Method):
else:
klass.EXC_CALLBACKS.append(callback)
+ @classmethod
+ def register_interactive_prompt_callback(klass, callback, first=False):
+ assert callable(callback)
+ if not hasattr(klass, 'INTERACTIVE_PROMPT_CALLBACKS'):
+ klass.INTERACTIVE_PROMPT_CALLBACKS = []
+ if first:
+ klass.INTERACTIVE_PROMPT_CALLBACKS.insert(0, callback)
+ else:
+ klass.INTERACTIVE_PROMPT_CALLBACKS.append(callback)
+
def _call_exc_callbacks(self, args, options, exc, call_func, *call_args, **call_kwargs):
rv = None
for i in xrange(len(getattr(self, 'EXC_CALLBACKS', []))):
@@ -670,6 +685,9 @@ class LDAPCreate(CallbackInterface, crud.Create):
def exc_callback(self, keys, options, exc, call_func, *call_args, **call_kwargs):
raise exc
+ def interactive_prompt_callback(self, kw):
+ return
+
# list of attributes we want exported to JSON
json_friendly_attributes = (
'takes_args', 'takes_options',
@@ -795,6 +813,9 @@ class LDAPRetrieve(LDAPQuery):
def exc_callback(self, keys, options, exc, call_func, *call_args, **call_kwargs):
raise exc
+ def interactive_prompt_callback(self, kw):
+ return
+
class LDAPUpdate(LDAPQuery, crud.Update):
"""
@@ -959,6 +980,9 @@ class LDAPUpdate(LDAPQuery, crud.Update):
def exc_callback(self, keys, options, exc, call_func, *call_args, **call_kwargs):
raise exc
+ def interactive_prompt_callback(self, kw):
+ return
+
class LDAPDelete(LDAPMultiQuery):
"""
@@ -1046,6 +1070,9 @@ class LDAPDelete(LDAPMultiQuery):
def exc_callback(self, keys, options, exc, call_func, *call_args, **call_kwargs):
raise exc
+ def interactive_prompt_callback(self, kw):
+ return
+
class LDAPModMember(LDAPQuery):
"""
@@ -1191,6 +1218,9 @@ class LDAPAddMember(LDAPModMember):
def exc_callback(self, keys, options, exc, call_func, *call_args, **call_kwargs):
raise exc
+ def interactive_prompt_callback(self, kw):
+ return
+
class LDAPRemoveMember(LDAPModMember):
"""
@@ -1297,6 +1327,9 @@ class LDAPRemoveMember(LDAPModMember):
def exc_callback(self, keys, options, exc, call_func, *call_args, **call_kwargs):
raise exc
+ def interactive_prompt_callback(self, kw):
+ return
+
class LDAPSearch(CallbackInterface, crud.Search):
"""
@@ -1501,6 +1534,9 @@ class LDAPSearch(CallbackInterface, crud.Search):
def exc_callback(self, args, options, exc, call_func, *call_args, **call_kwargs):
raise exc
+ def interactive_prompt_callback(self, kw):
+ return
+
# list of attributes we want exported to JSON
json_friendly_attributes = (
'takes_options',
@@ -1644,6 +1680,9 @@ class LDAPAddReverseMember(LDAPModReverseMember):
def exc_callback(self, keys, options, exc, call_func, *call_args, **call_kwargs):
raise exc
+ def interactive_prompt_callback(self, kw):
+ return
+
class LDAPRemoveReverseMember(LDAPModReverseMember):
"""
Remove other LDAP entries from members in reverse.
@@ -1753,3 +1792,6 @@ class LDAPRemoveReverseMember(LDAPModReverseMember):
def exc_callback(self, keys, options, exc, call_func, *call_args, **call_kwargs):
raise exc
+
+ def interactive_prompt_callback(self, kw):
+ return