From 78aac6a0372e8d772f5d21bea04fe3283320ff3c Mon Sep 17 00:00:00 2001 From: htrgouvea Date: Fri, 23 Aug 2024 11:22:40 -0300 Subject: [PATCH] fix identation and incorrect interpolation --- lib/SecurityGate/Engine/Dependencies.pm | 85 +++++++++++++------------ 1 file changed, 43 insertions(+), 42 deletions(-) diff --git a/lib/SecurityGate/Engine/Dependencies.pm b/lib/SecurityGate/Engine/Dependencies.pm index d5294b6..951829d 100644 --- a/lib/SecurityGate/Engine/Dependencies.pm +++ b/lib/SecurityGate/Engine/Dependencies.pm @@ -1,56 +1,57 @@ -package SecurityGate::Engine::Dependencies; +package SecurityGate::Engine::Dependencies { + use strict; + use warnings; + use Mojo::UserAgent; + use Mojo::JSON; + use Exporter 'import'; -use strict; -use warnings; -use Mojo::UserAgent; -use Mojo::JSON; -use Exporter 'import'; + our @EXPORT_OK = qw(@SEVERITIES); + our @SEVERITIES = ("critical", "high", "medium", "low"); -our @EXPORT_OK = qw(@SEVERITIES); -our @SEVERITIES = ("critical", "high", "medium", "low"); + sub new { + my ($class, $token, $repository, $severity_limits) = @_; -sub new { - my ($class, $token, $repository, $severity_limits) = @_; - - my %severity_counts = map { $_ => 0 } @SEVERITIES; - - my $endpoint = "https://api.github.com/repos/$repository/dependabot/alerts"; - my $userAgent = Mojo::UserAgent -> new(); - my $request = $userAgent -> get($endpoint, {Authorization => "Bearer $token"}) -> result(); - - if ($request -> code() == 200) { - my $data = $request -> json(); + my %severity_counts = map { $_ => 0 } @SEVERITIES; - foreach my $alert (@$data) { - if ($alert -> {state} eq "open") { - my $severity = $alert -> {security_vulnerability} -> {severity}; - $severity_counts{$severity}++; + my $endpoint = "https://api.github.com/repos/$repository/dependabot/alerts"; + my $userAgent = Mojo::UserAgent -> new(); + my $request = $userAgent -> get($endpoint, {Authorization => "Bearer $token"}) -> result(); + + if ($request -> code() == 200) { + my $data = $request -> json(); + + foreach my $alert (@$data) { + if ($alert -> {state} eq "open") { + my $severity = $alert -> {security_vulnerability} -> {severity}; + $severity_counts{$severity}++; + } } - } - print "[!] Total of security alerts:\n\n"; + print "[!] Total of security alerts:\n\n"; - foreach my $severity (@SEVERITIES) { - print "[-] $severity: $severity_counts{$severity}\n"; - } + foreach my $severity (@SEVERITIES) { + print "[-] $severity: $severity_counts{$severity}\n"; + } + + print "\n"; - print "\n"; + my $threshold_exceeded = 0; - my $threshold_exceeded = 0; - foreach my $severity (@SEVERITIES) { - if ($severity_counts{$severity} > $severity_limits -> {$severity}) { - print "[+] More than $severity_limits -> {$severity} $severity security alerts found.\n"; - $threshold_exceeded = 1; + foreach my $severity (@SEVERITIES) { + if ($severity_counts{$severity} > $severity_limits -> {$severity}) { + print "[+] More than $severity_limits->{$severity} $severity security alerts found.\n"; + $threshold_exceeded = 1; + } } - } - return $threshold_exceeded; - } - - else { - print "Error: Unable to fetch alerts. HTTP status code: " . $request -> code() . "\n"; - return 1; + return $threshold_exceeded; + } + + else { + print "Error: Unable to fetch alerts. HTTP status code: " . $request -> code() . "\n"; + return 1; + } } } -1; +1; \ No newline at end of file