mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
batch, schema: use Dict instead of Any
Add new Dict parameter class and use it in the batch and command_defaults plugins. https://fedorahosted.org/freeipa/ticket/4739 Reviewed-By: David Kupka <dkupka@redhat.com>
This commit is contained in:
4
API.txt
4
API.txt
@@ -446,7 +446,7 @@ output: Output('summary', type=[<type 'unicode'>, <type 'NoneType'>])
|
||||
output: PrimaryKey('value')
|
||||
command: batch
|
||||
args: 1,1,2
|
||||
arg: Any('methods*')
|
||||
arg: Dict('methods*')
|
||||
option: Str('version?')
|
||||
output: Output('count', type=[<type 'int'>])
|
||||
output: Output('results', type=[<type 'list'>, <type 'tuple'>])
|
||||
@@ -853,7 +853,7 @@ output: PrimaryKey('value')
|
||||
command: command_defaults
|
||||
args: 1,3,1
|
||||
arg: Str('name')
|
||||
option: Any('kw?')
|
||||
option: Dict('kw?')
|
||||
option: Str('params*')
|
||||
option: Str('version?')
|
||||
output: Output('result')
|
||||
|
||||
@@ -41,8 +41,8 @@ _PARAMS = {
|
||||
'bool': parameters.Bool,
|
||||
'bytes': parameters.Bytes,
|
||||
'datetime': parameters.DateTime,
|
||||
'dict': parameters.Dict,
|
||||
'int': parameters.Int,
|
||||
'object': parameters.Any,
|
||||
'str': parameters.Str,
|
||||
}
|
||||
|
||||
|
||||
@@ -1961,3 +1961,12 @@ class DNSNameParam(Param):
|
||||
def _rule_only_relative(self, _, value):
|
||||
if self.only_relative and value.is_absolute():
|
||||
return _('must be relative')
|
||||
|
||||
|
||||
class Dict(Param):
|
||||
"""
|
||||
A parameter for dictionary.
|
||||
"""
|
||||
|
||||
type = dict
|
||||
type_error = _("must be dictionary")
|
||||
|
||||
@@ -49,7 +49,7 @@ import six
|
||||
|
||||
from ipalib import api, errors
|
||||
from ipalib import Command
|
||||
from ipalib.parameters import Str, Any
|
||||
from ipalib.parameters import Str, Dict
|
||||
from ipalib.output import Output
|
||||
from ipalib.text import _
|
||||
from ipalib.request import context
|
||||
@@ -66,7 +66,7 @@ class batch(Command):
|
||||
NO_CLI = True
|
||||
|
||||
takes_args = (
|
||||
Any('methods*',
|
||||
Dict('methods*',
|
||||
doc=_('Nested Methods to execute'),
|
||||
),
|
||||
)
|
||||
@@ -90,12 +90,6 @@ class batch(Command):
|
||||
def execute(self, methods=None, **options):
|
||||
results = []
|
||||
for arg in (methods or []):
|
||||
# As take_args = Any, no check is done before
|
||||
# Need to make sure that methods contain dict objects
|
||||
if not isinstance(arg, dict):
|
||||
raise errors.ConversionError(
|
||||
name='methods',
|
||||
error=_(u'must contain dict objects'))
|
||||
params = dict()
|
||||
name = None
|
||||
try:
|
||||
|
||||
@@ -12,7 +12,7 @@ from ipalib import errors
|
||||
from ipalib.crud import PKQuery, Retrieve, Search
|
||||
from ipalib.frontend import Command, Method, Object
|
||||
from ipalib.output import Entry, ListOfEntries, ListOfPrimaryKeys, PrimaryKey
|
||||
from ipalib.parameters import Any, Bool, Flag, Int, Str
|
||||
from ipalib.parameters import Bool, Dict, Flag, Int, Str
|
||||
from ipalib.plugable import Registry
|
||||
from ipalib.text import _
|
||||
from ipapython.version import API_VERSION
|
||||
@@ -216,18 +216,14 @@ class command_defaults(PKQuery):
|
||||
|
||||
takes_options = (
|
||||
Str('params*'),
|
||||
Any('kw?'),
|
||||
Dict('kw?'),
|
||||
)
|
||||
|
||||
def execute(self, name, **options):
|
||||
command = self.api.Command[name]
|
||||
|
||||
params = options.get('params', [])
|
||||
|
||||
kw = options.get('kw', {})
|
||||
if not isinstance(kw, dict):
|
||||
raise errors.ConversionError(name=name,
|
||||
error=_("must be a dictionary"))
|
||||
|
||||
result = command.get_default(params, **kw)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user