summaryrefslogtreecommitdiffstats
path: root/ipalib/output.py
diff options
context:
space:
mode:
authorJan Cholasta <jcholast@redhat.com>2014-03-27 14:04:00 +0100
committerPetr Viktorin <pviktori@redhat.com>2014-04-18 14:59:20 +0200
commit4314d02fbf9ef1cb9543ecf76a8d22e79d250214 (patch)
tree8c6ac601e881712e8cf7c25fce420026a3762553 /ipalib/output.py
parentc644b47492e22370bc71f57e5ac46b50f9b4e247 (diff)
downloadfreeipa-4314d02fbf9ef1cb9543ecf76a8d22e79d250214.tar.gz
freeipa-4314d02fbf9ef1cb9543ecf76a8d22e79d250214.tar.xz
freeipa-4314d02fbf9ef1cb9543ecf76a8d22e79d250214.zip
Allow primary keys to use different type than unicode.
Also return list of primary keys instead of a single unicode CSV value from LDAPDelete-based commands. This introduces a new capability 'primary_key_types' for backward compatibility with old clients. Reviewed-By: Tomas Babej <tbabej@redhat.com>
Diffstat (limited to 'ipalib/output.py')
-rw-r--r--ipalib/output.py52
1 files changed, 50 insertions, 2 deletions
diff --git a/ipalib/output.py b/ipalib/output.py
index 1f42b4d6e..3501cddd2 100644
--- a/ipalib/output.py
+++ b/ipalib/output.py
@@ -24,6 +24,7 @@ Simple description of return values.
from inspect import getdoc
from types import NoneType
from plugable import ReadOnly, lock
+from capabilities import client_has_capability
from text import _
@@ -99,7 +100,7 @@ class ListOfEntries(Output):
type = (list, tuple)
doc = _('A list of LDAP entries')
- def validate(self, cmd, entries):
+ def validate(self, cmd, entries, version):
assert isinstance(entries, self.type)
for (i, entry) in enumerate(entries):
if not isinstance(entry, dict):
@@ -107,6 +108,47 @@ class ListOfEntries(Output):
self.name, i, dict, type(entry), entry)
)
+class PrimaryKey(Output):
+ def validate(self, cmd, value, version):
+ if client_has_capability(version, 'primary_key_types'):
+ if hasattr(cmd, 'obj') and cmd.obj and cmd.obj.primary_key:
+ types = cmd.obj.primary_key.allowed_types
+ else:
+ types = (unicode,)
+ types = types + (NoneType,)
+ else:
+ types = (unicode,)
+ if not isinstance(value, types):
+ raise TypeError(
+ "%s.validate_output() => %s.validate():\n"
+ " output[%r]: need %r; got %r: %r" % (
+ cmd.name, self.__class__.__name__, self.name,
+ types[0], type(value), value))
+
+class ListOfPrimaryKeys(Output):
+ def validate(self, cmd, values, version):
+ if client_has_capability(version, 'primary_key_types'):
+ types = (tuple, list)
+ else:
+ types = (unicode,)
+ if not isinstance(values, types):
+ raise TypeError(
+ "%s.validate_output() => %s.validate():\n"
+ " output[%r]: need %r; got %r: %r" % (
+ cmd.name, self.__class__.__name__, self.name,
+ types[0], type(values), values))
+
+ if client_has_capability(version, 'primary_key_types'):
+ if hasattr(cmd, 'obj') and cmd.obj and cmd.obj.primary_key:
+ types = cmd.obj.primary_key.allowed_types
+ else:
+ types = (unicode,)
+ for (i, value) in enumerate(values):
+ if not isinstance(value, types):
+ raise TypeError(emsg % (
+ cmd.name, self.__class__.__name__, i, self.name,
+ types[0], type(value), value))
+
result = Output('result', doc=_('All commands should at least have a result'))
@@ -114,7 +156,7 @@ summary = Output('summary', (unicode, NoneType),
_('User-friendly description of action performed')
)
-value = Output('value', unicode,
+value = PrimaryKey('value', None,
_("The primary_key value of the entry, e.g. 'jdoe' for a user"),
flags=['no_display'],
)
@@ -140,6 +182,12 @@ standard_delete = (
value,
)
+standard_multi_delete = (
+ summary,
+ Output('result', dict, _('List of deletions that failed')),
+ ListOfPrimaryKeys('value', flags=['no_display']),
+)
+
standard_boolean = (
summary,
Output('result', bool, _('True means the operation was successful')),