From 0fd039e92045bd93c7d2ba1ec4ede44c2b1526d2 Mon Sep 17 00:00:00 2001 From: htrgouvea Date: Fri, 23 Aug 2024 11:22:03 -0300 Subject: [PATCH] fix identation and change some names of variables --- security-gate.pl | 79 ++++++++++++++++++++++++++---------------------- 1 file changed, 43 insertions(+), 36 deletions(-) diff --git a/security-gate.pl b/security-gate.pl index 2096f2a..a58fa7f 100644 --- a/security-gate.pl +++ b/security-gate.pl @@ -11,52 +11,59 @@ use Getopt::Long; sub main { - my ($token, $repository, $dependency_alerts, $secret_scanning_alerts, $code_scanning_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-scanning-alerts" => \$secret_scanning_alerts, - "code-scanning-alerts" => \$code_scanning_alerts - ); - - if ($token && $repository) { - my $result = 0; - - my %alert_checks = ( - 'dependency-alerts' => sub { SecurityGate::Engine::Dependencies->new($token, $repository, \%severity_limits) }, - 'secret-scanning-alerts' => sub { SecurityGate::Engine::Secrets->new($token, $repository) }, - 'code-scanning-alerts' => sub { SecurityGate::Engine::CodeScanning->new($token, $repository, \%severity_limits) }, + 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 ); - for my $alert_type (keys %alert_checks) { - if ($$alert_type) { - $result += $alert_checks{$alert_type}->(); - } - } + if ($token && $repository) { + my $result = 0; + + my %alert_checks = ( + 'dependency-alerts' => sub { SecurityGate::Engine::Dependencies->new($token, $repository, \%severity_limits) }, + 'secret-alerts' => sub { SecurityGate::Engine::Secrets->new($token, $repository) }, + 'code-alerts' => sub { SecurityGate::Engine::CodeScanning->new($token, $repository, \%severity_limits) } + ); - return $result; - } + for my $alert_type (keys %alert_checks) { + if ($alert_type eq 'dependency-alerts' && $dependency_alerts) { + $result += $alert_checks{$alert_type}->(); + } - else { - print SecurityGate::Utils::Helper->new(); + elsif ($alert_type eq 'secret-alerts' && $secret_alerts) { + $result += $alert_checks{$alert_type}->(); + } + + elsif ($alert_type eq 'code-alerts' && $code_alerts) { + $result += $alert_checks{$alert_type}->(); + } + } - return 1; - } + return $result; + } + + else { + print SecurityGate::Utils::Helper->new(); + return 1; + } - return 0; + return 0; } if ($ENV{TEST_MODE}) { - main(); + main(); } else { - exit main(); + exit main(); } \ No newline at end of file