From 493a66449307d703bf53eb3a239d645126b63e09 Mon Sep 17 00:00:00 2001 From: William Brown Date: Feb 03 2020 00:47:11 +0000 Subject: Ticket 50787 - fix implementation of attr unique Bug Description: The implementation of attribute unique relies on a "plugin per config" which is different to most other handlings. This creates an exception case to the standard plugin framework in lib389 that was not correctly handled in the CLI. Fix Description: Fix the cli to have the correct customised variants of the commands to support this plugin's behaviour. > dsconf localhost plugin attr-uniq status uid-test Plugin 'uid-test' is disabled > dsconf localhost plugin attr-uniq enable uid-test Successfully enabled the cn=uid-test,cn=plugins,cn=config > dsconf localhost plugin attr-uniq enable uid-test Plugin 'uid-test' already enabled > dsconf localhost plugin attr-uniq status uid-test Plugin 'uid-test' is enabled > dsconf localhost plugin attr-uniq disable uid-test Successfully disabled the cn=uid-test,cn=plugins,cn=config > dsconf localhost plugin attr-uniq disable uid-test Plugin 'uid-test' already disabled https://pagure.io/389-ds-base/issue/50787 Author: William Brown Review by: ??? --- diff --git a/src/lib389/lib389/cli_conf/plugins/attruniq.py b/src/lib389/lib389/cli_conf/plugins/attruniq.py index fee4137..804dc7d 100644 --- a/src/lib389/lib389/cli_conf/plugins/attruniq.py +++ b/src/lib389/lib389/cli_conf/plugins/attruniq.py @@ -78,6 +78,38 @@ def attruniq_del(inst, basedn, log, args): log.info("Successfully deleted the %s", plugin.dn) +def attruniq_enable(inst, basedn, log, args): + log = log.getChild('attruniq_enable') + plugins = AttributeUniquenessPlugins(inst) + plugin = plugins.get(args.NAME) + if plugin.status(): + log.info("Plugin '%s' already enabled" % plugin.rdn) + else: + plugin.enable() + log.info("Successfully enabled the %s", plugin.dn) + + +def attruniq_disable(inst, basedn, log, args): + log = log.getChild('attruniq_disable') + plugins = AttributeUniquenessPlugins(inst) + plugin = plugins.get(args.NAME) + if not plugin.status(): + log.info("Plugin '%s' already disabled" % plugin.rdn) + else: + plugin.disable() + log.info("Successfully disabled the %s", plugin.dn) + + +def attruniq_status(inst, basedn, log, args): + log = log.getChild('attruniq_status') + plugins = AttributeUniquenessPlugins(inst) + plugin = plugins.get(args.NAME) + if plugin.status() is True: + log.info("Plugin '%s' is enabled" % plugin.rdn) + else: + log.info("Plugin '%s' is disabled" % plugin.rdn) + + def _add_parser_args(parser): parser.add_argument('NAME', help='Sets the name of the plug-in configuration record. (cn) You can use any string, ' 'but "attribute_name Attribute Uniqueness" is recommended.') @@ -104,7 +136,7 @@ def _add_parser_args(parser): def create_parser(subparsers): attruniq = subparsers.add_parser('attr-uniq', help='Manage and configure Attribute Uniqueness plugin') subcommands = attruniq.add_subparsers(help='action') - add_generic_plugin_parsers(subcommands, AttributeUniquenessPlugin) + # We can't use the add_generic_plugin_parsers as we need named sub instances. list = subcommands.add_parser('list', help='List available plugin configs') list.set_defaults(func=attruniq_list) @@ -127,12 +159,12 @@ def create_parser(subparsers): enable = subcommands.add_parser('enable', help='enable plugin') enable.add_argument('NAME', help='Sets the name of the plug-in configuration record') - enable.set_defaults(func=generic_enable) + enable.set_defaults(func=attruniq_enable) disable = subcommands.add_parser('disable', help='disable plugin') disable.add_argument('NAME', help='Sets the name of the plug-in configuration record') - disable.set_defaults(func=generic_disable) + disable.set_defaults(func=attruniq_disable) status = subcommands.add_parser('status', help='display plugin status') status.add_argument('NAME', help='Sets the name of the plug-in configuration record') - status.set_defaults(func=generic_status) + status.set_defaults(func=attruniq_status)