Hello,
Recently i've learn how to use the python binding of openscap. It was pretty 
hard at the begin, because when you have not understand how this API works you 
are swimming in the fog :D
So firstly I think that a tutorial to explain how to approach this API should 
be awesome (how to interpret error, how to use C documentation through the api 
etc.)

Secondly, i think that an "introspection" feature should be great. For 
instance, when you are trying to use a callback and you don't really know what 
kind of argument you have, we actually need to:

  *   find which kind of object we have
  *   following this, deduct which functions are availables (overrided ones, or 
builtins ones). For the builtins you need to find the right page in the C 
documentation etc. (and if you don't know how the api routes function calls, 
you will probaly get lost)

But with a call to arg.introspect(), we cand return (or directly print ?):

  *   The object type (and potentatially interresting attributes).
  *   The overrided functions (using its __dict__ ).
  *   The builtins functions using OSCAP.__dict__ (and a filter to keep only 
the builtin functions prefixed with the object name).
  *   Potentially a link to the C documentation (faster, and avoid to choose a 
wrong documentation version like me ... )

Eventually a function listing all builtins functions (OSCAP.__dict__ ) should 
be usefull. For instance by calling openscap_api.introspect_all() or 
openscap_api.common.introspect()
So i'm looking forward for your advice about this proposal; i think it could be 
a good helper (it's not necessary but it helps, especially when you don't know 
well how to use this api), but perhaps some of you think it's not relevant.

Here is an example of function that i've add in openscap_api to facilitate my 
comprehension of objects. Of course I propose to make a proper version of that 
custom function, following what I said before. If you agree, have you remaks 
about notations etc. ? (should I print directly or return a string, is the call 
"obj.instrospect()" well nammed etc.) About the tutorial I was thinking to a 
README.md in the folder openscap/swig

# in class Oscap_Object:
  def introspect_current(self):
        """ Returns all builtin function accessible through SWIG which is 
corresponding to the current object """
        funcs=dict();
        for (k, v) in OSCAP.__dict__.items():
            if k.startswith(self.object):
                funcs[k]=v
        return funcs

test.py
# loading oval file and running eval agent with a callback
def oval_callback(msg, usr):
print("Msg returned by callback: "+msg.__repr__());
pprint(msg.introspect_current());

Result:
python3 test_api.py
OVAL file loaded :)
Msg returned by callback: <Oscap Object of type 'oval_result_definition' with 
instance '<Swig Object of type 'struct oval_result_definition *' at 
0x7f1ba4bd8120>'>
{'oval_result_definition_add_message': <built-in function 
oval_result_definition_add_message>,
 'oval_result_definition_clone': <built-in function 
oval_result_definition_clone>,
 'oval_result_definition_eval': <built-in function oval_result_definition_eval>,
 'oval_result_definition_free': <built-in function oval_result_definition_free>,
 'oval_result_definition_get_criteria': <built-in function 
oval_result_definition_get_criteria>,
 'oval_result_definition_get_definition': <built-in function 
oval_result_definition_get_definition>,
 'oval_result_definition_get_id': <built-in function 
oval_result_definition_get_id>,
 'oval_result_definition_get_instance': <built-in function 
oval_result_definition_get_instance>,
 'oval_result_definition_get_messages': <built-in function 
oval_result_definition_get_messages>,
 'oval_result_definition_get_result': <built-in function 
oval_result_definition_get_result>,
 'oval_result_definition_get_system': <built-in function 
oval_result_definition_get_system>,
etc.

Like i said, not necessary but it really easier (especially if a sample 
msg.introspect() is sufficient).

Regards,
Dominique.
_______________________________________________
Open-scap-list mailing list
Open-scap-list@redhat.com
https://www.redhat.com/mailman/listinfo/open-scap-list

Reply via email to