1 | #!/usr/bin/perl |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | use LATMOS::Accounts; |
---|
6 | use Getopt::Long; |
---|
7 | use Pod::Usage; |
---|
8 | use LATMOS::Accounts::I18N; |
---|
9 | use LATMOS::Accounts::Cli; |
---|
10 | use LATMOS::Accounts::Cli::Context; |
---|
11 | |
---|
12 | =head1 NAME |
---|
13 | |
---|
14 | la-query - Tools to query base in LATMOS::Accounts system |
---|
15 | |
---|
16 | =head1 SYNOPSIS |
---|
17 | |
---|
18 | la-query [options] [obj_id] |
---|
19 | |
---|
20 | =head1 DESCRIPTION |
---|
21 | |
---|
22 | [obj_id] : If present, all set attributes (rw) will be displayed for that obj_id. |
---|
23 | If none is given, all obj_ids will be printed. |
---|
24 | |
---|
25 | For the default object_type (user), obj_id = login. |
---|
26 | |
---|
27 | Example : la-query lambda |
---|
28 | |
---|
29 | =cut |
---|
30 | |
---|
31 | Getopt::Long::Configure("pass_through"); |
---|
32 | GetOptions( |
---|
33 | 'c|config=s' => \my $config, |
---|
34 | 'b|base=s' => \my $base, |
---|
35 | 'o|object=s' => \my $otype, |
---|
36 | 'no-unexp|wo-unexp' => \my $nounexp, |
---|
37 | 'with-unexp' => \my $unexp, |
---|
38 | 'help' => sub { pod2usage(0) }, |
---|
39 | ) or pod2usage(); |
---|
40 | |
---|
41 | $otype ||= 'user'; |
---|
42 | |
---|
43 | =head1 OPTIONS |
---|
44 | |
---|
45 | =over 4 |
---|
46 | |
---|
47 | =item -c|--config configdir |
---|
48 | |
---|
49 | Use this configuration directory instead of the default one. |
---|
50 | |
---|
51 | =item -b|--base basename |
---|
52 | |
---|
53 | Query this specific base instead of the default one. |
---|
54 | |
---|
55 | =item -o|object object_type |
---|
56 | |
---|
57 | Query will be performed on this object. Default is the 'User' object. |
---|
58 | |
---|
59 | =item --with-unexp |
---|
60 | |
---|
61 | Take into account all objects (even non propagated ones, with attribute |
---|
62 | 'exported'=0) (default) |
---|
63 | |
---|
64 | =item --wo-unexp |
---|
65 | |
---|
66 | Take into account only propagated objects (attribute 'exported'=1) |
---|
67 | |
---|
68 | =item -e|--empty |
---|
69 | |
---|
70 | (Only if obj_id is specified) Include also unset attributes. |
---|
71 | |
---|
72 | =item --ro |
---|
73 | |
---|
74 | (Only if obj_id is specified) Include also read-only attributes as comments. |
---|
75 | |
---|
76 | =item --recur |
---|
77 | |
---|
78 | Dump also all related objects |
---|
79 | |
---|
80 | =item --fmt format |
---|
81 | |
---|
82 | Specify a format of output. |
---|
83 | |
---|
84 | If NOT present and "obj_id" is specified, all non-empty writable attributes will be printed (modified by -e and -ro). |
---|
85 | If NOT present and "obj_id" is NOT specified, only the list of "obj_id" will be printed. |
---|
86 | |
---|
87 | The "format" string may query tags in form: |
---|
88 | |
---|
89 | %{ATTRIBUTE:printflike} |
---|
90 | |
---|
91 | Where ATTRIBUTE is the name of an attribute and the optional |
---|
92 | C<:printflike> is a printf like string to print the attribute content (without |
---|
93 | the C<%>). |
---|
94 | |
---|
95 | Examples for users: |
---|
96 | |
---|
97 | --fmt "Name %{sn}, First Name %{givenName}\n" |
---|
98 | |
---|
99 | --fmt "Name %{sn:20s}, First Name %{givenName}\n" |
---|
100 | |
---|
101 | =item --filefmt format-file |
---|
102 | |
---|
103 | "format-file" is a text file with the same strings as "--fmt" option, WITHOUT quotes ("). |
---|
104 | |
---|
105 | It can be on more than one line, but all lines will be concatenated as one. |
---|
106 | Don't forget the "\n" if you really want seperate lines. |
---|
107 | |
---|
108 | Example of format-file: |
---|
109 | |
---|
110 | Name: %{sn}, First Name: %{givenName}\n |
---|
111 | Department : %{department}\n |
---|
112 | |
---|
113 | Note : --fmt and --filefmt can be used together, and will be concatenated (the "fmt" string first, then what is in the "format-file"). |
---|
114 | |
---|
115 | =back |
---|
116 | |
---|
117 | =cut |
---|
118 | |
---|
119 | my $LA = LATMOS::Accounts->new($config, noacl => 1); |
---|
120 | my $labase = $LA->base($base); |
---|
121 | $labase && $labase->load or die l("Cannot load base %s\n", $base); |
---|
122 | |
---|
123 | $labase->unexported($nounexp ? 0 : 1); |
---|
124 | |
---|
125 | my $Env = LATMOS::Accounts::Cli->new( |
---|
126 | Context => LATMOS::Accounts::Cli::Context->new( |
---|
127 | base => $labase, |
---|
128 | ), |
---|
129 | ); |
---|
130 | |
---|
131 | if (@ARGV) { |
---|
132 | $Env->run('query', '-o', $otype, @ARGV); |
---|
133 | } else { |
---|
134 | $Env->run('ls', $otype); |
---|
135 | } |
---|