mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
ipalib: make optional positional command arguments actually optional
Fix several plugins not to assume optional positional arguments have a value of None when not specified. https://fedorahosted.org/freeipa/ticket/4739 Reviewed-By: David Kupka <dkupka@redhat.com>
This commit is contained in:
parent
f8cf136c55
commit
71f960457e
@ -700,7 +700,7 @@ class aci_find(crud.Search):
|
||||
takes_options = (_prefix_option.clone_rename("aciprefix?", required=False),
|
||||
gen_pkey_only_option("name"),)
|
||||
|
||||
def execute(self, term, **kw):
|
||||
def execute(self, term=None, **kw):
|
||||
ldap = self.api.Backend.ldap2
|
||||
|
||||
entry = ldap.get_entry(self.api.env.basedn, ['aci'])
|
||||
|
@ -2017,9 +2017,14 @@ class LDAPSearch(BaseLDAPCommand, crud.Search):
|
||||
def execute(self, *args, **options):
|
||||
ldap = self.obj.backend
|
||||
|
||||
term = args[-1]
|
||||
index = tuple(self.args).index('criteria')
|
||||
keys = args[:index]
|
||||
try:
|
||||
term = args[index]
|
||||
except IndexError:
|
||||
term = None
|
||||
if self.obj.parent_object:
|
||||
base_dn = self.api.Object[self.obj.parent_object].get_dn(*args[:-1])
|
||||
base_dn = self.api.Object[self.obj.parent_object].get_dn(*keys)
|
||||
else:
|
||||
base_dn = DN(self.obj.container_dn, api.env.basedn)
|
||||
assert isinstance(base_dn, DN)
|
||||
@ -2083,7 +2088,7 @@ class LDAPSearch(BaseLDAPCommand, crud.Search):
|
||||
except errors.EmptyResult:
|
||||
(entries, truncated) = ([], False)
|
||||
except errors.NotFound:
|
||||
self.api.Object[self.obj.parent_object].handle_not_found(*args[:-1])
|
||||
self.api.Object[self.obj.parent_object].handle_not_found(*keys)
|
||||
|
||||
for callback in self.get_callbacks('post'):
|
||||
truncated = callback(self, ldap, entries, truncated, *args, **options)
|
||||
|
@ -87,9 +87,9 @@ class batch(Command):
|
||||
Output('results', (list, tuple), doc='')
|
||||
)
|
||||
|
||||
def execute(self, *args, **options):
|
||||
def execute(self, methods=None, **options):
|
||||
results = []
|
||||
for arg in (args[0] or []):
|
||||
for arg in (methods or []):
|
||||
params = dict()
|
||||
name = None
|
||||
try:
|
||||
|
@ -197,7 +197,7 @@ class delegation_find(crud.Search):
|
||||
takes_options = (gen_pkey_only_option("name"),)
|
||||
has_output_params = output_params
|
||||
|
||||
def execute(self, term, **kw):
|
||||
def execute(self, term=None, **kw):
|
||||
kw['aciprefix'] = ACI_PREFIX
|
||||
results = api.Command['aci_find'](term, **kw)['result']
|
||||
|
||||
|
@ -1654,8 +1654,8 @@ def _convert_to_idna(value):
|
||||
pass
|
||||
return None
|
||||
|
||||
def _create_idn_filter(cmd, ldap, *args, **options):
|
||||
term = args[-1]
|
||||
|
||||
def _create_idn_filter(cmd, ldap, term=None, **options):
|
||||
if term:
|
||||
#include idna values to search
|
||||
term_idna = _convert_to_idna(term)
|
||||
@ -4191,11 +4191,12 @@ class dnsrecord_find(LDAPSearch):
|
||||
continue
|
||||
yield option
|
||||
|
||||
def pre_callback(self, ldap, filter, attrs_list, base_dn, scope, *args, **options):
|
||||
def pre_callback(self, ldap, filter, attrs_list, base_dn, scope,
|
||||
dnszoneidnsname, *args, **options):
|
||||
assert isinstance(base_dn, DN)
|
||||
|
||||
# validate if zone is master zone
|
||||
self.obj.check_zone(args[-2], **options)
|
||||
self.obj.check_zone(dnszoneidnsname, **options)
|
||||
|
||||
filter = _create_idn_filter(self, ldap, *args, **options)
|
||||
return (filter, base_dn, ldap.SCOPE_SUBTREE)
|
||||
|
@ -455,7 +455,8 @@ class group_find(LDAPSearch):
|
||||
),
|
||||
)
|
||||
|
||||
def pre_callback(self, ldap, filter, attrs_list, base_dn, scope, *args, **options):
|
||||
def pre_callback(self, ldap, filter, attrs_list, base_dn, scope,
|
||||
criteria=None, **options):
|
||||
assert isinstance(base_dn, DN)
|
||||
|
||||
# filter groups by pseudo type
|
||||
@ -485,7 +486,7 @@ class group_find(LDAPSearch):
|
||||
if len(attrs) == 1 and isinstance(attrs[0], six.string_types):
|
||||
search_attrs = attrs[0].split(',')
|
||||
for a in search_attrs:
|
||||
search_kw[a] = args[-1]
|
||||
search_kw[a] = criteria
|
||||
cflt = ldap.make_filter(search_kw, exact=False)
|
||||
|
||||
filter = ldap.combine_filters((oflt, cflt), rules=ldap.MATCH_ALL)
|
||||
|
@ -70,7 +70,7 @@ class json_metadata(Command):
|
||||
Output('commands', dict, doc=_('Dict of JSON encoded IPA Commands')),
|
||||
)
|
||||
|
||||
def execute(self, objname, methodname, **options):
|
||||
def execute(self, objname=None, methodname=None, **options):
|
||||
objects = dict()
|
||||
methods = dict()
|
||||
commands = dict()
|
||||
|
@ -149,6 +149,9 @@ class krbtpolicy(baseldap.LDAPObject):
|
||||
class krbtpolicy_mod(baseldap.LDAPUpdate):
|
||||
__doc__ = _('Modify Kerberos ticket policy.')
|
||||
|
||||
def execute(self, uid=None, **options):
|
||||
return super(krbtpolicy_mod, self).execute(uid, **options)
|
||||
|
||||
def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
|
||||
assert isinstance(dn, DN)
|
||||
# disable all flag
|
||||
@ -162,6 +165,9 @@ class krbtpolicy_mod(baseldap.LDAPUpdate):
|
||||
class krbtpolicy_show(baseldap.LDAPRetrieve):
|
||||
__doc__ = _('Display the current Kerberos ticket policy.')
|
||||
|
||||
def execute(self, uid=None, **options):
|
||||
return super(krbtpolicy_show, self).execute(uid, **options)
|
||||
|
||||
def pre_callback(self, ldap, dn, attrs_list, *keys, **options):
|
||||
assert isinstance(dn, DN)
|
||||
# disable all flag
|
||||
@ -206,14 +212,14 @@ class krbtpolicy_reset(baseldap.LDAPQuery):
|
||||
|
||||
has_output = output.standard_entry
|
||||
|
||||
def execute(self, *keys, **options):
|
||||
def execute(self, uid=None, **options):
|
||||
ldap = self.obj.backend
|
||||
|
||||
dn = self.obj.get_dn(*keys, **options)
|
||||
dn = self.obj.get_dn(uid, **options)
|
||||
|
||||
def_values = {}
|
||||
# if reseting policy for a user - just his values
|
||||
if keys[-1] is not None:
|
||||
if uid is not None:
|
||||
for a in self.obj.default_attributes:
|
||||
def_values[a] = None
|
||||
# if reseting global policy - set values to default
|
||||
@ -227,11 +233,11 @@ class krbtpolicy_reset(baseldap.LDAPQuery):
|
||||
except errors.EmptyModlist:
|
||||
pass
|
||||
|
||||
if keys[-1] is not None:
|
||||
if uid is not None:
|
||||
# policy for user was deleted, retrieve global policy
|
||||
dn = self.obj.get_dn(None)
|
||||
entry_attrs = ldap.get_entry(dn, self.obj.default_attributes)
|
||||
|
||||
entry_attrs = entry_to_dict(entry_attrs, **options)
|
||||
|
||||
return dict(result=entry_attrs, value=pkey_to_value(keys[-1], options))
|
||||
return dict(result=entry_attrs, value=pkey_to_value(uid, options))
|
||||
|
@ -85,7 +85,7 @@ class env(LocalOrRemote):
|
||||
keys.add(query)
|
||||
return keys
|
||||
|
||||
def execute(self, variables, **options):
|
||||
def execute(self, variables=None, **options):
|
||||
if variables is None:
|
||||
keys = self.env
|
||||
else:
|
||||
|
@ -291,6 +291,9 @@ class otptoken_add(LDAPCreate):
|
||||
Str('uri?', label=_('URI')),
|
||||
)
|
||||
|
||||
def execute(self, ipatokenuniqueid=None, **options):
|
||||
return super(otptoken_add, self).execute(ipatokenuniqueid, **options)
|
||||
|
||||
def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
|
||||
# Fill in a default UUID when not specified.
|
||||
if entry_attrs.get('ipatokenuniqueid', None) is None:
|
||||
|
@ -488,6 +488,9 @@ class pwpolicy_del(LDAPDelete):
|
||||
class pwpolicy_mod(LDAPUpdate):
|
||||
__doc__ = _('Modify a group password policy.')
|
||||
|
||||
def execute(self, cn=None, **options):
|
||||
return super(pwpolicy_mod, self).execute(cn, **options)
|
||||
|
||||
def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
|
||||
assert isinstance(dn, DN)
|
||||
self.obj.convert_time_on_input(entry_attrs)
|
||||
@ -538,6 +541,9 @@ class pwpolicy_show(LDAPRetrieve):
|
||||
),
|
||||
)
|
||||
|
||||
def execute(self, cn=None, **options):
|
||||
return super(pwpolicy_show, self).execute(cn, **options)
|
||||
|
||||
def pre_callback(self, ldap, dn, attrs_list, *keys, **options):
|
||||
assert isinstance(dn, DN)
|
||||
if options.get('user') is not None:
|
||||
|
@ -194,7 +194,7 @@ class selfservice_find(crud.Search):
|
||||
takes_options = (gen_pkey_only_option("name"),)
|
||||
has_output_params = output_params
|
||||
|
||||
def execute(self, term, **kw):
|
||||
def execute(self, term=None, **kw):
|
||||
kw['selfaci'] = True
|
||||
kw['aciprefix'] = ACI_PREFIX
|
||||
result = api.Command['aci_find'](term, **kw)['result']
|
||||
|
@ -500,7 +500,7 @@ class servicedelegationtarget_find(LDAPSearch):
|
||||
)
|
||||
|
||||
def pre_callback(self, ldap, filters, attrs_list, base_dn, scope,
|
||||
*args, **options):
|
||||
term=None, **options):
|
||||
"""
|
||||
Exclude rules from the search output. A target contains a subset
|
||||
of a rule objectclass.
|
||||
@ -515,7 +515,6 @@ class servicedelegationtarget_find(LDAPSearch):
|
||||
)
|
||||
|
||||
search_kw = {}
|
||||
term = args[-1]
|
||||
for a in self.obj.default_attributes:
|
||||
search_kw[a] = term
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user