EtcDv2.pm

filter: Statementstmt 75.5% 71 / 94 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 80.7% 21 / 26 Podpod 100% 5 / 5 totaltotal 69.2% 97 / 140 CC 9 SCAR 25.6
CC
9
Cov
66%
new
56.0
ls
6.0
rmdir
6.0
CRAP 13.0
« EtcDv2/Node/Directory.pm ↑ Summary EtcDv2/Auth.pm »
1 6 package Net::EtcDv2 v0.0.3 {
2 6 ▶ use v5.30;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 6 ▶ use strictures;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶ use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶ use English;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 ▶ use feature ":5.30";
Subroutine BEGIN: called CC=1 SCAR=0.0
8 6 ▶ use feature 'lexical_subs';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 6 ▶ use feature 'signatures';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶ use feature 'switch';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶ no warnings "experimental::signatures";
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 ▶ no warnings "experimental::smartmatch";
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 6 ▶ use boolean;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 6 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 6 ▶ use Errno qw(:POSIX);
Subroutine BEGIN: called CC=1 SCAR=0.0
17 6 ▶ use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 6 ▶ use HTTP::Status qw(:constants);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 6 ▶ use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 6 ▶ use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 6 ▶ use Throw qw(throw classify);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 6 ▶ use Try::Tiny qw(try catch);
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 6 ▶ use Net::EtcDv2::Node;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 6 ▶ use Net::EtcDv2::Node::Directory;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 # use Net::EtcDv2::Node::Key;
27  
28 # class references
29 6 my $node = undef;
30 6 my $node_dir = undef;
31  
32 # class member data
33 6 my $debug = false;
34 6 my $host = undef;
35 6 my $port = undef;
36 6 my $user = undef;
37 6 my $password = undef;
38  
39 0 ▶ sub new ($class, %args) {
Subroutine new: not called CC=7 SCAR=40.3
Pod documented
40 0 ▶ if (exists $args{'debug'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"debug"}) 0 0 0
41 0 ▶ if (defined $args{'args'} && $args{'debug'} eq true) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{"args"} and $args{"debug"} eq &true()) 0 0 0
Condition0%0/3
defined $args{"args"} and $args{"debug"} eq &true()
!ll&&!rl&&r
000
MC/DC0%0/2
defined $args{"args"} and $args{"debug"} eq &true()
defined $args{"args"} $args{"debug"} eq &true()
Truth table0%0/3
A and B
A= defined $args{"args"}B= $args{"debug"} eq &true()
ABresult
0X0
100
111
42 0 $debug = true;
43 }
44 }
45  
46 0 my $sub = (caller(0))[3];
47 0 ▶ if ($debug eq true) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug eq &true()) 0 0 0
48 0 say "DEBUG: Sub: $sub";
49 0 say "DEBUG: Constructing object";
50 }
51  
52 0 $host = $args{'host'};
53 0 $port = $args{'port'};
54  
55 0 ▶ if (exists $args{'user'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"user"}) 0 0 0
56 0 $user = $args{'user'};
57 }
58 0 ▶ if (exists $args{'password'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{"password"}) 0 0 0
59 0 $password = $args{'password'};
60 }
61  
62 0 $node = Net::EtcDv2::Node->new(
63 'debug' => $debug,
64 'host' => $host,
65 'password' => $password,
66 'port' => $port,
67 'user' => $user
68 );
69  
70 0 $node_dir = Net::EtcDv2::Node::Directory->new(
71 'debug' => $debug,
72 'host' => $host,
73 'password' => $password,
74 'port' => $port,
75 'user' => $user
76 );
77  
78 0 my $self = {};
79 0 bless $self, $class;
80 }
81  
82 0 ▶ our sub stat ($self, $path) {
Subroutine stat: not called CC=1 SCAR=6.9
Pod documented
83 0 return $node->stat($path);
84 }
85  
86 0 ▶ our sub ls ($self, $path, $recursive = false) {
Subroutine ls: not called CC=2 SCAR=17.9
Pod documented
87 0 return $node->ls($path, $recursive);
88 }
89  
90 0 ▶ our sub mkdir ($self, $path) {
Subroutine mkdir: not called CC=1 SCAR=6.9
Pod documented
91 0 return $node_dir->mkdir($path);
92 }
93  
94 0 ▶ our sub rmdir ($self, $path, $recursive = false) {
Subroutine rmdir: not called CC=2 SCAR=17.9
Pod documented
95 0 return $node_dir->rmdir($path, $recursive);
96 }
97  
98 6 true; # End of Net::EtcDv2
99 }
100  
101 =head1 NAME
102  
103 Net::EtcDv2 - A object oriented Perl module to interact with the EtcD version 2 API
104  
105 =head1 VERSION
106  
107 Version 0.0.1
108  
109 =head1 SYNOPSIS
110  
111 use feature say;
112 use Data::Dumper;
113 use Net::EtcDv2;
114  
115 # create an un-authenticated object for an etcd running on localhost on
116 # port 2379
117 my $foo = Net::EtcDv2->new(
118 'host' => "http://localhost",
119 'port' => 2379
120 );
121
122 my $stat_struct = $foo->stat('/myDir');
123 say Dumper $stat_struct;
124  
125 # outputs the following if '/myDir' exists and is a directory
126 # $VAR1 = {
127 # 'type' => 'dir',
128 # 'uri' => 'http://localhost:2379/myDir',
129 # 'ace' => '*:POST, GET, OPTIONS, PUT, DELETE',
130 # 'entryId' => 'cdf818194f3b8d32:23'
131 # };
132 #
133 # The ACE is the access allowed methods and and origin for that path, and
134 # the 'entryId' is made up from the cluster ID and the etcd item index ID
135  
136 =head1 DESCRIPTION
137  
138 The Net::EtcDv2 module allows code to create, read, update, and delete
139 key/value data in an etcd cluster. Additionally, using the v2 API, this
140 module can create, list, and delete directories in the key store to
141 organize the data.
142  
143 Additionally, this module can manage users and roles, which govern the
144 access rights to the key/value heirarchy.
145  
146 =head1 METHODS
147  
148 =head2 new
149  
150 The constructor for the class. For now, we only support HTTP basic
151 authentication.
152  
153 If the DEBUG environment variable is set, the class will emit debugging
154 output on STDERR.
155  
156 B<Parameters:>
157  
158 - class, SCALAR: The class name
159 - args, HASH: A hash of named parameters:
160 - host: the hostname of the etcd endpoint
161 - port: the port number of the etcd endpoint
162 - user: the username authorized for the etcd environment
163 - password: the password for the user authorized for the etcd
164 environment
165  
166 =head2 stat
167  
168 This method takes a path and gathers information about the etcd object. If the
169 item doesn't exist, it throws an exception (error code 6).
170  
171 B<Parameters:>
172  
173 - self, SCALAR REF: the object reference
174 - path, SCALAR: the path segment of the URI to get info for
175  
176 B<Return type:>
177  
178 - stat_struct: HASH: the stat information for the path
179  
180 B<Exceptions:>
181  
182 If the object is not found (HTTP 404), the method will emit error ENXIO
183  
184 =head2 ls
185  
186 This method, like stat, takes a path and gathers information about the etcd
187 object. If the item doesn't exist, it throws an exception (error code 6).
188  
189 Unlike C<stat>, it only returns in the JSON response the node name, type, and
190 whether it has any children. In addition, while C<stat> only returns specific
191 information about the named node, ls can do recursive listing, and if the item
192 requested was a directory, it's immediate children; any child items are nested
193 in the response.
194  
195 B<Parameters:>
196  
197 - self, SCALAR REF: the object reference
198 - path, SCALAR: the path segment of the URI to get info for
199 - recursive, SCALAR boolean [OPTIONAL]: Whether to recursively descend into
200 sub directories
201  
202 B<Return type:>
203  
204 - status, SCALAR boolean: Whether the listing was successful or not
205 - stat_struct: HASH: the stat information for the path
206  
207 B<Exceptions:>
208  
209 If the object is not found (HTTP 404), the method will emit error ENXIO
210  
211 =head2 mkdir
212  
213 This method creates a directory if the named object does not already exist
214 at that level of the heirarchy. If it already exists, no matter if it is a
215 key or directory, it emits an exception.
216  
217 B<Parameters:>
218  
219 - self, SCALAR REF: the object reference
220 - path, SCALAR: the full path to create
221  
222 B<Return type:>
223  
224 - path, SCALAR: the full path that was created
225  
226 B<Exceptions:>
227  
228 If the named entry, irregardless of the type, exists, the method will emit
229 error EEXIST
230  
231 =head2 rmdir
232  
233 This method will delete a directory if the named object exists, and is empty.
234 If any of the following are true, the method emits and appropriate exception:
235  
236 - If the directory does not exist
237 - If the directory is not empty unless the recursive flag is passed
238 - If the object is not a directory
239  
240 B<Parameters:>
241  
242 - self, SCALAR REF: the object reference
243 - path, SCALAR: the full path to delete
244 - recursive, boolean: whether to recursively delete the directory if it
245 contains any content
246  
247 B<Return type:>
248  
249 - path: SCALAR: the path that was created
250  
251 B<Exceptions:>
252  
253 The following exceptions are emitted during error events:
254  
255 - If the directory does not exist, a 404 exception is thrown
256 - If the directory is not empty, a 400 exception is thrown
257 - If the object is not a directory, a 400 exception is thrown
258  
259 =head1 AUTHOR
260  
261 Gary L. Greene, Jr., C<< <greeneg at tolharadys.net> >>
262  
263 =head1 BUGS
264  
265 Please report any bugs or feature requests via this module's GitHub Issues tracker, here:
266 L<https://github.com/greeneg/Net-EtcDv2>.
267  
268 =head1 SUPPORT
269  
270 You can find documentation for this module with the perldoc command.
271  
272 perldoc Net::EtcDv2
273  
274 You can also look for information at:
275  
276 =over 4
277  
278 =item * AnnoCPAN: Annotated CPAN documentation
279  
280 L<http://annocpan.org/dist/Net-EtcDv2>
281  
282 =item * CPAN Ratings
283  
284 L<https://cpanratings.perl.org/d/Net-EtcDv2>
285  
286 =item * Search CPAN
287  
288 L<https://metacpan.org/release/Net-EtcDv2>
289  
290 =back
291  
292 =head1 LICENSE AND COPYRIGHT
293  
294 This software is Copyright (c) 2020 by Gary L. Greene, Jr.
295  
296 This is free software, licensed under:
297  
298 The Apache License, Version 2.0, January 2004
299  
300 =cut
« EtcDv2/Node/Directory.pm ↑ Summary EtcDv2/Auth.pm »