blib/lib/OPP/Proc/Discovery.pm

filter: Statementstmt 39.1% 18 / 46 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 75.0% 6 / 8 Podpod n/a totaltotal 36.9% 24 / 65 CC 8 SCAR 29.8
CC
8
Cov
32%
process
42.0
__ANON__
12.0
BEGIN
1.0
CRAP 19.6
« blib/lib/OPP/Proc/Fields.pm ↑ Summary blib/lib/Class/Gomor.pm »
1 #
2 # $Id: Discovery.pm,v 69a3d7308875 2023/04/05 15:11:02 gomor $
3 #
4 package OPP::Proc::Discovery;
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use base qw(OPP::Proc);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 __PACKAGE__->cgBuildIndices;
10  
11 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Onyphe::Api;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use File::Temp qw(tempfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 our $VERSION = '1.00';
16  
17 my $oa = Onyphe::Api->new->init or die("discovery: init failed");
18 $oa->silent(1);
19 $oa->verbose(0);
20  
21 #
22 # NOTE: datascan category by default
23 #
24 # | discovery
25 # | discovery category:vulnscan
26 # | discovery category:datascan tag:open device.class:database
27 #
28 sub process {
29 0 ▶ my $self = shift;
Subroutine process: not called CC=6 SCAR=37.4
30 0 my ($input) = @_;
31  
32 0 my $options = $self->options;
33 0 ▶ my $category = $options->{category}[0] || 'datascan';
Condition0%0/2
$options->{'category'}[0] || 'datascan'
l!l
00
MC/DC0%0/1
$options->{'category'}[0] || 'datascan'
$options->{'category'}[0]
Truth table0%0/2
A
A= $options->{'category'}[0]
Aresult
11
00
34 0 my $oql;
35 0 ▶ if (defined($options->{args})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $options->{"args"}) 0 0 0
36 0 $oql = $options->{args};
37 0 $oql =~ s{category\s*:\s*(\S+)\s*}{}g; # Remove category if given
38 }
39  
40 0 my ($fh, $filename) = tempfile();
41 0 for my $field (keys %$input) {
42 0 my $value = $input->{$field};
43 0 $value =~ s{"}{\\"}g;
44 0 my $print = "$field:\"$value\"";
45 0 ▶ if (defined($oql)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $oql) 0 0 0
46 0 $print .= " $oql";
47 }
48 0 utf8::encode($print);
49 0 print $fh "$print\n";
50 }
51 0 close($fh);
52  
53 #print STDERR "tempfile [$filename]\n";
54  
55 my $cb = sub {
56 0 ▶ my ($results) = @_;
Subroutine __ANON__: not called CC=3 SCAR=24.8
57 0 for (@$results) {
58 0 ▶ next if m{.\@category.\s*:\s*.none.};
Branch: 1 branch
BranchTrueFalseTotal
if /.\@category.\s*:\s*.none./ 0 0 0
59 0 my $docs = $self->from_json($_);
60 0 $docs = $self->flatten($docs);
61 0 $self->output->add($docs);
62 }
63 0 };
64  
65 0 $oa->bulk_discovery($category, $filename, undef, { trackquery => 'true' }, $cb);
66  
67 0 ▶ unlink($filename) if -f $filename;
Branch: 1 branch
BranchTrueFalseTotal
if -f $filename 0 0 0
68  
69 0 return 1;
70 }
71  
72 1;
73  
74 __END__
« blib/lib/OPP/Proc/Fields.pm ↑ Summary blib/lib/Class/Gomor.pm »