Changeset 1354 for trunk/LATMOS-Accounts


Ignore:
Timestamp:
06/24/15 15:36:23 (9 years ago)
Author:
nanardon
Message:

Add filtering option on object to sync to base

Location:
trunk/LATMOS-Accounts
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts.pm

    r1242 r1354  
    223223    } 
    224224 
    225     my $labfrom = $options{from} ? $self->base($options{from}) : $self->default_base; 
     225    my $labfrom = $options{from} ? $self->base($options{from}) : $self->base; 
    226226 
    227227    my @labto = 
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Synchro.pm

    r1206 r1354  
    274274 
    275275    my %desterror; 
    276     my %existings; 
    277276    my $updated = 0; 
    278277    foreach my $destbase ($self->to) { 
     
    281280            $destbase->is_supported_object($otype) or next; 
    282281 
    283             $existings{$otype} ||= { map { $_ => 1 } 
     282            my %existings; 
     283            my %filtering; 
     284 
     285            $existings{$otype} = { map { $_ => 1 } 
    284286                $self->from->list_objects($otype) }; 
    285287 
     288            # Is there a filter to apply: 
     289            my $filtername = 'filter.' . $destbase->label . '.' . $otype; 
     290            if (my $filter = $self->{options}->{$filtername}) { 
     291                la_log(LA_DEBUG, "Found %s param, using it: %s", $filtername, $filter); 
     292                $filtering{$otype} = { map { $_ => 1 } 
     293                    $self->from->search_objects($otype, $filter) }; 
     294            } else { 
     295                $filtering{$otype} = $existings{$otype}; 
     296            } 
     297 
     298 
    286299            # deleting non existing object in dest: 
     300            my $deletefiltered = 'deletefiltered.' . $destbase->label . '.' . $otype; 
    287301            foreach ($destbase->list_objects($otype)) { 
    288                 if(!$existings{$otype}{$_}) { 
    289                     if (my $res = $destbase->sync_object_from($self->from, 
    290                             $otype, $_, %options)) { 
    291                         la_log(LA_NOTICE, "%s::%s::%s => %s %s", 
    292                             $self->from->label, $otype, $_, $destbase->label, $res, 
    293                         ); 
    294                         if ($destbase->is_transactionnal) { 
    295                             $destbase->commit; 
    296                         } 
    297                         $updated = 1; 
    298                     } else { 
    299                         if ($destbase->is_transactionnal) { 
    300                             $destbase->rollback; 
    301                         } 
     302 
     303                if ($filtering{$otype}{$_}) { 
     304                    # the object must exists 
     305                    next; 
     306                } elsif ($existings{$otype}{$_}) { 
     307                    # object exists but is filtered 
     308                    if (!$self->{options}->{$deletefiltered}) { 
     309                        next; 
     310                    } 
     311                } 
     312 
     313                if (my $res = $destbase->sync_object_from($self->from, 
     314                        $otype, $_, %options)) { 
     315                    la_log(LA_NOTICE, "%s::%s::%s => %s %s", 
     316                        $self->from->label, $otype, $_, $destbase->label, $res, 
     317                    ); 
     318                    if ($destbase->is_transactionnal) { 
     319                        $destbase->commit; 
     320                    } 
     321                    $updated = 1; 
     322                } else { 
     323                    if ($destbase->is_transactionnal) { 
     324                        $destbase->rollback; 
    302325                    } 
    303326                } 
    304327            } 
    305328 
    306             @{$objlist{$otype}} = $self->from->list_objects_from_rev( 
     329            # Finding object to synchronize: 
     330            @{$objlist{$otype}} = grep { $filtering{$otype}{$_} } $self->from->list_objects_from_rev( 
    307331                $otype, 
    308332                $self->val($self->from->label, $destbase->label, 0), 
    309333            ); 
    310334        } 
     335 
     336        my %objectok; 
    311337        foreach my $pass (1, 0) { 
    312338            foreach my $otype ($destbase->ordered_objects) { 
    313339                exists($objlist{$otype}) or next; 
    314340                foreach (@{$objlist{$otype} || []}) { 
     341 
     342                    # If first synchro is not ok, don't retry to sync the object 
     343                    if ((!$pass) && (!$objectok{$otype}{$_})) { 
     344                        next; 
     345                    } 
     346 
    315347                    my $res = $destbase->sync_object_from($self->from, $otype, $_, 
    316348                        %options, firstpass => $pass); 
     
    325357                            } 
    326358                            $updated = 1; 
     359                            $objectok{$otype}{$_} = 1; 
    327360                        } 
    328361                    } else { 
     
    336369                        } 
    337370                    } 
    338  
    339371                } 
    340372            } 
  • trunk/LATMOS-Accounts/man/man5/latmos-accounts.ini.pod

    r1249 r1354  
    135135feature (SQL only at time) 
    136136 
     137=head3 filtering object propagation 
     138 
     139It is possible to filter the objects you want to propagate into peer base. 
     140 
     141The filter to apply must be set into the parameter named 
     142C<filter.BASENAME.OTYPE>, where C<BASENAME> is the name of the destination 
     143base and C<OTYPE> the object type to filter. 
     144 
     145For example to push into C<ldap> base only user being into group C<unix>: 
     146 
     147  filter.ldap.user = memberOf=unix 
     148 
     149=head3 Deleting filtered object 
     150 
     151By default filtered object will not be deleted to the destination base, neither 
     152touched. 
     153 
     154Setting option in form C<deletefiltered.BASENAME.OTYPE> to true will allow 
     155deletion. This option has effects only if filtering objects is enabled. 
     156 
    137157=head1 SEE ALSO 
    138158 
Note: See TracChangeset for help on using the changeset viewer.