krbtpolicy plugin: Code cleanup

- Use the new plugin registration API
  See: http://www.freeipa.org/page/Coding_Best_Practices#Decorator-based_plugin_registration

- Remove the star import from baseldap
  Part of the work for: https://fedorahosted.org/freeipa/ticket/2653

Reviewed-By: Rob Crittenden <rcritten@redhat.com>
This commit is contained in:
Petr Viktorin 2014-05-29 15:39:26 +02:00
parent 16092c3907
commit b22bdfbb02

View File

@ -17,10 +17,12 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from ipalib import api from ipalib import api, errors, output, _
from ipalib import Int, Str from ipalib import Int, Str
from ipalib.plugins.baseldap import * from ipalib.plugins import baseldap
from ipalib import _ from ipalib.plugins.baseldap import entry_to_dict, pkey_to_value
from ipalib.plugable import Registry
from ipapython.dn import DN
__doc__ = _(""" __doc__ = _("""
Kerberos ticket policy Kerberos ticket policy
@ -60,6 +62,8 @@ EXAMPLES:
ipa krbtpolicy-mod admin --maxlife=3600 ipa krbtpolicy-mod admin --maxlife=3600
""") """)
register = Registry()
# FIXME: load this from a config file? # FIXME: load this from a config file?
_default_values = { _default_values = {
'krbmaxticketlife': 86400, 'krbmaxticketlife': 86400,
@ -67,7 +71,8 @@ _default_values = {
} }
class krbtpolicy(LDAPObject): @register()
class krbtpolicy(baseldap.LDAPObject):
""" """
Kerberos Ticket Policy object Kerberos Ticket Policy object
""" """
@ -141,10 +146,9 @@ class krbtpolicy(LDAPObject):
return self.api.Object.user.get_dn(*keys, **kwargs) return self.api.Object.user.get_dn(*keys, **kwargs)
return DN(self.container_dn, api.env.basedn) return DN(self.container_dn, api.env.basedn)
api.register(krbtpolicy)
@register()
class krbtpolicy_mod(LDAPUpdate): class krbtpolicy_mod(baseldap.LDAPUpdate):
__doc__ = _('Modify Kerberos ticket policy.') __doc__ = _('Modify Kerberos ticket policy.')
def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options): def pre_callback(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):
@ -155,10 +159,9 @@ class krbtpolicy_mod(LDAPUpdate):
options['all'] = False options['all'] = False
return dn return dn
api.register(krbtpolicy_mod)
@register()
class krbtpolicy_show(LDAPRetrieve): class krbtpolicy_show(baseldap.LDAPRetrieve):
__doc__ = _('Display the current Kerberos ticket policy.') __doc__ = _('Display the current Kerberos ticket policy.')
def pre_callback(self, ldap, dn, attrs_list, *keys, **options): def pre_callback(self, ldap, dn, attrs_list, *keys, **options):
@ -180,10 +183,9 @@ class krbtpolicy_show(LDAPRetrieve):
entry_attrs.setdefault(a, res['result'][a]) entry_attrs.setdefault(a, res['result'][a])
return dn return dn
api.register(krbtpolicy_show)
@register()
class krbtpolicy_reset(LDAPQuery): class krbtpolicy_reset(baseldap.LDAPQuery):
__doc__ = _('Reset Kerberos ticket policy to the default values.') __doc__ = _('Reset Kerberos ticket policy to the default values.')
has_output = output.standard_entry has_output = output.standard_entry
@ -217,5 +219,3 @@ class krbtpolicy_reset(LDAPQuery):
entry_attrs = entry_to_dict(entry_attrs, **options) entry_attrs = entry_to_dict(entry_attrs, **options)
return dict(result=entry_attrs, value=pkey_to_value(keys[-1], options)) return dict(result=entry_attrs, value=pkey_to_value(keys[-1], options))
api.register(krbtpolicy_reset)