mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
Make LDAPObject classes JSON serializable.
This commit is contained in:
parent
9d9d789912
commit
5797c8167a
@ -21,6 +21,7 @@ Base classes for LDAP plugins.
|
||||
"""
|
||||
|
||||
import re
|
||||
import json
|
||||
|
||||
from ipalib import crud, errors, uuid
|
||||
from ipalib import Method, Object
|
||||
@ -29,6 +30,7 @@ from ipalib.base import NameSpace
|
||||
from ipalib.cli import to_cli, from_cli
|
||||
from ipalib import output
|
||||
from ipalib.text import _
|
||||
from ipalib.util import json_serialize
|
||||
|
||||
|
||||
def validate_add_attribute(ugettext, attr):
|
||||
@ -121,6 +123,21 @@ class LDAPObject(Object):
|
||||
}
|
||||
)
|
||||
|
||||
# list of attributes we want exported to JSON
|
||||
json_friendly_attributes = (
|
||||
'parent_object', 'container_dn', 'object_name', 'object_name_plural',
|
||||
'object_class', 'object_class_config', 'default_attributes', 'label',
|
||||
'hidden_attributes', 'uuid_attribute', 'attribute_members', 'name',
|
||||
'takes_params',
|
||||
)
|
||||
def __json__(self):
|
||||
json_dict = dict(
|
||||
(a, getattr(self, a)) for a in self.json_friendly_attributes
|
||||
)
|
||||
json_dict['primary_key'] = self.primary_key.name
|
||||
json_dict['methods'] = [m for m in self.methods]
|
||||
return json_dict
|
||||
|
||||
|
||||
# Options used by create and update.
|
||||
_attr_options = (
|
||||
|
@ -31,6 +31,12 @@ from ipalib import errors
|
||||
from ipapython import dnsclient
|
||||
|
||||
|
||||
def json_serialize(obj):
|
||||
if not callable(getattr(obj, '__json__', None)):
|
||||
# raise TypeError('%r is not JSON serializable')
|
||||
return ''
|
||||
return obj.__json__()
|
||||
|
||||
def get_current_principal():
|
||||
try:
|
||||
return unicode(krbV.default_context().default_ccache().principal().name)
|
||||
|
Loading…
Reference in New Issue
Block a user