@@ -5,7 +5,7 @@ package Metabrik::Client::Onyphe;
5
5
use strict;
6
6
use warnings;
7
7
8
- our $VERSION = ' 1.04 ' ;
8
+ our $VERSION = ' 1.06 ' ;
9
9
10
10
use base qw( Metabrik) ;
11
11
@@ -19,12 +19,14 @@ sub brik_properties {
19
19
apikey => [ qw( apikey) ],
20
20
apiurl => [ qw( apiurl) ],
21
21
autoscroll => [ qw( 0|1) ],
22
+ wait => [ qw( seconds) ],
22
23
_ao => [ qw( INTERNAL) ],
23
24
_sb => [ qw( INTERNAL) ],
24
25
},
25
26
attributes_default => {
26
27
apiurl => ' https://www.onyphe.io/api/v2' ,
27
28
autoscroll => 0,
29
+ wait => 2,
28
30
},
29
31
commands => {
30
32
user => [ ],
@@ -356,6 +358,9 @@ sub function_merge {
356
358
return $return -> ();
357
359
}
358
360
361
+ #
362
+ # Will remove everything from input stream on matches.
363
+ #
359
364
sub function_blacklist {
360
365
my $self = shift ;
361
366
my ($r , $lookup ) = @_ ;
@@ -393,20 +398,28 @@ sub function_blacklist {
393
398
for my $page (@$r ) {
394
399
for my $this (@{$page -> {results }}) {
395
400
my $skip = 0;
401
+ # $field is the field to match against (example: domain):
396
402
for my $field (@$fields ) {
397
- if (defined ($self -> _value($this , $field ))) {
403
+ # Fetch the value from current result $this:
404
+ my $value = $self -> _value($this , $field );
405
+ if (defined ($value )) {
406
+ # Compare against all fields given in the CSV:
398
407
for my $h (@$l ) {
399
- if (exists ($h -> {$field })
400
- && $h -> { $field } ne $self -> _value( $this , $field )) {
408
+ if (exists ($h -> {$field }) && $h -> { $field } eq $value ) {
409
+ # print "[DEBUG] skip field [ $field] value [$value]\n";
401
410
$skip ++;
402
411
last ;
403
412
}
404
413
}
405
414
}
406
- last if $skip == $fields_count ;
415
+ # When all fields have matched, no need to compare with remaining
416
+ if ($skip == $fields_count ) {
417
+ # print "[DEBUG] all fields matched [$skip]\n";
418
+ last ;
419
+ }
407
420
}
408
- if ($skip != $fields_count ) { # Not all fields have matched,
409
- # we keep results.
421
+ if ($skip != $fields_count ) { # Not all fields have matched, it is
422
+ # NOT blacklisted, we keep results
410
423
push @new , $this ;
411
424
}
412
425
}
@@ -415,6 +428,9 @@ sub function_blacklist {
415
428
return $return -> ();
416
429
}
417
430
431
+ #
432
+ # Will keep everything from input stream on matches.
433
+ #
418
434
sub function_whitelist {
419
435
my $self = shift ;
420
436
my ($r , $lookup ) = @_ ;
@@ -452,18 +468,28 @@ sub function_whitelist {
452
468
for my $page (@$r ) {
453
469
for my $this (@{$page -> {results }}) {
454
470
my $skip = 0;
471
+ # $field is the field to match against (example: domain):
455
472
for my $field (@$fields ) {
456
- if (defined ($self -> _value($this , $field ))) {
473
+ # Fetch the value from current result $this:
474
+ my $value = $self -> _value($this , $field );
475
+ if (defined ($value )) {
476
+ # Compare against all fields given in the CSV:
457
477
for my $h (@$l ) {
458
- if (exists ($h -> {$field }) && $h -> {$field } eq $self -> _value($this , $field )) {
478
+ if (exists ($h -> {$field }) && $h -> {$field } eq $value ) {
479
+ # print "[DEBUG] skip field [$field] value [$value]\n";
459
480
$skip ++;
460
481
last ;
461
482
}
462
483
}
463
484
}
464
- last if $skip == $fields_count ;
485
+ # When all fields have matched, no need to compare with remaining
486
+ if ($skip == $fields_count ) {
487
+ # print "[DEBUG] all fields matched [$skip]\n";
488
+ last ;
489
+ }
465
490
}
466
- if ($skip != $fields_count ) { # No all fields have matched, we keep results.
491
+ if ($skip == $fields_count ) { # All fields have matched, it is
492
+ # whitelisted, we keep results.
467
493
push @new , $this ;
468
494
}
469
495
}
@@ -895,7 +921,7 @@ L<Metabrik>
895
921
896
922
=head1 COPYRIGHT AND LICENSE
897
923
898
- Copyright (c) 2018-2019 , ONYPHE
924
+ Copyright (c) 2018-2020 , ONYPHE
899
925
900
926
You may distribute this module under the terms of The BSD 3-Clause License.
901
927
See LICENSE file in the source distribution archive.
0 commit comments