source: trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Task/Unexportexpired.pm @ 1880

Last change on this file since 1880 was 1880, checked in by nanardon, 7 years ago

Fix "Slow down unexport user process"

This reverts commit 14fbb14e8e0c5beb898566b58b05d4f1f1721b8b.

  • Property svn:executable set to *
File size: 2.0 KB
Line 
1package LATMOS::Accounts::Task::Unexportexpired;
2
3use strict;
4use warnings;
5use base qw(LATMOS::Accounts::Task);
6use LATMOS::Accounts;
7use LATMOS::Accounts::Log;
8use LATMOS::Accounts::Utils;
9use DateTime;
10
11=head1 NAME
12
13LATMOS::Accounts::Task::Refreshexpired - Task to disable expired users
14
15=head1 DESCRIPTION
16
17Some base doesn't handle accounts expiration. One way to do it is to synchronize
18user with value denying login (wrong UNIX shell, password entry set to false,
19...).
20
21For performance issue, objects are not written at each synchronisation, only
22when they changes.
23
24This module find expired user and refresh modification time to ensure
25propagation to other database.
26
27=cut
28
29# Every 10 minutes
30sub runDelay { 20 * 60 }
31
32sub init {
33    my ($self) = @_;
34    my $LA = LATMOS::Accounts->new($self->{config}, noacl => 1);
35    my $labase = $self->{base} ? $LA->base($self->{base}) : $LA->base;
36    $labase && $labase->load or die "Cannot load base";
37
38    $self->{_la} = $LA;
39    $self->{_base} = $labase;
40
41    1;
42}
43
44sub run {
45    my ($self) = @_;
46
47    my $now = DateTime->now();
48    my $nowtext = $now->iso8601();
49
50    foreach my $otype (qw(Aliases Nethost Address)) {
51
52        foreach my $name (
53            $self->{_base}->search_objects($otype, 'exported=t', "expire<$nowtext")) {
54            my $obj = $self->{_base}->get_object($otype, $name);
55            la_log(LA_NOTICE, "Unexport %s/%s object due to expire (%s)", $otype, $name, $obj->_get_attributes('expire') ||'');
56            $obj->_set_c_fields(unexported => 1);
57            $self->{_base}->commit;
58        }
59
60    }
61
62    1;
63}
64
651;
66
67__END__
68
69=head1 SEE ALSO
70
71L<LATMOS::Accounts>, L<LATMOS::Accounts::Task>
72
73=head1 AUTHOR
74
75Olivier Thauvin, E<lt>olivier.thauvin@latmos.ipsl.frE<gt>
76
77=head1 COPYRIGHT AND LICENSE
78
79Copyright (C) 2012 CNRS SA/CETP/LATMOS
80
81This library is free software; you can redistribute it and/or modify
82it under the same terms as Perl itself, either Perl version 5.10.0 or,
83at your option, any later version of Perl 5 you may have available.
84
85=cut
86
Note: See TracBrowser for help on using the repository browser.