[531] | 1 | #!/usr/bin/perl |
---|
| 2 | |
---|
| 3 | use strict; |
---|
| 4 | use warnings; |
---|
| 5 | use LATMOS::Accounts; |
---|
| 6 | use Getopt::Long; |
---|
| 7 | use Pod::Usage; |
---|
| 8 | |
---|
| 9 | =head1 NAME |
---|
| 10 | |
---|
| 11 | la-delete - Tools to delete object in LATMOS-Accounts |
---|
| 12 | |
---|
| 13 | =head1 SYNOPSIS |
---|
| 14 | |
---|
[594] | 15 | la-delete [options] obj_id |
---|
[531] | 16 | |
---|
| 17 | =cut |
---|
| 18 | |
---|
| 19 | GetOptions( |
---|
| 20 | 'c|config=s' => \my $config, |
---|
| 21 | 'b|base=s' => \my $base, |
---|
| 22 | 'o|object=s' => \my $otype, |
---|
[685] | 23 | 'force' => \my $force, |
---|
[531] | 24 | 'help' => sub { pod2usage(0) }, |
---|
| 25 | ) or pod2usage(); |
---|
| 26 | |
---|
| 27 | $otype ||= 'user'; |
---|
| 28 | |
---|
| 29 | =head1 OPTIONS |
---|
| 30 | |
---|
| 31 | =over 4 |
---|
| 32 | |
---|
| 33 | =item -c|--config configfile |
---|
| 34 | |
---|
[594] | 35 | Use this configuration file instead of the default one. |
---|
[531] | 36 | |
---|
| 37 | =item -b|--base basename |
---|
| 38 | |
---|
[594] | 39 | Query this specific base instead of the default one. |
---|
[531] | 40 | |
---|
| 41 | =item -o|object object_type |
---|
| 42 | |
---|
[594] | 43 | Query will be performed on this object. Default is the 'User' object. |
---|
[531] | 44 | |
---|
[685] | 45 | =item --force |
---|
| 46 | |
---|
| 47 | Do not ask confirmation before deleting |
---|
| 48 | |
---|
[531] | 49 | =back |
---|
| 50 | |
---|
| 51 | =cut |
---|
| 52 | |
---|
[656] | 53 | if (!$ARGV[0]) {warn "You must specify 'obj_id', aborting\n"; pod2usage(); } |
---|
[655] | 54 | |
---|
[531] | 55 | my $LA = LATMOS::Accounts->new($config, noacl => 1); |
---|
| 56 | my $labase = $base ? $LA->base($base) : $LA->default_base; |
---|
| 57 | $labase && $labase->load or die "Cannot load base"; |
---|
[664] | 58 | $labase->wexported(1); |
---|
[531] | 59 | |
---|
[685] | 60 | if (!$labase->get_object($otype, $ARGV[0])) { |
---|
| 61 | die "Cannot find object $otype $ARGV[0]\n"; |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | if (!$force) { |
---|
| 65 | my $alea = int(rand(1000)); |
---|
| 66 | print "Deleting object is definitive !\n"; |
---|
| 67 | print "Are you sure you want to delete objet $otype $ARGV[0] ?\n"; |
---|
| 68 | print "To confirm please enter this number: $alea\n"; |
---|
| 69 | my $enter = <STDIN>; |
---|
| 70 | chomp($enter); |
---|
| 71 | if (!($enter =~ /^\d+$/ && $enter == $alea)) { |
---|
| 72 | die "Wonrg input, aborting\n"; |
---|
| 73 | } |
---|
| 74 | } |
---|
| 75 | |
---|
[531] | 76 | if ($labase->delete_object($otype, $ARGV[0])) { |
---|
[607] | 77 | $labase->commit; |
---|
[531] | 78 | print "$otype/$ARGV[0] succefully deleted\n"; |
---|
[602] | 79 | $LA->call_batch_sync; |
---|
[531] | 80 | } else { |
---|
| 81 | warn "Cannot delete $otype/$ARGV[0]\n"; |
---|
| 82 | exit(1); |
---|
| 83 | } |
---|