lib/Rex/Interface/Fs/HTTP.pm

filter: Statementstmt 23.8% 26 / 109 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 31.0% 9 / 29 Podpod 0.0% 0 / 20 totaltotal 20.0% 35 / 175 CC 10 SCAR 13.9
CC
10
Cov
21%
download
12.0
new
6.0
ls
6.0
CRAP 4.0
« lib/Rex/RunList.pm ↑ Summary lib/Rex/Service/Redhat/systemd.pm »
1 #
2 # (c) Jan Gehring <jan.gehring@gmail.com>
3 #
4  
5 package Rex::Interface::Fs::HTTP;
6  
7 1 ▶use v5.14.4;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 our $VERSION = '1.16.1'; # VERSION
11  
12 1 ▶use Rex::Commands;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Rex::Interface::Exec;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Rex::Interface::Fs::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶ use Rex::Require;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 MIME::Base64->use;
20 }
21 1 ▶use base qw(Rex::Interface::Fs::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod undocumented
24 0 my $that = shift;
25 0 ▶ my $proto = ref($that) || $that;
Condition0%0/3
ref $that || $that
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $that || $that
ref $that $that
Truth table0%0/3
A || B
A= ref $thatB= $that
ABresult
1X1
011
000
26 0 my $self = $proto->SUPER::new(@_);
27  
28 0 bless( $self, $proto );
29  
30 0 return $self;
31 }
32  
33 0 ▶sub ls {
Subroutine ls: not called CC=2 SCAR=17.9
Pod undocumented
34 0 my ( $self, $path ) = @_;
35  
36 0 my $resp = connection->post( "/fs/ls", { path => $path } );
37 0 ▶ if ( $resp->{ok} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resp->{"ok"}) 0 0 0
38 0 return @{ $resp->{ls} };
39 }
40 }
41  
42 0 ▶sub is_dir {
Subroutine is_dir: not called CC=1 SCAR=6.9
Pod undocumented
43 0 my ( $self, $path ) = @_;
44 0 my $resp = connection->post( "/fs/is_dir", { path => $path } );
45 0 return $resp->{ok};
46 }
47  
48 0 ▶sub is_file {
Subroutine is_file: not called CC=1 SCAR=6.9
Pod undocumented
49 0 my ( $self, $file ) = @_;
50 0 my $resp = connection->post( "/fs/is_file", { path => $file } );
51 0 return $resp->{ok};
52 }
53  
54 0 ▶sub unlink {
Subroutine unlink: not called CC=2 SCAR=17.9
Pod undocumented
55 0 my ( $self, @files ) = @_;
56  
57 0 my $ok = 0;
58 0 for my $file (@files) {
59 0 my $resp = connection->post( "/fs/unlink", { path => $file } );
60 0 $ok = $resp->{ok};
61 }
62  
63 0 return $ok;
64 }
65  
66 0 ▶sub mkdir {
Subroutine mkdir: not called CC=1 SCAR=6.9
Pod undocumented
67 0 my ( $self, $dir ) = @_;
68 0 my $resp = connection->post( "/fs/mkdir", { path => $dir } );
69 0 return $resp->{ok};
70 }
71  
72 0 ▶sub stat {
Subroutine stat: not called CC=2 SCAR=17.9
Pod undocumented
73 0 my ( $self, $file ) = @_;
74 0 my $resp = connection->post( "/fs/stat", { path => $file } );
75 0 ▶ if ( $resp->{ok} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resp->{"ok"}) 0 0 0
76 0 return %{ $resp->{stat} };
77 }
78  
79 0 return undef;
80 }
81  
82 0 ▶sub is_readable {
Subroutine is_readable: not called CC=1 SCAR=6.9
Pod undocumented
83 0 my ( $self, $file ) = @_;
84 0 my $resp = connection->post( "/fs/is_readable", { path => $file } );
85 0 return $resp->{ok};
86 }
87  
88 0 ▶sub is_writable {
Subroutine is_writable: not called CC=1 SCAR=6.9
Pod undocumented
89 0 my ( $self, $file ) = @_;
90 0 my $resp = connection->post( "/fs/is_writable", { path => $file } );
91 0 return $resp->{ok};
92 }
93  
94 0 ▶sub readlink {
Subroutine readlink: not called CC=2 SCAR=17.9
Pod undocumented
95 0 my ( $self, $file ) = @_;
96 0 my $resp = connection->post( "/fs/readlink", { path => $file } );
97 0 ▶ if ( $resp->{ok} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resp->{"ok"}) 0 0 0
98 0 return $resp->{link};
99 }
100 }
101  
102 0 ▶sub rename {
Subroutine rename: not called CC=1 SCAR=6.9
Pod undocumented
103 0 my ( $self, $old, $new ) = @_;
104 0 my $resp = connection->post( "/fs/rename", { old => $old, new => $new } );
105 0 return $resp->{ok};
106 }
107  
108 0 ▶sub glob {
Subroutine glob: not called CC=2 SCAR=17.9
Pod undocumented
109 0 my ( $self, $glob ) = @_;
110 0 my $resp = connection->post( "/fs/glob", { glob => $glob } );
111 0 ▶ if ( $resp->{ok} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resp->{"ok"}) 0 0 0
112 0 return @{ $resp->{glob} };
113 }
114 }
115  
116 0 ▶sub upload {
Subroutine upload: not called CC=1 SCAR=6.9
Pod undocumented
117 0 my ( $self, $source, $target ) = @_;
118  
119 0 my $resp = connection->upload( [ content => [$source], path => $target ] );
120 0 return $resp->{ok};
121 }
122  
123 0 ▶sub download {
Subroutine download: not called CC=3 SCAR=24.8
Pod undocumented
124 0 my ( $self, $source, $target ) = @_;
125  
126 0 my $resp = connection->post( "/fs/download", { path => $source } );
127 0 ▶ if ( $resp->{ok} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resp->{"ok"}) 0 0 0
128 0 ▶ open( my $fh, ">", $target ) or die($!);
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $target or die $! 0 0 0
129 0 print $fh decode_base64( $resp->{content} );
130 0 close($fh);
131  
132 0 return 1;
133 }
134  
135 0 return 0;
136 }
137  
138 0 ▶sub ln {
Subroutine ln: not called CC=1 SCAR=6.9
Pod undocumented
139 0 my ( $self, $from, $to ) = @_;
140  
141 0 Rex::Logger::debug("Symlinking files: $to -> $from");
142 0 my $resp = connection->post( "/fs/ln", { from => $from, to => $to } );
143 0 return $resp->{ok};
144 }
145  
146 0 ▶sub rmdir {
Subroutine rmdir: not called CC=2 SCAR=17.9
Pod undocumented
147 0 my ( $self, @dirs ) = @_;
148  
149 0 Rex::Logger::debug( "Removing directories: " . join( ", ", @dirs ) );
150 0 my $ok = 0;
151 0 for my $dir (@dirs) {
152 0 my $resp = connection->post( "/fs/rmdir", { path => $dir } );
153 0 $ok = $resp->{ok};
154 }
155  
156 0 return $ok;
157 }
158  
159 0 ▶sub chown {
Subroutine chown: not called CC=1 SCAR=6.9
Pod undocumented
160 0 my ( $self, $user, $file, @opts ) = @_;
161  
162 0 my $resp = connection->post(
163 "/fs/chown",
164 {
165 user => $user,
166 path => $file,
167 options => {@opts},
168 }
169 );
170  
171 0 return $resp->{ok};
172 }
173  
174 0 ▶sub chgrp {
Subroutine chgrp: not called CC=1 SCAR=6.9
Pod undocumented
175 0 my ( $self, $group, $file, @opts ) = @_;
176  
177 0 my $resp = connection->post(
178 "/fs/chgrp",
179 {
180 group => $group,
181 path => $file,
182 options => {@opts},
183 }
184 );
185  
186 0 return $resp->{ok};
187 }
188  
189 0 ▶sub chmod {
Subroutine chmod: not called CC=1 SCAR=6.9
Pod undocumented
190 0 my ( $self, $mode, $file, @opts ) = @_;
191  
192 0 my $resp = connection->post(
193 "/fs/chmod",
194 {
195 mode => $mode,
196 path => $file,
197 options => {@opts},
198 }
199 );
200  
201 0 return $resp->{ok};
202 }
203  
204 0 ▶sub cp {
Subroutine cp: not called CC=1 SCAR=6.9
Pod undocumented
205 0 my ( $self, $source, $dest ) = @_;
206  
207 0 my $resp = connection->post(
208 "/fs/cp",
209 {
210 source => $source,
211 dest => $dest,
212 }
213 );
214  
215 0 return $resp->{ok};
216 }
217  
218 1 1;
« lib/Rex/RunList.pm ↑ Summary lib/Rex/Service/Redhat/systemd.pm »