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-search - Perform object search in Latmos::Accounts base |
---|
12 | |
---|
13 | =head1 SYNOPSIS |
---|
14 | |
---|
15 | la-search [options] filter [filter2 [...]] |
---|
16 | |
---|
17 | =head1 OPTIONS |
---|
18 | |
---|
19 | =over 4 |
---|
20 | |
---|
21 | =item --config configdir |
---|
22 | |
---|
23 | Use this configuration directory instead default |
---|
24 | |
---|
25 | =item --base basename |
---|
26 | |
---|
27 | Perform search in this specific base instead default |
---|
28 | |
---|
29 | =item --with-unexp |
---|
30 | |
---|
31 | Take into account all objects (even non propagated ones, with attribute |
---|
32 | 'exported'=0) (default) |
---|
33 | |
---|
34 | =item --wo-unexp |
---|
35 | |
---|
36 | Take into account only propagated objects (attribute 'exported'=1) |
---|
37 | |
---|
38 | =item --fmt format |
---|
39 | |
---|
40 | Specify a format of output. |
---|
41 | |
---|
42 | The "format" string may query tags in form: |
---|
43 | |
---|
44 | %{ATTRIBUTE:printflike} |
---|
45 | |
---|
46 | Where ATTRIBUTE is the name of an attribute and the optional |
---|
47 | C<:printflike> is a printf like string to print the attribute content |
---|
48 | (without the C<%>). |
---|
49 | |
---|
50 | Examples for users: |
---|
51 | |
---|
52 | --fmt "Name %{sn}, First Name %{givenName}\n" |
---|
53 | |
---|
54 | --fmt "Name %{sn:20s}, First Name %{givenName}\n" |
---|
55 | |
---|
56 | =item FILTER |
---|
57 | |
---|
58 | Filter are in form "[ATTRIBUTE][OPERATOR][VALUE]" |
---|
59 | |
---|
60 | where attribute is a supported attribute. |
---|
61 | |
---|
62 | OPERATOR can be: |
---|
63 | |
---|
64 | =over 4 |
---|
65 | |
---|
66 | =item C<=> |
---|
67 | |
---|
68 | Search object having attribute strictely equal to VALUE. If VALUE is C<*> match |
---|
69 | any non empty value. |
---|
70 | |
---|
71 | =item C<~> |
---|
72 | |
---|
73 | Search object having attribute containing VALUE. |
---|
74 | |
---|
75 | =back |
---|
76 | |
---|
77 | =back |
---|
78 | |
---|
79 | =cut |
---|
80 | |
---|
81 | GetOptions( |
---|
82 | 'c|config=s' => \my $config, |
---|
83 | 'b|base=s' => \my $base, |
---|
84 | 'o|object=s' => \my $otype, |
---|
85 | 'fmt=s' => \my $fmt, |
---|
86 | 'no-unexp|wo-unexp' => \my $nounexp, |
---|
87 | 'with-unexp' => \my $unexp, |
---|
88 | 'help' => sub { pod2usage(0) }, |
---|
89 | ) or pod2usage(); |
---|
90 | |
---|
91 | $otype ||= 'user'; |
---|
92 | |
---|
93 | my $LA = LATMOS::Accounts->new($config, noacl => 1); |
---|
94 | my $labase = $LA->base($base); |
---|
95 | $labase && $labase->load or die "Cannot load base"; |
---|
96 | |
---|
97 | $labase->unexported($nounexp ? 0 : 1); |
---|
98 | |
---|
99 | my @result = $labase->search_objects($otype, @ARGV); |
---|
100 | foreach (@result) { |
---|
101 | if ($fmt) { |
---|
102 | my $o = $labase->get_object($otype, $_) or next; |
---|
103 | print $o->queryformat($fmt); |
---|
104 | } else { |
---|
105 | print "$_\n"; |
---|
106 | } |
---|
107 | } |
---|
108 | |
---|
109 | STDOUT->autoflush(1); |
---|
110 | warn "\n" . scalar(@result) . " results\n"; |
---|
111 | exit(0); |
---|