1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
|
package main
import (
"fmt"
"runtime"
rfc2119 "github.com/opencontainers/runtime-tools/error"
"github.com/opencontainers/runtime-tools/specerror"
"github.com/opencontainers/runtime-tools/validate"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
var bundleValidateFlags = []cli.Flag{
cli.StringFlag{Name: "path", Value: ".", Usage: "path to a bundle"},
cli.StringFlag{Name: "platform", Value: runtime.GOOS, Usage: "platform of the target bundle (linux, windows, solaris)"},
}
var bundleValidateCommand = cli.Command{
Name: "validate",
Usage: "validate an OCI bundle",
Flags: bundleValidateFlags,
Before: before,
Action: func(context *cli.Context) error {
hostSpecific := context.GlobalBool("host-specific")
complianceLevelString := context.GlobalString("compliance-level")
complianceLevel, err := rfc2119.ParseLevel(complianceLevelString)
if err != nil {
complianceLevel = rfc2119.Must
logrus.Warningf("%s, using 'MUST' by default.", err.Error())
}
inputPath := context.String("path")
platform := context.String("platform")
v, err := validate.NewValidatorFromPath(inputPath, hostSpecific, platform)
if err != nil {
return err
}
if err := v.CheckAll(); err != nil {
levelErrors, err := specerror.SplitLevel(err, complianceLevel)
if err != nil {
return err
}
for _, e := range levelErrors.Warnings {
logrus.Warn(e)
}
return levelErrors.Error.ErrorOrNil()
}
fmt.Println("Bundle validation succeeded.")
return nil
},
}
|