From de98902a85982351c7539672391de014252edde5 Mon Sep 17 00:00:00 2001 From: Dan Fandrich Date: Fri, 8 Mar 2024 18:33:47 -0800 Subject: Add 'showjson' command to output an advisory in OSV JSON Open Source Vulnerability format is a standard for publishing vulnerabilities in Open Source projects and is defined at https://ossf.github.io/osv-schema/ --- lib/MGA/Advisories.pm | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'lib') diff --git a/lib/MGA/Advisories.pm b/lib/MGA/Advisories.pm index cbabd68..c8514fa 100644 --- a/lib/MGA/Advisories.pm +++ b/lib/MGA/Advisories.pm @@ -821,4 +821,27 @@ sub showadv { print $advtxt; } +sub showadvjson { + my ($advdb, $adv) = @_; + if (!$advdb->{advisories}{$adv}) { + print STDERR "Cannot find advisory $adv\n"; + return undef; + } + my $template = Template->new( + ENCODING => 'utf8', + INCLUDE_PATH => $config->{tmpl_dir}, + EVAL_PERL => 1, + ); + my $vars = { + config => $config, + advisory => $adv, + advdb => $advdb, + basename => \%basename, + tools => \%tools, + }; + my $advtxt; + process_template($template, 'advisory', $vars, \$advtxt, 'json'); + print $advtxt; +} + 1; -- cgit v1.2.1