This is used in quite a few commands, move to base class.
This ensures the correct encoder class and settings are always used,
and they are only defined in one place.
Signed-off-by: Rob van der Linde <rob@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
+import json
import optparse
import sys
import textwrap
from samba.logger import get_samba_logger
from samba.samdb import SamDB
+from .encoders import JSONEncoder
from .validators import ValidationError
return SamDB(ldap_url, credentials=creds,
session_info=system_session(lp), lp=lp)
+ def print_json(self, data):
+ """Print json on the screen using consistent formatting and sorting.
+
+ A custom JSONEncoder class is used to help with serializing unknown
+ objects such as Dn for example.
+ """
+ json.dump(data, self.outf, cls=JSONEncoder, indent=2, sort_keys=True)
+ self.outf.write("\n")
+
def show_command_error(self, e):
"""display a command error"""
if isinstance(e, CommandError):
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import json
-
from samba.netcmd import Command, CommandError
-from samba.netcmd.encoders import JSONEncoder
from samba.netcmd.domain.models import AuthenticationPolicy
super().__init__(*args, **kwargs)
self.ldb = None
- def print_json(self, data):
- """Print json on the screen using consistent formatting and sorting.
-
- A custom JSONEncoder class is used to help with serializing unknown
- objects such as Dn for example.
- """
- json.dump(data, self.outf, cls=JSONEncoder, indent=2, sort_keys=True)
- self.outf.write("\n")
-
def get_policy(self, name):
"""Helper function to return auth policy or raise CommandError.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-import json
-
from ldb import SCOPE_ONELEVEL
from samba.netcmd import Command
-from samba.netcmd.encoders import JSONEncoder
class ClaimCommand(Command):
super().__init__(*args, **kwargs)
self.ldb = None
- def print_json(self, data):
- """Print json on the screen using consistent formatting and sorting.
-
- A custom JSONEncoder class is used to help with serializing unknown
- objects such as Dn for example.
- """
- json.dump(data, self.outf, cls=JSONEncoder, indent=2, sort_keys=True)
- self.outf.write("\n")
-
def get_attribute_from_schema(self, name):
"""Find DN by name in attribute schema.