Univention Bugzilla – Bug 51280
Write active S4-Connector mapping to log file
Last modified: 2020-06-25 16:23:54 CEST
Since Commit 4795bb08ed for Bug #48410 the committed mapping.py file doesn't show the active mapping any longer. E.g. the mapping_table generated from UCR connector/s4/mapping/group/table/ is not shown any more. This makes it hard for supporters to see what the S4-Connector is configured to do.
Created attachment 10360 [details] print_mapping.diff Something like this.
There is already logging in: services/univention-s4-connector/modules/univention/s4connector/s4/__init__.py: 729 » » ud.debug(ud.LDAP, ud.ALL, 'Mapping is: %s' % (pprint.pformat(property, indent=4, width=250)))
Plus you can also do: python -i /etc/univention/connector/s4/mapping.py >>> print(s4_mapping)
Re: Comment 2: Ok two things: * we should at least lower the minimal debug level to INFO, ALL (4) is a bit much. * we should find a different place for this, because at that point in the mapping gets logged every time somebody runs univention-s4connector-list-rejected. Or we should adjust something about the logging.
OK. Let's always print it to the status logfile when starting the S4-connector and remove it from regular logging.
The current logging is insufficient (example taken from ADC): 17.06.2020 15:16:09.284 LDAP (ALL ): Mapping is: { 'container': <univention.connector.property instance at 0x7f1794e14d88>, 'group': <univention.connector.property instance at 0x7f1794e14b00>, 'ou': <univention.connector.property instance at 0x7f1794e14e60>, 'user': <univention.connector.property instance at 0x7f1794e148c0>, 'windowscomputer': <univention.connector.property instance at 0x7f1794e14cb0>}
Gosh, this pprint/__repr__ technique results in proper uglyness: ======================= 17.06.2020 22:58:18.485 LDAP (INFO ): Mapping: { 'container': univention.connector.property(**{ 'attributes': { 'cn': univention.connector.attribute(**{ 'compare_function': <function compare_lowercase at 0x7f3751cac7d0>, 'con_attribute': 'cn', 'con_other_attribute': '', 'con_value_merge_function': '', 'ldap_attribute': 'cn', 'required': 1, [...] ======================= Why on earth doesn't pprint print a newline after the opening brackets/braces/parentheses? Is this even PEP8?
(In reply to Arvid Requate from comment #8) > Gosh, this pprint/__repr__ technique results in proper uglyness: Yes, the alternative would be: `json.dumps(foo, indent=4, sort_keys=True)`
Problem with that is: TypeError: <function compare_lowercase at 0x7f5b878c17d0> is not JSON serializable So we'd either have to subclass JSONEncoder (resulted in even more uglyness in my attempts, but that surely could work). or convert the functions to callable classes, which is too intrusive for my taste, just to print the mapping. For now I'll stick to my ugly code producing less ugly output in the ADC.
Felix also requested, that this should rather be written into a separate file. Like /usr/sbin/univention-s4-connector does "cat mapping | ucr filter > mapping.py", but then with the final mapping.