-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsecurity-gate.pl
59 lines (48 loc) · 1.69 KB
/
security-gate.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env perl
use 5.030;
use strict;
use warnings;
use lib "./lib/";
use SecurityGate::Engine::Dependencies qw(@SEVERITIES);
use SecurityGate::Engine::Secrets;
use SecurityGate::Engine::Code;
use SecurityGate::Utils::Helper;
use Getopt::Long;
sub main {
my ($token, $repository, $dependency_alerts, $secret_alerts, $code_alerts);
my %severity_limits = map {$_ => 0} @SEVERITIES;
Getopt::Long::GetOptions(
"t|token=s" => \$token,
"r|repo=s" => \$repository,
"c|critical=i" => \$severity_limits{critical},
"h|high=i" => \$severity_limits{high},
"m|medium=i" => \$severity_limits{medium},
"l|low=i" => \$severity_limits{low},
"dependency-alerts" => \$dependency_alerts,
"secret-alerts" => \$secret_alerts,
"code-alerts" => \$code_alerts
);
if ($token && $repository) {
my $result = 0;
my %alert_checks = (
'dependency-alerts' => $dependency_alerts ? sub { SecurityGate::Engine::Dependencies->new($token, $repository, \%severity_limits) } : undef,
'secret-alerts' => $secret_alerts ? sub { SecurityGate::Engine::Secrets->new($token, $repository, \%severity_limits) } : undef,
'code-alerts' => $code_alerts ? sub { SecurityGate::Engine::Code->new($token, $repository, \%severity_limits) } : undef
);
for my $check (grep { defined } values %alert_checks) {
$result += $check->();
}
return $result;
}
else {
print SecurityGate::Utils::Helper->new();
return 1;
}
return 0;
}
if ($ENV{TEST_MODE}) {
main();
}
else {
exit main();
}