summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ipalib/frontend.py21
-rw-r--r--ipalib/parameters.py15
-rw-r--r--ipalib/plugins/baseldap.py9
3 files changed, 40 insertions, 5 deletions
diff --git a/ipalib/frontend.py b/ipalib/frontend.py
index e8a84eabe..10087ba24 100644
--- a/ipalib/frontend.py
+++ b/ipalib/frontend.py
@@ -1003,13 +1003,32 @@ class Command(HasParam):
# list of attributes we want exported to JSON
json_friendly_attributes = (
- 'name', 'takes_args', 'takes_options',
+ 'name', 'takes_args',
)
+ # list of options we want only to mention their presence and not to write
+ # their attributes
+ json_only_presence_options = (
+ 'all', 'raw', 'attrs', 'addattr', 'delattr', 'setattr', 'version',
+ )
+
+ def get_json_options(self):
+ """
+ Get only options we want exported to JSON
+ """
+ for option in self.get_options():
+ if option.name not in self.json_only_presence_options:
+ yield option
+ else:
+ yield { 'name': option.name }
+
def __json__(self):
json_dict = dict(
(a, getattr(self, a)) for a in self.json_friendly_attributes
)
+
+ json_dict['takes_options'] = list(self.get_json_options())
+
return json_dict
class LocalOrRemote(Command):
diff --git a/ipalib/parameters.py b/ipalib/parameters.py
index 529f15b37..cdc991f48 100644
--- a/ipalib/parameters.py
+++ b/ipalib/parameters.py
@@ -961,15 +961,28 @@ class Param(ReadOnly):
pass
return self.default
+ json_exclude_attrs = (
+ 'alwaysask', 'autofill', 'cli_name', 'cli_short_name', 'csv',
+ 'csv_separator', 'csv_skipspace', 'sortorder', 'falsehoods', 'truths',
+ 'version',
+ )
+
def __json__(self):
json_dict = {}
for (a, k, d) in self.kwargs:
+ if a in self.json_exclude_attrs:
+ continue
if k in (callable, DefaultFrom):
continue
elif isinstance(getattr(self, a), frozenset):
json_dict[a] = [k for k in getattr(self, a, [])]
else:
- json_dict[a] = getattr(self, a, '')
+ val = getattr(self, a, '')
+ if val is None or not val:
+ # ignore false and not set because lack of their presence is
+ # the information itself
+ continue;
+ json_dict[a] = val
json_dict['class'] = self.__class__.__name__
json_dict['name'] = self.name
json_dict['type'] = self.type.__name__
diff --git a/ipalib/plugins/baseldap.py b/ipalib/plugins/baseldap.py
index 93852a2dd..b8ef43d47 100644
--- a/ipalib/plugins/baseldap.py
+++ b/ipalib/plugins/baseldap.py
@@ -1091,13 +1091,14 @@ class LDAPCreate(BaseLDAPCommand, crud.Create):
# list of attributes we want exported to JSON
json_friendly_attributes = (
- 'takes_args', 'takes_options',
+ 'takes_args',
)
def __json__(self):
json_dict = dict(
(a, getattr(self, a)) for a in self.json_friendly_attributes
)
+ json_dict['takes_options'] = list(self.get_json_options())
return json_dict
class LDAPQuery(BaseLDAPCommand, crud.PKQuery):
@@ -1115,13 +1116,14 @@ class LDAPQuery(BaseLDAPCommand, crud.PKQuery):
# list of attributes we want exported to JSON
json_friendly_attributes = (
- 'takes_args', 'takes_options',
+ 'takes_args',
)
def __json__(self):
json_dict = dict(
(a, getattr(self, a)) for a in self.json_friendly_attributes
)
+ json_dict['takes_options'] = list(self.get_json_options())
return json_dict
class LDAPMultiQuery(LDAPQuery):
@@ -1894,13 +1896,14 @@ class LDAPSearch(BaseLDAPCommand, crud.Search):
# list of attributes we want exported to JSON
json_friendly_attributes = (
- 'takes_options',
+ 'takes_args',
)
def __json__(self):
json_dict = dict(
(a, getattr(self, a)) for a in self.json_friendly_attributes
)
+ json_dict['takes_options'] = list(self.get_json_options())
return json_dict
class LDAPModReverseMember(LDAPQuery):