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 | |
---|
15 | la-delete [options] obj_id |
---|
16 | |
---|
17 | =cut |
---|
18 | |
---|
19 | GetOptions( |
---|
20 | 'c|config=s' => \my $config, |
---|
21 | 'b|base=s' => \my $base, |
---|
22 | 'o|object=s' => \my $otype, |
---|
23 | 'force' => \my $force, |
---|
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 configdir |
---|
34 | |
---|
35 | Use this configuration directory instead of the default one. |
---|
36 | |
---|
37 | =item -b|--base basename |
---|
38 | |
---|
39 | Query this specific base instead of the default one. |
---|
40 | |
---|
41 | =item -o|object object_type |
---|
42 | |
---|
43 | Query will be performed on this object. Default is the 'User' object. |
---|
44 | |
---|
45 | =item --force |
---|
46 | |
---|
47 | Do not ask confirmation before deleting |
---|
48 | |
---|
49 | =back |
---|
50 | |
---|
51 | =cut |
---|
52 | |
---|
53 | if (!$ARGV[0]) {warn "You must specify 'obj_id', aborting\n"; pod2usage(); } |
---|
54 | |
---|
55 | my $LA = LATMOS::Accounts->new($config, noacl => 1); |
---|
56 | my $labase = $LA->base($base); |
---|
57 | $labase && $labase->load or die "Cannot load base"; |
---|
58 | $labase->wexported(1); |
---|
59 | |
---|
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 | |
---|
76 | if ($labase->delete_object($otype, $ARGV[0])) { |
---|
77 | $labase->commit; |
---|
78 | print "$otype/$ARGV[0] succefully deleted\n"; |
---|
79 | $LA->call_batch_sync; |
---|
80 | } else { |
---|
81 | warn "Cannot delete $otype/$ARGV[0]\n"; |
---|
82 | exit(1); |
---|
83 | } |
---|