line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
23
|
|
2
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
39
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
package Footprintless::Plugin::Atlassian::Confluence::Client; |
5
|
|
|
|
|
|
|
$Footprintless::Plugin::Atlassian::Confluence::Client::VERSION = '1.02'; |
6
|
|
|
|
|
|
|
# ABSTRACT: A REST client for Atlassian Confluence |
7
|
|
|
|
|
|
|
# PODNAME: Footprintless::Plugin::Atlassian::Confluence::Client |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
3
|
use parent qw(Footprintless::MixableBase); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
|
|
52
|
use Footprintless::Mixins qw( |
12
|
|
|
|
|
|
|
_sub_entity |
13
|
1
|
|
|
1
|
|
1006
|
); |
|
1
|
|
|
|
|
3566
|
|
14
|
1
|
|
|
|
|
30
|
use Footprintless::Util qw( |
15
|
|
|
|
|
|
|
dynamic_module_new |
16
|
1
|
|
|
1
|
|
4
|
); |
|
1
|
|
|
|
|
1
|
|
17
|
1
|
|
|
1
|
|
2
|
use Log::Any; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
2
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $logger = Log::Any->get_logger(); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub _init { |
22
|
2
|
|
|
2
|
|
69
|
my ( $self, %options ) = @_; |
23
|
|
|
|
|
|
|
|
24
|
2
|
|
|
|
|
5
|
$self->{username} = $self->_sub_entity( 'automation.username', 1 ); |
25
|
2
|
|
|
|
|
96
|
$self->{password} = $self->_sub_entity( 'automation.password', 1 ); |
26
|
2
|
|
33
|
|
|
47
|
$self->{agent} = $options{agent} || $self->{factory}->agent(); |
27
|
|
|
|
|
|
|
$self->{request_builder} = dynamic_module_new( |
28
|
|
|
|
|
|
|
( $options{request_builder_module} |
29
|
2
|
|
100
|
|
|
468
|
|| 'Footprintless::Plugin::Atlassian::Confluence::RequestBuilder' |
30
|
|
|
|
|
|
|
), |
31
|
|
|
|
|
|
|
$self->_web_url() |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
$self->{response_parser} = dynamic_module_new( |
34
|
|
|
|
|
|
|
( $options{response_parser_module} |
35
|
2
|
|
50
|
|
|
29
|
|| 'Footprintless::Plugin::Atlassian::Confluence::ResponseParser' |
36
|
|
|
|
|
|
|
) |
37
|
|
|
|
|
|
|
); |
38
|
|
|
|
|
|
|
|
39
|
2
|
|
|
|
|
12
|
return $self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub request { |
43
|
2
|
|
|
2
|
1
|
920
|
my ( $self, $endpoint, $args, %response_options ) = @_; |
44
|
|
|
|
|
|
|
|
45
|
2
|
|
|
|
|
2
|
my $response; |
46
|
2
|
|
|
|
|
2
|
eval { |
47
|
2
|
|
|
|
|
7
|
$logger->debugf( 'requesting %s', $endpoint ); |
48
|
2
|
50
|
|
|
|
23
|
my $http_request = $self->{request_builder}->$endpoint( ( $args ? @$args : () ) ); |
49
|
2
|
|
|
|
|
230
|
$http_request->authorization_basic( $self->{username}, $self->{password} ); |
50
|
|
|
|
|
|
|
|
51
|
2
|
50
|
|
|
|
1075
|
if ( $logger->is_trace() ) { |
52
|
0
|
|
|
|
|
0
|
$logger->trace( |
53
|
|
|
|
|
|
|
join( '', |
54
|
|
|
|
|
|
|
"----------------------BEGIN REQUEST--------------------\n", |
55
|
|
|
|
|
|
|
$http_request->dump( maxlength => 500 ), |
56
|
|
|
|
|
|
|
"\n---------------------- END REQUEST --------------------\n" ) |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
2
|
|
|
|
|
21
|
my @content = (); |
61
|
2
|
50
|
|
|
|
8
|
if ( $response_options{content_file} ) { |
|
|
50
|
|
|
|
|
|
62
|
0
|
|
|
|
|
0
|
$logger->tracef( 'writing response to %s', $response_options{content_file} ); |
63
|
0
|
|
|
|
|
0
|
push( @content, $response_options{content_file} ); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
elsif ( $response_options{content_cb} ) { |
66
|
0
|
|
|
|
|
0
|
$logger->trace('writing response to callback'); |
67
|
0
|
|
|
|
|
0
|
push( @content, $response_options{content_cb}, $response_options{read_size_hint} ); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
2
|
|
|
|
|
8
|
my $http_response = $self->{agent}->request( $http_request, @content ); |
71
|
|
|
|
|
|
|
|
72
|
2
|
50
|
|
|
|
5764
|
if ( $logger->is_trace() ) { |
73
|
0
|
|
|
|
|
0
|
$logger->trace( |
74
|
|
|
|
|
|
|
join( '', |
75
|
|
|
|
|
|
|
"----------------------BEGIN RESPONSE--------------------\n", |
76
|
|
|
|
|
|
|
$http_response->dump( maxlength => 500 ), |
77
|
|
|
|
|
|
|
"\n---------------------- END RESPONSE --------------------\n" ) |
78
|
|
|
|
|
|
|
); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
2
|
|
|
|
|
27
|
$response = $self->{response_parser}->$endpoint( $http_response, %response_options ); |
82
|
|
|
|
|
|
|
}; |
83
|
2
|
50
|
|
|
|
5
|
if ($@) { |
84
|
0
|
0
|
0
|
|
|
0
|
if ( ref($@) eq 'HASH' && $@->{code} ) { |
85
|
0
|
|
|
|
|
0
|
$response = $@; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
else { |
88
|
0
|
|
|
|
|
0
|
$response = { |
89
|
|
|
|
|
|
|
code => 500, |
90
|
|
|
|
|
|
|
content => {}, |
91
|
|
|
|
|
|
|
message => $@, |
92
|
|
|
|
|
|
|
success => 0, |
93
|
|
|
|
|
|
|
}; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
} |
96
|
2
|
|
|
|
|
9
|
return $response; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub request_all { |
100
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $endpoint, $args, @response_options ) = @_; |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
0
|
my $response = $self->request( |
103
|
|
|
|
|
|
|
$endpoint, |
104
|
|
|
|
|
|
|
[ @$args, |
105
|
|
|
|
|
|
|
limit => 100, |
106
|
|
|
|
|
|
|
start => 0 |
107
|
|
|
|
|
|
|
], |
108
|
|
|
|
|
|
|
@response_options |
109
|
|
|
|
|
|
|
); |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
0
|
my $next = $response; |
112
|
0
|
|
0
|
|
|
0
|
while ( $next->{success} && $next->{content}{_links}{next} ) { |
113
|
0
|
|
|
|
|
0
|
my $limit = $response->{content}{limit}; |
114
|
|
|
|
|
|
|
$next = $self->request( |
115
|
|
|
|
|
|
|
$endpoint, |
116
|
|
|
|
|
|
|
[ @$args, |
117
|
|
|
|
|
|
|
limit => $limit, |
118
|
0
|
|
|
|
|
0
|
start => $next->{content}{start} + $limit, |
119
|
|
|
|
|
|
|
], |
120
|
|
|
|
|
|
|
@response_options |
121
|
|
|
|
|
|
|
); |
122
|
0
|
|
|
|
|
0
|
push( @{ $response->{content}{results} }, @{ $next->{content}{results} } ); |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
0
|
delete( $response->{content}{_links}{next} ); |
126
|
0
|
|
|
|
|
0
|
$response->{content}{limit} = scalar( @{ $response->{content}{results} } ); |
|
0
|
|
|
|
|
0
|
|
127
|
0
|
|
|
|
|
0
|
$response->{content}{size} = $response->{content}{limit}; |
128
|
0
|
|
|
|
|
0
|
$response->{content}{start} = 0; |
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
0
|
return $response; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub _web_url { |
134
|
2
|
|
|
2
|
|
2
|
my ($self) = @_; |
135
|
2
|
|
|
|
|
6
|
my $web = $self->_sub_entity( 'web', 1 ); |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
return |
138
|
|
|
|
|
|
|
( $web->{https} ? 'https://' : 'http://' ) |
139
|
|
|
|
|
|
|
. $web->{hostname} |
140
|
|
|
|
|
|
|
. ( $web->{port} ? ":$web->{port}" : '' ) |
141
|
2
|
50
|
50
|
|
|
55
|
. ( $web->{context_path} || '' ); |
|
|
50
|
|
|
|
|
|
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
1; |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
__END__ |