line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::FreeIPA::API::Magic; |
2
|
|
|
|
|
|
|
$Net::FreeIPA::API::Magic::VERSION = '3.0.2'; |
3
|
8
|
|
|
8
|
|
65178
|
use strict; |
|
8
|
|
|
|
|
13
|
|
|
8
|
|
|
|
|
297
|
|
4
|
8
|
|
|
8
|
|
31
|
use warnings; |
|
8
|
|
|
|
|
10
|
|
|
8
|
|
|
|
|
195
|
|
5
|
|
|
|
|
|
|
|
6
|
8
|
|
|
8
|
|
27
|
use Types::Serialiser; # is used by JSON::XS |
|
8
|
|
|
|
|
8
|
|
|
8
|
|
|
|
|
164
|
|
7
|
8
|
|
|
8
|
|
30
|
use JSON::XS; |
|
8
|
|
|
|
|
9
|
|
|
8
|
|
|
|
|
411
|
|
8
|
|
|
|
|
|
|
|
9
|
8
|
|
|
8
|
|
16290
|
use Net::FreeIPA::API::Data; |
|
8
|
|
|
|
|
21
|
|
|
8
|
|
|
|
|
437
|
|
10
|
|
|
|
|
|
|
|
11
|
8
|
|
|
8
|
|
65
|
use Readonly; |
|
8
|
|
|
|
|
7
|
|
|
8
|
|
|
|
|
429
|
|
12
|
|
|
|
|
|
|
|
13
|
8
|
|
|
8
|
|
41
|
use base qw(Exporter); |
|
8
|
|
|
|
|
18
|
|
|
8
|
|
|
|
|
5497
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our @EXPORT_OK = qw(retrieve version); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
Readonly my $TRUE => Types::Serialiser::true; |
18
|
|
|
|
|
|
|
Readonly my $FALSE => Types::Serialiser::false; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Cache these command keys |
21
|
|
|
|
|
|
|
Readonly::Array our @CACHE_KEYS => qw( |
22
|
|
|
|
|
|
|
name |
23
|
|
|
|
|
|
|
takes_args takes_options |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# Cache these keys from the takes_ CACHE_KEYS |
27
|
|
|
|
|
|
|
Readonly::Array our @CACHE_TAKES_KEYS => qw( |
28
|
|
|
|
|
|
|
name type class |
29
|
|
|
|
|
|
|
required autofill multivalue |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Readonly::Hash our %CACHE_TAKES_DEFAULT => { |
33
|
|
|
|
|
|
|
autofill => $FALSE, |
34
|
|
|
|
|
|
|
class => 'unknown_class', |
35
|
|
|
|
|
|
|
multivalue => $FALSE, |
36
|
|
|
|
|
|
|
name => 'unknown_name', |
37
|
|
|
|
|
|
|
required => $FALSE, |
38
|
|
|
|
|
|
|
type => 'unknown_type', |
39
|
|
|
|
|
|
|
}; |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# hashref to store cached command data |
42
|
|
|
|
|
|
|
my $cmd_cache = {}; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head2 Public functions |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=over |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=item flush_cache |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Reset the cache |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=cut |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub flush_cache |
55
|
|
|
|
|
|
|
{ |
56
|
1
|
|
|
1
|
1
|
1552
|
$cmd_cache = {}; |
57
|
1
|
|
|
|
|
34
|
return $cmd_cache; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=item cache |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Given C command hashref, cache (and return) the relevant |
63
|
|
|
|
|
|
|
(filtered) command data. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
C is typically the decoded JSON command response. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=cut |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub cache |
70
|
|
|
|
|
|
|
{ |
71
|
5
|
|
|
5
|
1
|
7238
|
my ($data) = @_; |
72
|
|
|
|
|
|
|
|
73
|
5
|
|
|
|
|
16
|
my $name = $data->{name}; |
74
|
|
|
|
|
|
|
|
75
|
5
|
|
|
|
|
52
|
foreach my $key (sort keys %$data) { |
76
|
21
|
100
|
|
|
|
72
|
if ($key =~ m/^takes_/) { |
77
|
10
|
|
|
|
|
18
|
my $newdata = []; |
78
|
10
|
|
|
|
|
12
|
foreach my $tdata (@{$data->{$key}}) { |
|
10
|
|
|
|
|
19
|
|
79
|
99
|
100
|
|
|
|
199
|
if (ref($tdata) eq '') { |
80
|
1
|
|
|
|
|
3
|
my $value = $tdata; |
81
|
1
|
|
|
|
|
4
|
$value =~ s/[*+?]$//; |
82
|
1
|
|
|
|
|
7
|
$tdata = {%CACHE_TAKES_DEFAULT}; |
83
|
1
|
|
|
|
|
84
|
$tdata->{name} = $value; |
84
|
|
|
|
|
|
|
} else { |
85
|
|
|
|
|
|
|
# Arrayref of command hashrefs |
86
|
98
|
|
|
|
|
511
|
foreach my $tkey (sort keys %$tdata) { |
87
|
669
|
100
|
|
|
|
1399
|
delete $tdata->{$tkey} if (! grep {$tkey eq $_} @CACHE_TAKES_KEYS); |
|
4014
|
|
|
|
|
16716
|
|
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
99
|
|
|
|
|
349
|
push(@$newdata, $tdata); |
91
|
|
|
|
|
|
|
} |
92
|
10
|
|
|
|
|
38
|
$data->{$key} = $newdata; |
93
|
|
|
|
|
|
|
} else { |
94
|
11
|
100
|
|
|
|
42
|
delete $data->{$key} if (! grep {$key eq $_} @CACHE_KEYS); |
|
33
|
|
|
|
|
236
|
|
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
5
|
|
|
|
|
23
|
$cmd_cache->{$name} = $data; |
99
|
|
|
|
|
|
|
|
100
|
5
|
|
|
|
|
31
|
return $data; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=item version |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Return the API version from C |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=cut |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub version |
110
|
|
|
|
|
|
|
{ |
111
|
1
|
|
|
1
|
1
|
1710
|
return $Net::FreeIPA::API::Data::VERSION; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item retrieve |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Retrieve the command data for command C. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
(For now, the data is loaded from the C that is |
119
|
|
|
|
|
|
|
distributed with this package and is a fixed version only). |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
Returns the cache command hashref and undef errormessage on SUCCESS, |
122
|
|
|
|
|
|
|
an emptyhashref and actual errormessage otherwise. |
123
|
|
|
|
|
|
|
If the command is already in cache, return the cached version |
124
|
|
|
|
|
|
|
(and undef errormessage). |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=cut |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub retrieve |
129
|
|
|
|
|
|
|
{ |
130
|
4
|
|
|
4
|
1
|
3206
|
my ($name) = @_; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# Return already cached data |
133
|
4
|
100
|
|
|
|
27
|
return ($cmd_cache->{$name}, undef) if defined($cmd_cache->{$name}); |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
# Get the JSON data from Net::FreeIPA::API::Data |
136
|
|
|
|
|
|
|
# TODO: get the JSON data from the JSON api |
137
|
|
|
|
|
|
|
|
138
|
3
|
|
|
|
|
5
|
my $data; |
139
|
3
|
|
|
|
|
26
|
my $json = $Net::FreeIPA::API::Data::API_DATA{$name}; |
140
|
3
|
100
|
|
|
|
30
|
if (! $json) { |
141
|
1
|
|
|
|
|
8
|
return {}, "retrieve name $name failed: no JSON data"; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
2
|
|
|
|
|
3
|
local $@; |
145
|
2
|
|
|
|
|
6
|
eval { |
146
|
2
|
|
|
|
|
306
|
$data = decode_json($json); |
147
|
|
|
|
|
|
|
}; |
148
|
|
|
|
|
|
|
|
149
|
2
|
50
|
|
|
|
10
|
if ($@) { |
150
|
0
|
|
|
|
|
0
|
return {}, "retrieve name $name failed decode_json with $@"; |
151
|
|
|
|
|
|
|
} else { |
152
|
2
|
|
|
|
|
18
|
return cache($data), undef; |
153
|
|
|
|
|
|
|
}; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=item all_command_names |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Return all possible commandsnames sorted. |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Does not update cache. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=cut |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
# Used mainly to generate the API::Function exports |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub all_command_names |
167
|
|
|
|
|
|
|
{ |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
# Get the JSON data from Net::FreeIPA::API::Data |
170
|
|
|
|
|
|
|
# TODO: get the JSON data from the JSON api |
171
|
|
|
|
|
|
|
# If the JSON API doesn't allow to just get the names, |
172
|
|
|
|
|
|
|
|
173
|
1
|
|
|
1
|
1
|
43985
|
return sort keys %Net::FreeIPA::API::Data::API_DATA; |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=pod |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=back |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=cut |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
1; |