-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added "csaf-validator" utility and improved validation
- Loading branch information
1 parent
60ffdac
commit c485cf9
Showing
83 changed files
with
2,046 additions
and
1,717 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/usr/bin/perl | ||
|
||
use strict; | ||
use warnings; | ||
use utf8; | ||
|
||
use App::CSAF::Validator; | ||
|
||
exit App::CSAF::Validator->run(@ARGV) unless caller(); | ||
|
||
1; | ||
|
||
__END__ | ||
=encoding utf-8 | ||
=head1 NAME | ||
csaf-validator - CSAF Validator | ||
=head1 SYNOPSIS | ||
csaf-validator --file PATH | ||
csaf-validator [--help|--man|-v] | ||
Options: | ||
-f, --file PATH CSAF document path | ||
--help Brief help message | ||
--man Full documentation | ||
-v Print version | ||
=head1 DESCRIPTION | ||
C<csaf-validator> CSAF Validator | ||
=head1 EXAMPLES | ||
$ csaf-validator -f csaf-document.json | ||
[error] /document/tracking/revision_history: Sorted Revision History (6.1.14 - mandatory) | ||
[error] /document/tracking/version: Detected newer revision of document (6.1.16 - mandatory) | ||
$ cat csaf-document.json | csaf-validator | ||
[error] /product_tree/branches/0/branches/0/branches/name: Version Range in Product Version (6.1.31 - mandatory) | ||
=head1 AUTHOR | ||
L<Giuseppe Di Terlizzi|https://metacpan.org/author/gdt> | ||
=head1 COPYRIGHT AND LICENSE | ||
Copyright © 2023-2024 L<Giuseppe Di Terlizzi|https://metacpan.org/author/gdt> | ||
You may use and distribute this module according to the same terms | ||
that Perl is distributed under. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package App::CSAF::Validator; | ||
|
||
use 5.010001; | ||
use strict; | ||
use warnings; | ||
use utf8; | ||
|
||
use Getopt::Long qw( GetOptionsFromArray :config gnu_compat ); | ||
use Pod::Usage; | ||
use Carp; | ||
|
||
use CSAF; | ||
use CSAF::Parser; | ||
|
||
our $VERSION = $CSAF::VERSION; | ||
|
||
sub cli_error { | ||
my ($error) = @_; | ||
$error =~ s/ at .* line \d+.*//; | ||
print STDERR "ERROR: $error\n"; | ||
} | ||
|
||
sub run { | ||
|
||
my ($class, @args) = @_; | ||
|
||
my %options = (); | ||
|
||
delete $ENV{CSAF_DEBUG}; | ||
|
||
GetOptionsFromArray( | ||
\@args, \%options, qw( | ||
file|f=s | ||
help|h | ||
man | ||
v | ||
) | ||
) or pod2usage(-verbose => 0); | ||
|
||
pod2usage(-exitstatus => 0, -verbose => 2) if defined $options{man}; | ||
pod2usage(-exitstatus => 0, -verbose => 0) if defined $options{help}; | ||
|
||
if (defined $options{v}) { | ||
|
||
(my $progname = $0) =~ s/.*\///; | ||
|
||
say <<"VERSION"; | ||
$progname version $CSAF::VERSION | ||
Copyright 2023-2024, Giuseppe Di Terlizzi <gdt\@cpan.org> | ||
This program is part of the CSAF distribution and is free software; | ||
you can redistribute it and/or modify it under the same terms as Perl itself. | ||
Complete documentation for $progname can be found using 'man $progname' | ||
or on the internet at <https://metacpan.org/dist/CSAF>. | ||
VERSION | ||
|
||
return 0; | ||
|
||
} | ||
|
||
my $csaf_parser_options = {}; | ||
|
||
# Detect input from STDIN | ||
if (-p STDIN || -f STDIN) { | ||
$csaf_parser_options->{content} = do { local $/; <STDIN> }; | ||
} | ||
|
||
if (defined $options{file}) { | ||
$csaf_parser_options->{file} = $options{file}; | ||
} | ||
|
||
if (%{$csaf_parser_options}) { | ||
|
||
my $csaf = eval { CSAF::Parser->new(%{$csaf_parser_options})->parse }; | ||
|
||
if ($@) { | ||
cli_error($@); | ||
return 255; | ||
} | ||
|
||
if (my @errors = $csaf->validate) { | ||
say STDERR $_ for (@errors); | ||
return 1; | ||
} | ||
|
||
say STDERR "CSAF Document valid"; | ||
return 0; | ||
|
||
} | ||
|
||
pod2usage(-verbose => 0); | ||
return 0; | ||
|
||
} | ||
|
||
1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package CSAF::Base; | |
use 5.010001; | ||
use strict; | ||
use warnings; | ||
use utf8; | ||
|
||
use Carp; | ||
use Moo; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ package CSAF::Builder; | |
use 5.010001; | ||
use strict; | ||
use warnings; | ||
use utf8; | ||
|
||
use Carp; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.