mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
include more information in metadata
added to commands: doc, proper args, NO_CLI added to options: default_from, cli_name, cli_short_name and others https://fedorahosted.org/freeipa/ticket/3129 Reviewed-By: Martin Kosek <mkosek@redhat.com> Reviewed-By: Tomas Babej <tbabej@redhat.com>
This commit is contained in:
parent
884afb5d38
commit
ba0a1c6b33
@ -35,6 +35,7 @@ from errors import (ZeroArgumentError, MaxArgumentError, OverlapError,
|
|||||||
VersionError, OptionError, InvocationError,
|
VersionError, OptionError, InvocationError,
|
||||||
ValidationError, ConversionError)
|
ValidationError, ConversionError)
|
||||||
from ipalib import messages
|
from ipalib import messages
|
||||||
|
from ipalib.util import json_serialize
|
||||||
from textwrap import wrap
|
from textwrap import wrap
|
||||||
|
|
||||||
|
|
||||||
@ -1046,31 +1047,16 @@ class Command(HasParam):
|
|||||||
|
|
||||||
# list of attributes we want exported to JSON
|
# list of attributes we want exported to JSON
|
||||||
json_friendly_attributes = (
|
json_friendly_attributes = (
|
||||||
'name', 'takes_args',
|
'name', 'doc', 'NO_CLI'
|
||||||
)
|
)
|
||||||
|
|
||||||
# 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):
|
def __json__(self):
|
||||||
json_dict = dict(
|
json_dict = dict(
|
||||||
(a, getattr(self, a)) for a in self.json_friendly_attributes
|
(a, getattr(self, a)) for a in self.json_friendly_attributes
|
||||||
)
|
)
|
||||||
|
|
||||||
json_dict['takes_options'] = list(self.get_json_options())
|
json_dict['takes_args'] = list(self.get_args())
|
||||||
|
json_dict['takes_options'] = list(self.get_options())
|
||||||
|
|
||||||
return json_dict
|
return json_dict
|
||||||
|
|
||||||
@ -1206,6 +1192,20 @@ class Object(HasParam):
|
|||||||
return 1
|
return 1
|
||||||
return 2
|
return 2
|
||||||
|
|
||||||
|
json_friendly_attributes = (
|
||||||
|
'name', 'takes_params',
|
||||||
|
)
|
||||||
|
|
||||||
|
def __json__(self):
|
||||||
|
json_dict = dict(
|
||||||
|
(a, json_serialize(getattr(self, a)))
|
||||||
|
for a in self.json_friendly_attributes
|
||||||
|
)
|
||||||
|
if self.primary_key:
|
||||||
|
json_dict['primary_key'] = self.primary_key.name
|
||||||
|
json_dict['methods'] = [m for m in self.methods]
|
||||||
|
return json_dict
|
||||||
|
|
||||||
|
|
||||||
class Attribute(Plugin):
|
class Attribute(Plugin):
|
||||||
"""
|
"""
|
||||||
|
@ -240,6 +240,9 @@ class DefaultFrom(ReadOnly):
|
|||||||
except StandardError:
|
except StandardError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def __json__(self):
|
||||||
|
return self.keys
|
||||||
|
|
||||||
|
|
||||||
def parse_param_spec(spec):
|
def parse_param_spec(spec):
|
||||||
"""
|
"""
|
||||||
@ -917,30 +920,14 @@ class Param(ReadOnly):
|
|||||||
def sort_key(self, value):
|
def sort_key(self, value):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
json_exclude_attrs = (
|
|
||||||
'alwaysask', 'autofill', 'cli_name', 'cli_short_name', 'csv',
|
|
||||||
'sortorder', 'falsehoods', 'truths', 'version',
|
|
||||||
)
|
|
||||||
|
|
||||||
def __json__(self):
|
def __json__(self):
|
||||||
json_dict = {}
|
json_dict = {}
|
||||||
for (a, k, d) in self.kwargs:
|
for key in self.__kw:
|
||||||
if a in self.json_exclude_attrs:
|
json_dict[key] = json_serialize(self.__kw[key])
|
||||||
continue
|
|
||||||
if k in (callable, DefaultFrom):
|
|
||||||
continue
|
|
||||||
elif isinstance(getattr(self, a), frozenset):
|
|
||||||
json_dict[a] = [k for k in getattr(self, a, [])]
|
|
||||||
else:
|
|
||||||
val = getattr(self, a, '')
|
|
||||||
if val is None or val is False:
|
|
||||||
# ignore False and not set because lack of their presence is
|
|
||||||
# the information itself
|
|
||||||
continue;
|
|
||||||
json_dict[a] = json_serialize(val)
|
|
||||||
json_dict['class'] = self.__class__.__name__
|
json_dict['class'] = self.__class__.__name__
|
||||||
json_dict['name'] = self.name
|
json_dict['name'] = self.name
|
||||||
json_dict['type'] = self.type.__name__
|
json_dict['type'] = self.type.__name__
|
||||||
|
json_dict['flags'] = json_serialize([f for f in self.flags])
|
||||||
return json_dict
|
return json_dict
|
||||||
|
|
||||||
|
|
||||||
|
@ -1299,17 +1299,6 @@ class LDAPCreate(BaseLDAPCommand, crud.Create):
|
|||||||
def interactive_prompt_callback(self, kw):
|
def interactive_prompt_callback(self, kw):
|
||||||
return
|
return
|
||||||
|
|
||||||
# list of attributes we want exported to JSON
|
|
||||||
json_friendly_attributes = (
|
|
||||||
'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):
|
class LDAPQuery(BaseLDAPCommand, crud.PKQuery):
|
||||||
"""
|
"""
|
||||||
@ -1321,17 +1310,6 @@ class LDAPQuery(BaseLDAPCommand, crud.PKQuery):
|
|||||||
for arg in super(LDAPQuery, self).get_args():
|
for arg in super(LDAPQuery, self).get_args():
|
||||||
yield arg
|
yield arg
|
||||||
|
|
||||||
# list of attributes we want exported to JSON
|
|
||||||
json_friendly_attributes = (
|
|
||||||
'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):
|
class LDAPMultiQuery(LDAPQuery):
|
||||||
"""
|
"""
|
||||||
@ -2131,17 +2109,6 @@ class LDAPSearch(BaseLDAPCommand, crud.Search):
|
|||||||
def interactive_prompt_callback(self, kw):
|
def interactive_prompt_callback(self, kw):
|
||||||
return
|
return
|
||||||
|
|
||||||
# list of attributes we want exported to JSON
|
|
||||||
json_friendly_attributes = (
|
|
||||||
'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):
|
class LDAPModReverseMember(LDAPQuery):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user