diff options
author | umohnani8 <umohnani@redhat.com> | 2017-11-27 13:17:42 -0500 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2017-11-29 21:40:12 +0000 |
commit | ad255533d415393ebd119645af5c8b5a6637255f (patch) | |
tree | cce1f2053818a725f7084035a224052ab30699fa /cmd/kpod/create_cli.go | |
parent | cefa782e5067515bc38b5b3688d53f4fd9d0c70b (diff) | |
download | podman-ad255533d415393ebd119645af5c8b5a6637255f.tar.gz podman-ad255533d415393ebd119645af5c8b5a6637255f.tar.bz2 podman-ad255533d415393ebd119645af5c8b5a6637255f.zip |
Fix --volume flag for kpod create and run
Enable the --volume flag to validate user input
and add functionality for :z and :Z options
Signed-off-by: umohnani8 <umohnani@redhat.com>
Closes: #84
Approved by: mheon
Diffstat (limited to 'cmd/kpod/create_cli.go')
-rw-r--r-- | cmd/kpod/create_cli.go | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/cmd/kpod/create_cli.go b/cmd/kpod/create_cli.go index f90d530bf..9686b89a7 100644 --- a/cmd/kpod/create_cli.go +++ b/cmd/kpod/create_cli.go @@ -2,6 +2,7 @@ package main import ( "fmt" + "os" "strings" "github.com/docker/docker/pkg/sysinfo" @@ -40,6 +41,71 @@ func addWarning(warnings []string, msg string) []string { return append(warnings, msg) } +func parseVolumes(volumes []string) error { + if len(volumes) == 0 { + return nil + } + for _, volume := range volumes { + arr := strings.SplitN(volume, ":", 3) + if len(arr) < 2 { + return errors.Errorf("incorrect volume format %q, should be host-dir:ctr-dir:[option]", volume) + } + if err := validateVolumeHostDir(arr[0]); err != nil { + return err + } + if err := validateVolumeCtrDir(arr[1]); err != nil { + return err + } + if len(arr) > 2 { + if err := validateVolumeOpts(arr[2]); err != nil { + return err + } + } + } + return nil +} + +func validateVolumeHostDir(hostDir string) error { + if _, err := os.Stat(hostDir); err != nil { + return errors.Wrapf(err, "error checking path %q", hostDir) + } + return nil +} + +func validateVolumeCtrDir(ctrDir string) error { + if ctrDir[0] != '/' { + return errors.Errorf("invalid container directory path %q", ctrDir) + } + return nil +} + +func validateVolumeOpts(option string) error { + var foundRootPropagation, foundRWRO, foundLabelChange int + options := strings.Split(option, ",") + for _, opt := range options { + switch opt { + case "rw", "ro": + if foundRWRO > 1 { + return errors.Errorf("invalid options %q, can only specify 1 'rw' or 'ro' option", option) + } + foundRWRO++ + case "z", "Z": + if foundLabelChange > 1 { + return errors.Errorf("invalid options %q, can only specify 1 'z' or 'Z' option", option) + } + foundLabelChange++ + case "private", "rprivate", "shared", "rshared", "slave", "rslave": + if foundRootPropagation > 1 { + return errors.Errorf("invalid options %q, can only specify 1 '[r]shared', '[r]private' or '[r]slave' option", option) + } + foundRootPropagation++ + default: + return errors.Errorf("invalid option type %q", option) + } + } + return nil +} + func verifyContainerResources(config *createConfig, update bool) ([]string, error) { warnings := []string{} sysInfo := sysinfo.New(true) |