class hbacrule_add_accesstime(LDAPQuery): """ Add an access time to an HBAC rule. """ takes_options = (AccessTime( 'accesstime', cli_name='time', label=_('Access time'), ), ) def execute(self, cn, **options): ldap = self.obj.backend dn = self.obj.get_dn(cn) entry_attrs = ldap.get_entry(dn, ['accesstime']) entry_attrs.setdefault('accesstime', []).append(options['accesstime']) try: ldap.update_entry(entry_attrs) except errors.EmptyModlist: pass except errors.NotFound: self.obj.handle_not_found(cn) return dict(result=True) def output_for_cli(self, textui, result, cn, **options): textui.print_name(self.name) textui.print_dashed('Added access time "%s" to HBAC rule "%s"' % (options['accesstime'], cn))
class hbacrule_remove_accesstime(LDAPQuery): """ Remove access time to HBAC rule. """ takes_options = (AccessTime( 'accesstime?', cli_name='time', label=_('Access time'), ), ) def execute(self, cn, **options): ldap = self.obj.backend dn = self.obj.get_dn(cn) entry_attrs = ldap.get_entry(dn, ['accesstime']) try: entry_attrs.setdefault('accesstime', []).remove(options['accesstime']) ldap.update_entry(entry_attrs) except (ValueError, errors.EmptyModlist): pass except errors.NotFound: raise self.obj.handle_not_found(cn) return dict(result=True)
class hbacrule_remove_accesstime(LDAPQuery): """ Remove access time to HBAC rule. """ takes_options = (AccessTime( 'accesstime?', cli_name='time', label=_('Access time'), ), ) def execute(self, cn, **options): ldap = self.obj.backend dn = self.obj.get_dn(cn) (dn, entry_attrs) = ldap.get_entry(dn, ['accesstime']) try: entry_attrs.setdefault('accesstime', []).remove(options['accesstime']) ldap.update_entry(dn, entry_attrs) except (ValueError, errors.EmptyModlist): pass except errors.NotFound: self.obj.handle_not_found(cn) return dict(result=True) def output_for_cli(self, textui, result, cn, **options): textui.print_name(self.name) textui.print_dashed('Removed access time "%s" from HBAC rule "%s"' % (options['accesstime'], cn))