File: genaclperms.pl

package info (click to toggle)
libvirt 3.0.0-4%2Bdeb9u4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 221,536 kB
  • sloc: ansic: 536,027; xml: 118,597; sh: 9,608; makefile: 5,399; perl: 3,888; python: 3,838; ml: 468; sed: 16
file content (124 lines) | stat: -rwxr-xr-x 2,880 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/perl
#
# Copyright (C) 2013 Red Hat, Inc.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library.  If not, see
# <http://www.gnu.org/licenses/>.
#

use strict;
use warnings;

my @objects = (
    "CONNECT", "DOMAIN", "INTERFACE",
    "NETWORK","NODE_DEVICE", "NWFILTER",
     "SECRET", "STORAGE_POOL", "STORAGE_VOL",
    );

my %class;

foreach my $object (@objects) {
    my $class = lc $object;

    $class =~ s/(^\w|_\w)/uc $1/eg;
    $class =~ s/_//g;
    $class =~ s/Nwfilter/NWFilter/;
    $class = "vir" . $class . "Ptr";

    $class{$object} = $class;
}

my $objects = join ("|", @objects);

my %opts;
my $in_opts = 0;

my %perms;

while (<>) {
    if ($in_opts) {
        if (m,\*/,) {
            $in_opts = 0;
        } elsif (/\*\s*\@(\w+):\s*(.*?)\s*$/) {
            $opts{$1} = $2;
        }
    } elsif (m,/\*\*,) {
        $in_opts = 1;
    } elsif (/VIR_ACCESS_PERM_($objects)_((?:\w|_)+),/) {
        my $object = $1;
        my $perm = lc $2;
        next if $perm eq "last";

        $perm =~ s/_/-/g;

        $perms{$object} = {} unless exists $perms{$object};
        $perms{$object}->{$perm} = {
            desc => $opts{desc},
            message => $opts{message},
            anonymous => $opts{anonymous}
        };
        %opts = ();
    }
}

print <<EOF;
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <body>
EOF

foreach my $object (sort { $a cmp $b } keys %perms) {
    my $class = $class{$object};
    my $olink = lc "object_" . $object;
    print <<EOF;
<h3><a name="$olink">$class</a></h3>
<table class="acl">
  <thead>
    <tr>
      <th>Permission</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody>
EOF

    foreach my $perm (sort { $a cmp $b } keys %{$perms{$object}}) {
        my $description = $perms{$object}->{$perm}->{desc};

        die "missing description for $object.$perm" unless
            defined $description;

        my $plink = lc "perm_" . $object . "_" . $perm;
        $plink =~ s/-/_/g;

        print <<EOF;
    <tr>
      <td><a name="$plink">$perm</a></td>
      <td>$description</td>
    </tr>
EOF

    }

    print <<EOF;
  </tbody>
</table>
EOF
}

print <<EOF;
  </body>
</html>
EOF