mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
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>
This commit is contained in:
committed by
Petr Viktorin
parent
c644b47492
commit
4314d02fbf
@@ -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')),
|
||||
|
||||
Reference in New Issue
Block a user