line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Chef::REST; |
2
|
|
|
|
|
|
|
$Chef::REST::VERSION = 1.0; |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
my @base; |
5
|
|
|
|
|
|
|
BEGIN { |
6
|
3
|
|
|
3
|
|
15914
|
use File::Basename qw { dirname }; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
246
|
|
7
|
3
|
|
|
3
|
|
19
|
use File::Spec::Functions qw { splitdir rel2abs }; |
|
3
|
|
|
|
|
9
|
|
|
3
|
|
|
|
|
285
|
|
8
|
3
|
|
|
3
|
|
337
|
@base = ( splitdir ( rel2abs ( dirname(__FILE__) ) ) ); |
9
|
3
|
|
|
|
|
357
|
pop @base; #Chef |
10
|
3
|
|
|
|
|
91
|
push @INC, '/', @base; |
11
|
|
|
|
|
|
|
}; |
12
|
|
|
|
|
|
|
|
13
|
3
|
|
|
3
|
|
7818
|
use parent qw { Chef Chef::Header }; |
|
3
|
|
|
|
|
753
|
|
|
3
|
|
|
|
|
24
|
|
14
|
3
|
|
|
3
|
|
3446
|
use LWP::UserAgent; |
|
3
|
|
|
|
|
215312
|
|
|
3
|
|
|
|
|
209
|
|
15
|
3
|
|
|
3
|
|
2900
|
use Mojo::JSON; |
|
3
|
|
|
|
|
222956
|
|
|
3
|
|
|
|
|
1891
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new { |
18
|
1
|
|
|
1
|
0
|
2965
|
my $class = shift; |
19
|
1
|
|
|
|
|
13
|
my $self = $class->SUPER::new(@_); |
20
|
1
|
|
|
|
|
3
|
bless $self, $class; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
|
|
12
|
$self->_UA_( new LWP::UserAgent( ) ); |
24
|
1
|
|
|
|
|
6
|
$self->_UA_->ssl_opts( 'verify_hostname' => 0 ); |
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
|
|
32
|
return $self; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub _UA_ |
31
|
|
|
|
|
|
|
{ |
32
|
2
|
|
|
2
|
|
5668
|
my ($self,$new_ua) = (@_); |
33
|
2
|
100
|
|
|
|
23
|
$self->{'_UA_'} = $new_ua if defined $new_ua; |
34
|
2
|
|
|
|
|
11
|
return $self->{'_UA_'}; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub add_headers |
38
|
|
|
|
|
|
|
{ |
39
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
40
|
0
|
|
|
|
|
0
|
my $param = shift; |
41
|
0
|
|
|
|
|
0
|
foreach my $header_field( keys( %$param) ){ |
42
|
0
|
|
|
|
|
0
|
$self->_UA_->default_header( $header_field, $param->{ $header_field }); |
43
|
|
|
|
|
|
|
} |
44
|
0
|
|
|
|
|
0
|
return $self; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub get { |
48
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
49
|
0
|
|
|
|
|
0
|
my $param = {@_}; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
0
|
my $response = |
52
|
|
|
|
|
|
|
$self->add_headers( |
53
|
|
|
|
|
|
|
$self->header( |
54
|
|
|
|
|
|
|
'Method' => 'GET', |
55
|
|
|
|
|
|
|
'Path' => $param->{'api_end_point'}, |
56
|
|
|
|
|
|
|
'Content' => '' |
57
|
|
|
|
|
|
|
)->hash |
58
|
|
|
|
|
|
|
) |
59
|
|
|
|
|
|
|
->_UA_ |
60
|
|
|
|
|
|
|
->get( |
61
|
|
|
|
|
|
|
$self->get_uri( $param->{'api_end_point'} ) |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
0
|
return $response; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub post |
68
|
|
|
|
|
|
|
{ |
69
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
70
|
0
|
|
|
|
|
0
|
my $param = {@_}; |
71
|
0
|
|
|
|
|
0
|
my $mojo_json = new Mojo::JSON(); |
72
|
0
|
|
|
|
|
0
|
my $response = $self->add_headers( |
73
|
|
|
|
|
|
|
$self->header( |
74
|
|
|
|
|
|
|
'Method' => 'POST', |
75
|
|
|
|
|
|
|
'Path' => $param->{'api_end_point'}, |
76
|
|
|
|
|
|
|
'Content' => $mojo_json->encode($param->{'data'}) |
77
|
|
|
|
|
|
|
)->hash |
78
|
|
|
|
|
|
|
) |
79
|
|
|
|
|
|
|
->_UA_ |
80
|
|
|
|
|
|
|
->post( |
81
|
|
|
|
|
|
|
$self->get_uri( $param->{'api_end_point'} ), |
82
|
|
|
|
|
|
|
'Content' => $mojo_json->encode($param->{'data'}) |
83
|
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
0
|
return $response; |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub get_uri |
90
|
|
|
|
|
|
|
{ |
91
|
0
|
|
|
0
|
1
|
0
|
my ($self,$api_end_point) = (@_); |
92
|
0
|
0
|
|
|
|
0
|
return join '/', ( $self->server, |
93
|
|
|
|
|
|
|
$api_end_point ) |
94
|
|
|
|
|
|
|
if defined $api_end_point ; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub name |
98
|
|
|
|
|
|
|
{ |
99
|
1
|
|
|
1
|
1
|
6
|
my ($self,$client_name) = (@_); |
100
|
1
|
50
|
|
|
|
5
|
$self->{ 'CHEF_CLIENT' } = $client_name if defined $client_name; |
101
|
1
|
|
|
|
|
11
|
return $self->{ 'CHEF_CLIENT' }; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
__DATA__ |