source: trunk/LATMOS-Accounts/bin/la-sql-alias @ 1888

Last change on this file since 1888 was 1865, checked in by nanardon, 8 years ago

Merge branch

  • Property svn:executable set to *
File size: 1.9 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5use LATMOS::Accounts;
6use Getopt::Long;
7use Pod::Usage;
8
9=head1 NAME
10
11    la-sql-alias - Tools to create or edit object alias
12
13=head1 SYNOPSIS
14
15    la-sql-properties [options] obj_id
16
17=cut
18
19GetOptions(
20    'c|config=s' => \my $config,
21    'b|base=s'   => \my $base,
22    'o|object=s' => \my $otype,
23    'r|remove'   => \my $remove,
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
35Use this configuration directory instead of the default one.
36
37=item -b|--base basename
38
39Query this specific base instead of the default one.
40
41=item -o|object object_type
42
43Query will be performed on this object. Default is the 'User' object.
44
45=item -r|remove
46
47Remove the alias given in argument
48
49=back
50
51=cut
52
53my $LA = LATMOS::Accounts->new($config, noacl => 1);
54my $labase = $LA->base($base);
55$labase && $labase->load or die "Cannot load base";
56$labase->wexported(1);
57
58my ($name, $for) = @ARGV;
59
60if (!$name) {
61    foreach my $id ($labase->search_objects($otype, 'oalias=*')) {
62        my $isfor = '';
63        if (my $obj = $labase->GetAlias($otype, $id)) {
64            $isfor = $obj->get_attributes('oalias');
65        }
66        print "$id -> $isfor\n";
67    }
68    exit 0;
69}
70
71if ($remove) {
72    if($labase->RemoveAlias($otype, $name)) {
73        print "Alias $otype/$name removed\n";
74        exit(0);
75    } else {
76        die "Error while remove alias $otype/$name";
77    }
78}
79
80$for or do { pod2usage(1); };
81
82if (my $obj = $labase->GetAlias($otype, $name)) {
83    if ($obj->set_c_fields(oalias => $for)) {
84        $labase->commit;
85        print "Alias $name updated\n";
86    } else {
87        die "Alias $name unchanged\n";
88    }
89} else {
90    if ($labase->CreateAlias($otype, $name, $for)) {
91        $labase->commit;
92        print "Alias $name created\n";
93    } else {
94        die "Alias $name not created\n";
95    }
96}
97
Note: See TracBrowser for help on using the repository browser.