Ticket #50421: patch-rename-server-wallet-report.diff
File patch-rename-server-wallet-report.diff, 22.7 KB (added by akkornel (A. Karl Kornel), 8 years ago) |
---|
-
deleted file server/wallet-report
+ - 1 #!/usr/bin/perl2 #3 # Wallet server reporting interface.4 5 use 5.008;6 use strict;7 use warnings;8 9 use Wallet::Report;10 11 # The help output, sent in reply to the help command. Lists each supported12 # report command with a brief description of what it does.13 our $HELP = <<'EOH';14 Wallet reporting help:15 acls All ACLs16 acls duplicate ACLs that duplicate another17 acls empty All empty ACLs18 acls entry <scheme> <id> ACLs containing this entry (wildcarded)19 acls nesting <acl> ACLs containing this ACL as a nested entry20 acls unused ACLs that are not referenced by any object21 audit acls name ACLs failing the naming policy22 audit objects name Objects failing the naming policy23 objects All objects24 objects acl <acl> Objects granting permissions to that ACL25 objects flag <flag> Objects with that flag set26 objects history History of all objects27 objects host <hostname> All host-based objects for a specific host28 objects owner <owner> Objects owned by that owner29 objects type <type> Objects of that type30 objects unused Objects that have never been gotten31 objects unstored Objects that have never been stored32 owners <type> <name> All ACL entries owning matching objects33 schemes All configured ACL schemes34 types All configured wallet types35 EOH36 37 ##############################################################################38 # Implementation39 ##############################################################################40 41 # Parse and execute a command. We wrap this in a subroutine call for easier42 # testing.43 sub command {44 die "Usage: wallet-report <command> [<args> ...]\n" unless @_;45 my $report = Wallet::Report->new;46 47 # Parse command-line options and dispatch to the appropriate calls.48 my ($command, @args) = @_;49 if ($command eq 'acls') {50 die "too many arguments to acls\n" if @args > 3;51 my @acls = $report->acls (@args);52 if (!@acls and $report->error) {53 die $report->error, "\n";54 }55 if (@args && $args[0] eq 'duplicate') {56 for my $group (@acls) {57 print join (' ', @$group), "\n";58 }59 } else {60 for my $acl (sort { $$a[1] cmp $$b[1] } @acls) {61 print "$$acl[1] (ACL ID: $$acl[0])\n";62 }63 }64 } elsif ($command eq 'audit') {65 die "too many arguments to audit\n" if @args > 2;66 die "too few arguments to audit\n" if @args < 2;67 my @result = $report->audit (@args);68 if (!@result and $report->error) {69 die $report->error, "\n";70 }71 for my $item (@result) {72 if ($args[0] eq 'acls') {73 print "$$item[1] (ACL ID: $$item[0])\n";74 } else {75 print join (' ', @$item), "\n";76 }77 }78 } elsif ($command eq 'help') {79 print $HELP;80 } elsif ($command eq 'objects') {81 die "too many arguments to objects\n" if @args > 2;82 my @objects;83 if (@args && $args[0] eq 'history') {84 @objects = $report->objects_history (@args);85 } elsif (@args && $args[0] eq 'host') {86 @objects = $report->objects_hostname (@args);87 } else {88 @objects = $report->objects (@args);89 }90 if (!@objects and $report->error) {91 die $report->error, "\n";92 }93 for my $object (@objects) {94 print join (' ', @$object), "\n";95 }96 } elsif ($command eq 'owners') {97 die "too many arguments to owners\n" if @args > 2;98 die "too few arguments to owners\n" if @args < 2;99 my @entries = $report->owners (@args);100 if (!@entries and $report->error) {101 die $report->error, "\n";102 }103 for my $entry (@entries) {104 print join (' ', @$entry), "\n";105 }106 } elsif ($command eq 'schemes') {107 die "too many arguments to schemes\n" if @args > 0;108 my @schemes = $report->acl_schemes;109 for my $entry (@schemes) {110 print join (' ', @$entry), "\n";111 }112 113 } elsif ($command eq 'types') {114 die "too many arguments to types\n" if @args > 0;115 my @types = $report->types;116 for my $entry (@types) {117 print join (' ', @$entry), "\n";118 }119 120 } else {121 die "unknown command $command\n";122 }123 }124 command (@ARGV);125 __END__126 127 ##############################################################################128 # Documentation129 ##############################################################################130 131 =head1 NAME132 133 wallet-report - Wallet server reporting interface134 135 =for stopwords136 metadata ACL hostname backend acl acls wildcard SQL Allbery remctl137 MERCHANTABILITY NONINFRINGEMENT sublicense unstored138 139 =head1 SYNOPSIS140 141 B<wallet-report> I<type> [I<args> ...]142 143 =head1 DESCRIPTION144 145 B<wallet-report> provides a command-line interface for running reports on146 the wallet database. It is intended to be run on the wallet server as a147 user with access to the wallet database and configuration, but can also be148 made available via remctl to users who should have reporting privileges.149 150 This program is a fairly thin wrapper around Wallet::Report that151 translates command strings into method calls and returns the results.152 153 =head1 OPTIONS154 155 B<wallet-report> takes no traditional options.156 157 =head1 COMMANDS158 159 =over 4160 161 =item acls162 163 =item acls duplicate164 165 =item acls empty166 167 =item acls entry <scheme> <identifier>168 169 =item acls unused170 171 Returns a list of ACLs in the database. Except for the C<duplicate>172 report, ACLs will be listed in the form:173 174 <name> (ACL ID: <id>)175 176 where <name> is the human-readable name and <id> is the numeric ID. The177 numeric ID is what's used internally by the wallet system. There will be178 one line per ACL.179 180 For the C<duplicate> report, the output will instead be one duplicate set181 per line. This will be a set of ACLs that all have the same entries.182 Only the names will be given, separated by spaces.183 184 If no search type is given, all the ACLs in the database will be returned.185 If a search type (and possible search arguments) are given, then the ACLs186 will be limited to those that match the search.187 188 The currently supported ACL search types are:189 190 =over 4191 192 =item acls duplicate193 194 Returns all sets of ACLs that are duplicates, meaning that they contain195 exactly the same entries. Each line will be the names of the ACLs in a196 set of duplicates, separated by spaces.197 198 =item acls empty199 200 Returns all ACLs which have no entries, generally so that abandoned ACLs201 can be destroyed.202 203 =item acls entry <scheme> <identifier>204 205 Returns all ACLs containing an entry with given scheme and identifier.206 The scheme must be an exact match, but the <identifier> string will match207 any identifier containing that string.208 209 =item acls nested <acl>210 211 Returns all ACLs that contain this ACL as a nested entry.212 213 =item acls unused214 215 Returns all ACLs that are not referenced by any of the objects in the216 wallet database, either as an owner or on one of the more specific ACLs.217 218 =back219 220 =item audit acls name221 222 =item audit objects name223 224 Returns all ACLs or objects that violate the current site naming policy.225 Objects will be listed in the form:226 227 <type> <name>228 229 and ACLs in the form:230 231 <name> (ACL ID: <id>)232 233 where <name> is the human-readable name and <id> is the numeric ID. The234 numeric ID is what's used internally by the wallet system. There will be235 one line per object or ACL.236 237 =item help238 239 Displays a summary of all available commands.240 241 =item objects242 243 =item objects acl <acl>244 245 =item objects flag <flag>246 247 =item objects owner <owner>248 249 =item objects type <type>250 251 =item objects unused252 253 =item objects unstored254 255 Returns a list of objects in the database. Objects will be listed in the256 form:257 258 <type> <name>259 260 There will be one line per object.261 262 If no search type is given, all objects in the database will be returned.263 If a search type (and possible search arguments) are given, the objects264 will be limited to those that match the search.265 266 The currently supported object search types are:267 268 =over 4269 270 =item objects acl <acl>271 272 Returns all objects for which the given ACL name or ID has any273 permissions. This includes those objects owned by the ACL as well as274 those where that ACL has any other, more limited permissions.275 276 =item objects flag <flag>277 278 Returns all objects which have the given flag set.279 280 =item objects host <hostname>281 282 Returns all objects that belong to the given host. This requires adding283 local configuration to identify objects that belong to a given host. See284 L<Wallet::Config/"OBJECT HOST-BASED NAMES"> for more information.285 286 =item objects owner <acl>287 288 Returns all objects owned by the given ACL name or ID.289 290 =item objects type <type>291 292 Returns all objects of the given type.293 294 =item objects unused295 296 Returns all objects that have never been downloaded (have never been the297 target of a get command).298 299 =back300 301 =item owners <type-pattern> <name-pattern>302 303 Returns a list of all ACL entries in owner ACLs for all objects matching304 both <type-pattern> and <name-pattern>. These can be the type or name of305 objects or they can be patterns using C<%> as the wildcard character306 following the normal rules of SQL patterns.307 308 The output will be one line per ACL line in the form:309 310 <scheme> <identifier>311 312 with duplicates suppressed.313 314 =item schemes315 316 Returns a list of all registered ACL schemes.317 318 =item types319 320 Returns a list of all registered object types.321 322 =back323 324 =head1 AUTHOR325 326 Russ Allbery <eagle@eyrie.org>327 328 =head1 COPYRIGHT AND LICENSE329 330 Copyright 2016 Russ Allbery <eagle@eyrie.org>331 332 Copyright 2008, 2009, 2010, 2013, 2015 The Board of Trustees of the Leland333 Stanford Junior University334 335 Permission is hereby granted, free of charge, to any person obtaining a336 copy of this software and associated documentation files (the "Software"),337 to deal in the Software without restriction, including without limitation338 the rights to use, copy, modify, merge, publish, distribute, sublicense,339 and/or sell copies of the Software, and to permit persons to whom the340 Software is furnished to do so, subject to the following conditions:341 342 The above copyright notice and this permission notice shall be included in343 all copies or substantial portions of the Software.344 345 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR346 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,347 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL348 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER349 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING350 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER351 DEALINGS IN THE SOFTWARE.352 353 =head1 SEE ALSO354 355 Wallet::Config(3), Wallet::Report(3), wallet-backend(8)356 357 This program is part of the wallet system. The current version is358 available from L<http://www.eyrie.org/~eagle/software/wallet/>.359 360 =cut -
new file server/wallet-report.in
- + 1 #!@PERL@ 2 # 3 # Wallet server reporting interface. 4 5 use 5.008; 6 use strict; 7 use warnings; 8 9 use Wallet::Report; 10 11 # The help output, sent in reply to the help command. Lists each supported 12 # report command with a brief description of what it does. 13 our $HELP = <<'EOH'; 14 Wallet reporting help: 15 acls All ACLs 16 acls duplicate ACLs that duplicate another 17 acls empty All empty ACLs 18 acls entry <scheme> <id> ACLs containing this entry (wildcarded) 19 acls nesting <acl> ACLs containing this ACL as a nested entry 20 acls unused ACLs that are not referenced by any object 21 audit acls name ACLs failing the naming policy 22 audit objects name Objects failing the naming policy 23 objects All objects 24 objects acl <acl> Objects granting permissions to that ACL 25 objects flag <flag> Objects with that flag set 26 objects history History of all objects 27 objects host <hostname> All host-based objects for a specific host 28 objects owner <owner> Objects owned by that owner 29 objects type <type> Objects of that type 30 objects unused Objects that have never been gotten 31 objects unstored Objects that have never been stored 32 owners <type> <name> All ACL entries owning matching objects 33 schemes All configured ACL schemes 34 types All configured wallet types 35 EOH 36 37 ############################################################################## 38 # Implementation 39 ############################################################################## 40 41 # Parse and execute a command. We wrap this in a subroutine call for easier 42 # testing. 43 sub command { 44 die "Usage: wallet-report <command> [<args> ...]\n" unless @_; 45 my $report = Wallet::Report->new; 46 47 # Parse command-line options and dispatch to the appropriate calls. 48 my ($command, @args) = @_; 49 if ($command eq 'acls') { 50 die "too many arguments to acls\n" if @args > 3; 51 my @acls = $report->acls (@args); 52 if (!@acls and $report->error) { 53 die $report->error, "\n"; 54 } 55 if (@args && $args[0] eq 'duplicate') { 56 for my $group (@acls) { 57 print join (' ', @$group), "\n"; 58 } 59 } else { 60 for my $acl (sort { $$a[1] cmp $$b[1] } @acls) { 61 print "$$acl[1] (ACL ID: $$acl[0])\n"; 62 } 63 } 64 } elsif ($command eq 'audit') { 65 die "too many arguments to audit\n" if @args > 2; 66 die "too few arguments to audit\n" if @args < 2; 67 my @result = $report->audit (@args); 68 if (!@result and $report->error) { 69 die $report->error, "\n"; 70 } 71 for my $item (@result) { 72 if ($args[0] eq 'acls') { 73 print "$$item[1] (ACL ID: $$item[0])\n"; 74 } else { 75 print join (' ', @$item), "\n"; 76 } 77 } 78 } elsif ($command eq 'help') { 79 print $HELP; 80 } elsif ($command eq 'objects') { 81 die "too many arguments to objects\n" if @args > 2; 82 my @objects; 83 if (@args && $args[0] eq 'history') { 84 @objects = $report->objects_history (@args); 85 } elsif (@args && $args[0] eq 'host') { 86 @objects = $report->objects_hostname (@args); 87 } else { 88 @objects = $report->objects (@args); 89 } 90 if (!@objects and $report->error) { 91 die $report->error, "\n"; 92 } 93 for my $object (@objects) { 94 print join (' ', @$object), "\n"; 95 } 96 } elsif ($command eq 'owners') { 97 die "too many arguments to owners\n" if @args > 2; 98 die "too few arguments to owners\n" if @args < 2; 99 my @entries = $report->owners (@args); 100 if (!@entries and $report->error) { 101 die $report->error, "\n"; 102 } 103 for my $entry (@entries) { 104 print join (' ', @$entry), "\n"; 105 } 106 } elsif ($command eq 'schemes') { 107 die "too many arguments to schemes\n" if @args > 0; 108 my @schemes = $report->acl_schemes; 109 for my $entry (@schemes) { 110 print join (' ', @$entry), "\n"; 111 } 112 113 } elsif ($command eq 'types') { 114 die "too many arguments to types\n" if @args > 0; 115 my @types = $report->types; 116 for my $entry (@types) { 117 print join (' ', @$entry), "\n"; 118 } 119 120 } else { 121 die "unknown command $command\n"; 122 } 123 } 124 command (@ARGV); 125 __END__ 126 127 ############################################################################## 128 # Documentation 129 ############################################################################## 130 131 =head1 NAME 132 133 wallet-report - Wallet server reporting interface 134 135 =for stopwords 136 metadata ACL hostname backend acl acls wildcard SQL Allbery remctl 137 MERCHANTABILITY NONINFRINGEMENT sublicense unstored 138 139 =head1 SYNOPSIS 140 141 B<wallet-report> I<type> [I<args> ...] 142 143 =head1 DESCRIPTION 144 145 B<wallet-report> provides a command-line interface for running reports on 146 the wallet database. It is intended to be run on the wallet server as a 147 user with access to the wallet database and configuration, but can also be 148 made available via remctl to users who should have reporting privileges. 149 150 This program is a fairly thin wrapper around Wallet::Report that 151 translates command strings into method calls and returns the results. 152 153 =head1 OPTIONS 154 155 B<wallet-report> takes no traditional options. 156 157 =head1 COMMANDS 158 159 =over 4 160 161 =item acls 162 163 =item acls duplicate 164 165 =item acls empty 166 167 =item acls entry <scheme> <identifier> 168 169 =item acls unused 170 171 Returns a list of ACLs in the database. Except for the C<duplicate> 172 report, ACLs will be listed in the form: 173 174 <name> (ACL ID: <id>) 175 176 where <name> is the human-readable name and <id> is the numeric ID. The 177 numeric ID is what's used internally by the wallet system. There will be 178 one line per ACL. 179 180 For the C<duplicate> report, the output will instead be one duplicate set 181 per line. This will be a set of ACLs that all have the same entries. 182 Only the names will be given, separated by spaces. 183 184 If no search type is given, all the ACLs in the database will be returned. 185 If a search type (and possible search arguments) are given, then the ACLs 186 will be limited to those that match the search. 187 188 The currently supported ACL search types are: 189 190 =over 4 191 192 =item acls duplicate 193 194 Returns all sets of ACLs that are duplicates, meaning that they contain 195 exactly the same entries. Each line will be the names of the ACLs in a 196 set of duplicates, separated by spaces. 197 198 =item acls empty 199 200 Returns all ACLs which have no entries, generally so that abandoned ACLs 201 can be destroyed. 202 203 =item acls entry <scheme> <identifier> 204 205 Returns all ACLs containing an entry with given scheme and identifier. 206 The scheme must be an exact match, but the <identifier> string will match 207 any identifier containing that string. 208 209 =item acls nested <acl> 210 211 Returns all ACLs that contain this ACL as a nested entry. 212 213 =item acls unused 214 215 Returns all ACLs that are not referenced by any of the objects in the 216 wallet database, either as an owner or on one of the more specific ACLs. 217 218 =back 219 220 =item audit acls name 221 222 =item audit objects name 223 224 Returns all ACLs or objects that violate the current site naming policy. 225 Objects will be listed in the form: 226 227 <type> <name> 228 229 and ACLs in the form: 230 231 <name> (ACL ID: <id>) 232 233 where <name> is the human-readable name and <id> is the numeric ID. The 234 numeric ID is what's used internally by the wallet system. There will be 235 one line per object or ACL. 236 237 =item help 238 239 Displays a summary of all available commands. 240 241 =item objects 242 243 =item objects acl <acl> 244 245 =item objects flag <flag> 246 247 =item objects owner <owner> 248 249 =item objects type <type> 250 251 =item objects unused 252 253 =item objects unstored 254 255 Returns a list of objects in the database. Objects will be listed in the 256 form: 257 258 <type> <name> 259 260 There will be one line per object. 261 262 If no search type is given, all objects in the database will be returned. 263 If a search type (and possible search arguments) are given, the objects 264 will be limited to those that match the search. 265 266 The currently supported object search types are: 267 268 =over 4 269 270 =item objects acl <acl> 271 272 Returns all objects for which the given ACL name or ID has any 273 permissions. This includes those objects owned by the ACL as well as 274 those where that ACL has any other, more limited permissions. 275 276 =item objects flag <flag> 277 278 Returns all objects which have the given flag set. 279 280 =item objects host <hostname> 281 282 Returns all objects that belong to the given host. This requires adding 283 local configuration to identify objects that belong to a given host. See 284 L<Wallet::Config/"OBJECT HOST-BASED NAMES"> for more information. 285 286 =item objects owner <acl> 287 288 Returns all objects owned by the given ACL name or ID. 289 290 =item objects type <type> 291 292 Returns all objects of the given type. 293 294 =item objects unused 295 296 Returns all objects that have never been downloaded (have never been the 297 target of a get command). 298 299 =back 300 301 =item owners <type-pattern> <name-pattern> 302 303 Returns a list of all ACL entries in owner ACLs for all objects matching 304 both <type-pattern> and <name-pattern>. These can be the type or name of 305 objects or they can be patterns using C<%> as the wildcard character 306 following the normal rules of SQL patterns. 307 308 The output will be one line per ACL line in the form: 309 310 <scheme> <identifier> 311 312 with duplicates suppressed. 313 314 =item schemes 315 316 Returns a list of all registered ACL schemes. 317 318 =item types 319 320 Returns a list of all registered object types. 321 322 =back 323 324 =head1 AUTHOR 325 326 Russ Allbery <eagle@eyrie.org> 327 328 =head1 COPYRIGHT AND LICENSE 329 330 Copyright 2016 Russ Allbery <eagle@eyrie.org> 331 332 Copyright 2008, 2009, 2010, 2013, 2015 The Board of Trustees of the Leland 333 Stanford Junior University 334 335 Permission is hereby granted, free of charge, to any person obtaining a 336 copy of this software and associated documentation files (the "Software"), 337 to deal in the Software without restriction, including without limitation 338 the rights to use, copy, modify, merge, publish, distribute, sublicense, 339 and/or sell copies of the Software, and to permit persons to whom the 340 Software is furnished to do so, subject to the following conditions: 341 342 The above copyright notice and this permission notice shall be included in 343 all copies or substantial portions of the Software. 344 345 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 346 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 347 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 348 THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 349 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 350 FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 351 DEALINGS IN THE SOFTWARE. 352 353 =head1 SEE ALSO 354 355 Wallet::Config(3), Wallet::Report(3), wallet-backend(8) 356 357 This program is part of the wallet system. The current version is 358 available from L<http://www.eyrie.org/~eagle/software/wallet/>. 359 360 =cut