#49683 lib389 CLI tools need JSON output option
Closed: wontfix 3 years ago Opened 4 years ago by mreynolds.

Issue Description

The new Cockpit UI will use the lib389 cli tools for all things DS. The tool needs an option for returning JSON objects to the caller (the UI in this case).

We need JSON object(s) for schema/index lists, standard ldap entries (reuse work from rest389?), monitoring, replication, tasks, etc. Ideally there should be as few unique representations as possible: "list" representation, "entry" representation, ... We could use one representation for everything, but I want to keep the UI's work minimal and have lib389 do all the leg work. So having multiple JSON representations "might" be more efficient, but this needs more investigation.

Expected results


After reviewing what needs to be done I think using a single representation for all CLI results is best. Starting work...

Metadata Update from @mreynolds:
- Custom field component adjusted to None
- Custom field origin adjusted to None
- Custom field reviewstatus adjusted to None
- Custom field type adjusted to None
- Custom field version adjusted to None

4 years ago

Fortunately lib389 has built in JSON for returning data (entry, or attrs). But there looks like there are some issues ensure_str when it encounters a binary value like "nsstate" in the Replica object entry

../../../../src/lib389/lib389/_mapped_object.py:168: in _jsonify
    str_attrs[ensure_str(k)] = ensure_list_str(attrs[k])
../../../../src/lib389/lib389/utils.py:957: in ensure_list_str
    return [ensure_str(v) for v in val]
../../../../src/lib389/lib389/utils.py:957: in <listcomp>
    return [ensure_str(v) for v in val]
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

attr = nsstate
val = b'\x01\x00\x00\x00\x00\x00\x00\x00\xe7\xa6\xfcZ\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00'

    def ensure_str(val):
        if val != None and type(val) != str:
>           return val.decode('utf-8')
E           UnicodeDecodeError: 'utf-8' codec can't decode bytes in position 8-9: invalid continuation byte

../../../../src/lib389/lib389/utils.py:942: UnicodeDecodeError

I have a fix for this but I'm not sure it's correct:

 def ensure_str(val):
     if val != None and type(val) != str:
-        return val.decode('utf-8')
+        try:
+            result = val.decode('utf-8')
+        except UnicodeDecodeError:
+            # binary value, just return str repr?
+            result = str(val)
+        return result
     return val

We should also have a JSON "result" object for when things go wrong: error code and message

Metadata Update from @mreynolds:
- Custom field reviewstatus adjusted to review (was: None)

4 years ago

Metadata Update from @spichugi:
- Custom field reviewstatus adjusted to ack (was: review)

3 years ago

Metadata Update from @mreynolds:
- Issue close_status updated to: fixed
- Issue status updated to: Closed (was: Open)

3 years ago

389-ds-base is moving from Pagure to Github. This means that new issues and pull requests
will be accepted only in 389-ds-base's github repository.

This issue has been cloned to Github and is available here:
- https://github.com/389ds/389-ds-base/issues/2742

If you want to receive further updates on the issue, please navigate to the github issue
and click on subscribe button.

Thank you for understanding. We apologize for all inconvenience.

Metadata Update from @spichugi:
- Issue close_status updated to: wontfix (was: fixed)

2 years ago

Login to comment on this ticket.

Metadata