Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions cmd/oci-runtime-tool/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ func main() {
}
app.Usage = "OCI (Open Container Initiative) runtime tools"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "compliance-level",
Value: "must",
Usage: "compliance level (may, should, or must).",
},
cli.BoolFlag{
Name: "host-specific",
Usage: "generate host-specific configs or do host-specific validations",
Expand Down
26 changes: 24 additions & 2 deletions cmd/oci-runtime-tool/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ package main
import (
"fmt"

"github.com/hashicorp/go-multierror"
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"
)

Expand All @@ -19,6 +23,12 @@ var bundleValidateCommand = cli.Command{
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)
Expand All @@ -27,8 +37,20 @@ var bundleValidateCommand = cli.Command{
}

if err := v.CheckAll(); err != nil {
return err

merr, ok := err.(*multierror.Error)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice if this was a helper function we could reuse in tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be nice if this was a helper function we could reuse in tests.

We already have FindError, which you can use like this.

I've just pushed 91aa0e9 onto this series adding a FilterError helper, in case that's what you're looking for.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've just pushed 91aa0e9

I've pushed 91aa0e9be12cce which flips the order of the FilterError response variables to keep golint happy (avoiding “error should be the last type when returning multiple items”).

if !ok {
return err
}
var validationErrors error
for _, err = range merr.Errors {
e, ok := err.(*specerror.Error)
if ok && e.Err.Level < complianceLevel {
logrus.Warn(e)
continue
}
validationErrors = multierror.Append(validationErrors, err)
}
return validationErrors
}
fmt.Println("Bundle validation succeeded.")
return nil
Expand Down
3 changes: 2 additions & 1 deletion man/oci-runtime-tool.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ oci-runtime-tool is a collection of tools for working with the [OCI runtime spec
Log level (panic, fatal, error, warn, info, or debug) (default: "error").

**--compliance-level**=LEVEL
Compliance level (may, should or must) (default: "must").
Compliance level (`may`, `should`, or `must`) (default: `must`).
For example, a SHOULD-level violation is fatal if `--compliance-level` is `may` or `should` but non-fatal if `--compliance-level` is `must`.

**-v**, **--version**
Print version information.
Expand Down