| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package OpenSearch::Helper; |
|
2
|
4
|
|
|
4
|
|
22625
|
use strict; |
|
|
4
|
|
|
|
|
11
|
|
|
|
4
|
|
|
|
|
171
|
|
|
3
|
4
|
|
|
4
|
|
21
|
use warnings; |
|
|
4
|
|
|
|
|
7
|
|
|
|
4
|
|
|
|
|
202
|
|
|
4
|
4
|
|
|
4
|
|
22
|
use Moo::Role; |
|
|
4
|
|
|
|
|
36
|
|
|
|
4
|
|
|
|
|
72
|
|
|
5
|
4
|
|
|
4
|
|
5009
|
use JSON::XS; |
|
|
4
|
|
|
|
|
15205
|
|
|
|
4
|
|
|
|
|
319
|
|
|
6
|
4
|
|
|
4
|
|
33
|
use Data::Dumper; |
|
|
4
|
|
|
|
|
6
|
|
|
|
4
|
|
|
|
|
232
|
|
|
7
|
4
|
|
|
4
|
|
57
|
use feature qw(signatures); |
|
|
4
|
|
|
|
|
10
|
|
|
|
4
|
|
|
|
|
547
|
|
|
8
|
4
|
|
|
4
|
|
25
|
no warnings qw(experimental::signatures); |
|
|
4
|
|
|
|
|
9
|
|
|
|
4
|
|
|
|
|
3714
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
$Carp::Verbose = 1; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $functions = { |
|
13
|
|
|
|
|
|
|
as_is => sub { my $value = shift; return ($value); }, |
|
14
|
|
|
|
|
|
|
encode_json => sub { my $value = shift; return ( encode_json($value) ); }, |
|
15
|
|
|
|
|
|
|
encode_bool => sub { my $value = shift; return ( defined($value) ? ( $value ? 'true' : 'false' ) : $value ); }, |
|
16
|
|
|
|
|
|
|
concat_comma => sub { my $value = shift; return ( join( ',', @{$value} ) ); }, |
|
17
|
|
|
|
|
|
|
encode_bulk => sub { |
|
18
|
|
|
|
|
|
|
my $value = shift; |
|
19
|
|
|
|
|
|
|
my $bulk = []; |
|
20
|
|
|
|
|
|
|
foreach my $item ( @{$value} ) { |
|
21
|
|
|
|
|
|
|
push( @{$bulk}, encode_json($item) ); |
|
22
|
|
|
|
|
|
|
} |
|
23
|
|
|
|
|
|
|
return ( join( "\n", @{$bulk} ) . "\n" ); |
|
24
|
|
|
|
|
|
|
}, |
|
25
|
|
|
|
|
|
|
}; |
|
26
|
|
|
|
|
|
|
|
|
27
|
0
|
|
|
0
|
|
|
sub _generate_params( $self, $instance ) { |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
my $parsed = { url => {}, body => {} }; |
|
29
|
0
|
|
|
|
|
|
my $forced = undef; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Seems like there are API Endpoints that dont require any Params |
|
32
|
|
|
|
|
|
|
# See: https://opensearch.org/docs/latest/api-reference/security-apis/ |
|
33
|
0
|
0
|
|
|
|
|
my $api_spec = $instance->can('api_spec') ? $instance->api_spec : {}; |
|
34
|
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
foreach my $param ( keys( %{$api_spec} ) ) { |
|
|
0
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $value = $instance->$param; |
|
37
|
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
my $desc = $api_spec->{$param}; |
|
39
|
0
|
|
0
|
|
|
|
my $enc = $desc->{encode_func} // 'as_is'; |
|
40
|
0
|
|
|
|
|
|
my $type = $desc->{type}; |
|
41
|
0
|
|
|
|
|
|
my $fb = $desc->{forced_body}; |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Skipp all other body params if forced_body is already set |
|
44
|
0
|
0
|
0
|
|
|
|
next if ( $forced && ( $type eq 'body' ) ); |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# If forced_body is set by any attribute, we will only use this body param |
|
47
|
0
|
0
|
0
|
|
|
|
if ( $value && $fb ) { |
|
48
|
0
|
|
|
|
|
|
$forced = 1; |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
if ( $type ne 'path' ) { |
|
52
|
0
|
|
|
|
|
|
my $val = $self->_generate_value( $value, $enc ); |
|
53
|
0
|
0
|
|
|
|
|
if ($fb) { |
|
54
|
0
|
|
|
|
|
|
$parsed->{$type} = $val; |
|
55
|
|
|
|
|
|
|
} else { |
|
56
|
0
|
0
|
|
|
|
|
$parsed->{$type}->{$param} = $val if defined($val); |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
0
|
0
|
|
|
|
|
$instance->{$param} = undef if $self->clear_attrs; |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
return ($parsed); |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
0
|
|
|
0
|
|
|
sub _generate_value( $self, $value, $encode ) { |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
68
|
0
|
0
|
|
|
|
|
if ( ref($value) eq 'ARRAY' ) { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
69
|
0
|
0
|
|
|
|
|
return ( $functions->{$encode}->($value) ) if ( scalar( @{$value} ) ); |
|
|
0
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
} elsif ( ref($value) eq 'HASH' ) { |
|
72
|
0
|
0
|
|
|
|
|
return ( $functions->{$encode}->($value) ) if ( keys( %{$value} ) ); |
|
|
0
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
} elsif ( ref($value) ) { |
|
75
|
0
|
0
|
0
|
|
|
|
if ( $value->can('to_hash') && $value->to_hash ) { |
|
|
|
0
|
0
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
return ( $functions->{$encode}->( $value->to_hash ) ); |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
} elsif ( $value->can('to_string') && $value->to_string ) { |
|
79
|
0
|
|
|
|
|
|
return ( $functions->{$encode}->( $value->to_string ) ); |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
} else { |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# Wonder if we ever get here? Maybe on scalar ref? |
|
84
|
|
|
|
|
|
|
#warn("Reached unknown territory with value: " . Dumper($value) . "and type: " Dumper($type)); |
|
85
|
|
|
|
|
|
|
#return($functions->{$encode}->($value)); |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
} else { |
|
89
|
0
|
|
|
|
|
|
return ( $functions->{$encode}->($value) ); |
|
90
|
|
|
|
|
|
|
} |
|
91
|
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
return (undef); |
|
93
|
|
|
|
|
|
|
} |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
1; |