diff --git a/cmd/oci-image-tool/validate.go b/cmd/oci-image-tool/validate.go index 0782fa9..2798ee8 100644 --- a/cmd/oci-image-tool/validate.go +++ b/cmd/oci-image-tool/validate.go @@ -16,7 +16,6 @@ package main import ( "fmt" - "log" "os" "strings" @@ -37,9 +36,8 @@ var validateTypes = []string{ } type validateCmd struct { - stdout *log.Logger - typ string // the type to validate, can be empty string - refs []string + typ string // the type to validate, can be empty string + refs []string } var v validateCmd @@ -94,17 +92,13 @@ func validatePath(name string) error { } } - if v.stdout == nil { - v.stdout = log.New(os.Stdout, "oci-image-tool: ", 0) - } - switch typ { case image.TypeImageLayout: - return image.ValidateLayout(name, v.refs, v.stdout) + return image.ValidateLayout(name, v.refs) case image.TypeImageZip: - return image.ValidateZip(name, v.refs, v.stdout) + return image.ValidateZip(name, v.refs) case image.TypeImage: - return image.ValidateFile(name, v.refs, v.stdout) + return image.ValidateFile(name, v.refs) } if len(v.refs) != 0 { diff --git a/image/image.go b/image/image.go index e5c0fe1..6590d11 100644 --- a/image/image.go +++ b/image/image.go @@ -18,7 +18,6 @@ import ( "encoding/json" "fmt" "io" - "log" "os" "path/filepath" "strings" @@ -29,25 +28,25 @@ import ( // ValidateLayout walks through the given file tree and validates the manifest // pointed to by the given refs or returns an error if the validation failed. -func ValidateLayout(src string, refs []string, out *log.Logger) error { - return validate(newPathWalker(src), refs, out) +func ValidateLayout(src string, refs []string) error { + return validate(newPathWalker(src), refs) } // ValidateZip walks through the given file tree and validates the manifest // pointed to by the given refs or returns an error if the validation failed. -func ValidateZip(src string, refs []string, out *log.Logger) error { - return validate(newZipWalker(src), refs, out) +func ValidateZip(src string, refs []string) error { + return validate(newZipWalker(src), refs) } // ValidateFile opens the tar file given by the filename, then calls ValidateReader -func ValidateFile(tarFile string, refs []string, out *log.Logger) error { +func ValidateFile(tarFile string, refs []string) error { f, err := os.Open(tarFile) if err != nil { return errors.Wrap(err, "unable to open file") } defer f.Close() - return Validate(f, refs, out) + return Validate(f, refs) } // Validate walks through a tar stream and validates the manifest. @@ -55,8 +54,8 @@ func ValidateFile(tarFile string, refs []string, out *log.Logger) error { // * Checks that all referred blobs are valid // * Checks that mime-types are correct // returns error on validation failure -func Validate(r io.ReadSeeker, refs []string, out *log.Logger) error { - return validate(newTarWalker(r), refs, out) +func Validate(r io.ReadSeeker, refs []string) error { + return validate(newTarWalker(r), refs) } var validRefMediaTypes = []string{ @@ -64,7 +63,7 @@ var validRefMediaTypes = []string{ v1.MediaTypeImageIndex, } -func validate(w walker, refs []string, out *log.Logger) error { +func validate(w walker, refs []string) error { if err := layoutValidate(w); err != nil { return err } @@ -77,7 +76,7 @@ func validate(w walker, refs []string, out *log.Logger) error { // TODO(runcom): ugly, we'll need a better way and library // to express log levels. // see https://github.com/opencontainers/image-spec/issues/288 - out.Print("WARNING: no descriptors found") + fmt.Println("WARNING: no descriptors found") } if len(refs) == 0 { @@ -137,9 +136,7 @@ func validate(w walker, refs []string, out *log.Logger) error { } } - if out != nil { - out.Printf("reference %q: OK", ref) - } + fmt.Printf("reference %q: OK\n", ref) } return nil diff --git a/image/image_test.go b/image/image_test.go index ed73dce..c4a9963 100644 --- a/image/image_test.go +++ b/image/image_test.go @@ -237,7 +237,7 @@ func TestImageLayout(t *testing.T) { t.Fatal(err) } - err = ValidateLayout(root, refTag, nil) + err = ValidateLayout(root, refTag) if err != nil { t.Fatal(err) }