Skip to content

Commit

Permalink
add config validate
Browse files Browse the repository at this point in the history
Signed-off-by: zhouhao <zhouhao@cn.fujitsu.com>
  • Loading branch information
zhouhao committed Oct 12, 2016
1 parent b88fd0b commit 5a87b2f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 9 additions & 3 deletions image/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
package image

import (
"crypto/sha256"
"encoding/hex"
"bytes"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -64,19 +66,23 @@ func findConfig(w walker, d *descriptor) (*config, error) {
}
}

func (c *config) validate(w walk) error {
func (c *config) validate(w walker) error {

// check if the rootfs type is 'layers'
if c.RootFS.Type != "layers" {
return errors.New("%q is an unknown rootfs type, MUST be 'layers'", c.RootFS.Type)
return errors.New("RootFs is an unknown rootfs type, MUST be 'layers'")
}

for _, d = range c.RootFs.DiffIDs {
for _, d := range c.RootFS.DiffIDs {
h := sha256.New()
DiffIds := "sha256" + hex.EncodeToString(h.Sum(nil))

if DiffIds != d {
return errors.New("DiffIDs mismatch")
}
}

return nil
}

func (c *config) runtimeSpec(rootfs string) (*specs.Spec, error) {
Expand Down
4 changes: 4 additions & 0 deletions image/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ func createRuntimeBundle(w walker, dest, refName, rootfs string) error {
return err
}

if err := c.validate(w); err != nil {
return err
}

err = m.unpack(w, filepath.Join(dest, rootfs))
if err != nil {
return err
Expand Down

0 comments on commit 5a87b2f

Please sign in to comment.