mirror of
https://github.com/gocsaf/csaf.git
synced 2025-12-22 11:55:40 +01:00
Add support for remote validation services. (#185)
* Simple tool to test the remote validation * Added remote validator support to provider. * Added remote validation to aggregator. * Calm golint * Removed csaf_remote_validator tool as it was only for dev. * Re-added csaf_remote_validator tool. Testing is not done. * Embed the document entirely * Include testing the remote validator in the Itests * Change permission of the script * Remove code for Itests * As these will be done in another branch Co-authored-by: Fadi Abbud <fadi.abbud@intevation.de>
This commit is contained in:
parent
7cbbb4bf81
commit
78d8b89aca
16 changed files with 466 additions and 43 deletions
79
cmd/csaf_remote_validator/main.go
Normal file
79
cmd/csaf_remote_validator/main.go
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
// This file is Free Software under the MIT License
|
||||
// without warranty, see README.md and LICENSES/MIT.txt for details.
|
||||
//
|
||||
// SPDX-License-Identifier: MIT
|
||||
//
|
||||
// SPDX-FileCopyrightText: 2022 German Federal Office for Information Security (BSI) <https://www.bsi.bund.de>
|
||||
// Software-Engineering: 2022 Intevation GmbH <https://intevation.de>
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/csaf-poc/csaf_distribution/csaf"
|
||||
)
|
||||
|
||||
func loadJSONFromFile(fname string) (interface{}, error) {
|
||||
f, err := os.Open(fname)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer f.Close()
|
||||
var doc interface{}
|
||||
err = json.NewDecoder(f).Decode(&doc)
|
||||
return doc, err
|
||||
}
|
||||
|
||||
func process(options *csaf.RemoteValidatorOptions, fnames []string) error {
|
||||
validator, err := options.Open()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer validator.Close()
|
||||
|
||||
for _, fname := range fnames {
|
||||
doc, err := loadJSONFromFile(fname)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
valid, err := validator.Validate(doc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("%s: %t\n", fname, valid)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
var (
|
||||
url = flag.String("url", "", "URL to the validation service")
|
||||
presets = flag.String("presets", "", "validation presets")
|
||||
cache = flag.String("cache", "", "cache")
|
||||
)
|
||||
|
||||
flag.Parse()
|
||||
|
||||
var pres []string
|
||||
|
||||
if *presets != "" {
|
||||
pres = strings.Split(*presets, ",")
|
||||
}
|
||||
|
||||
options := csaf.RemoteValidatorOptions{
|
||||
URL: *url,
|
||||
Presets: pres,
|
||||
Cache: *cache,
|
||||
}
|
||||
|
||||
if err := process(&options, flag.Args()); err != nil {
|
||||
log.Fatalf("error: %v\n", err)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue