Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

verify os and arch, following golang doc #57

Merged
merged 1 commit into from
May 4, 2016
Merged
Changes from all commits
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
30 changes: 26 additions & 4 deletions validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ var bundleValidateCommand = cli.Command{
var spec rspec.Spec
if err = json.NewDecoder(sf).Decode(&spec); err != nil {
logrus.Fatal(err)
} else {
if spec.Platform.OS != "linux" {
logrus.Fatalf("Operation system '%s' of the bundle is not supported yet.", spec.Platform.OS)
}
}

rootfsPath := path.Join(inputPath, spec.Root.Path)
Expand All @@ -75,6 +71,7 @@ var bundleValidateCommand = cli.Command{
} else if !fi.IsDir() {
logrus.Fatalf("Rootfs: %v is not a directory.", spec.Root.Path)
}

bundleValidate(spec, rootfsPath)
logrus.Infof("Bundle validation succeeded.")
},
Expand All @@ -83,6 +80,7 @@ var bundleValidateCommand = cli.Command{
func bundleValidate(spec rspec.Spec, rootfs string) {
checkMandatoryField(spec)
checkSemVer(spec.Version)
checkPlatform(spec.Platform)
checkProcess(spec.Process, rootfs)
checkMounts(spec.Mounts, rootfs)
checkLinux(spec.Linux, rootfs)
Expand All @@ -106,6 +104,30 @@ func checkMounts(mounts []rspec.Mount, rootfs string) {
}
}

func checkPlatform(platform rspec.Platform) {
validCombins := map[string][]string{
"darwin": {"386", "amd64", "arm", "arm64"},
"dragonfly": {"amd64"},
"freebsd": {"386", "amd64", "arm"},
"linux": {"386", "amd64", "arm", "arm64", "ppc64", "ppc64le", "mips64", "mips64le"},
"netbsd": {"386", "amd64", "arm"},
"openbsd": {"386", "amd64", "arm"},
"plan9": {"386", "amd64"},
"solaris": {"amd64"},
"windows": {"386", "amd64"}}
for os, archs := range validCombins {
if os == platform.OS {
for _, arch := range archs {
if arch == platform.Arch {
return
}
}
logrus.Fatalf("Combination of '%s' and '%s' is invalid.", platform.OS, platform.Arch)
}
}
logrus.Fatalf("Operation system '%s' of the bundle is not supported yet.", platform.OS)
}

func checkProcess(process rspec.Process, rootfs string) {
for index := 0; index < len(process.Capabilities); index++ {
capability := process.Capabilities[index]
Expand Down