github.com/containers/libpod@v1.9.4-0.20220419124438-4284fd425507/cmd/podmanV2/common/createparse.go (about)

     1  package common
     2  
     3  import (
     4  	"github.com/containers/libpod/cmd/podmanV2/parse"
     5  	"github.com/containers/libpod/pkg/util"
     6  	"github.com/pkg/errors"
     7  )
     8  
     9  // validate determines if the flags and values given by the user are valid. things checked
    10  // by validate must not need any state information on the flag (i.e. changed)
    11  func (c *ContainerCLIOpts) validate() error {
    12  	var ()
    13  	if c.Rm && c.Restart != "" && c.Restart != "no" {
    14  		return errors.Errorf("the --rm option conflicts with --restart")
    15  	}
    16  
    17  	if _, err := util.ValidatePullType(c.Pull); err != nil {
    18  		return err
    19  	}
    20  	// Verify the additional hosts are in correct format
    21  	for _, host := range c.Net.AddHosts {
    22  		if _, err := parse.ValidateExtraHost(host); err != nil {
    23  			return err
    24  		}
    25  	}
    26  
    27  	if dnsSearches := c.Net.DNSSearch; len(dnsSearches) > 0 {
    28  		// Validate domains are good
    29  		for _, dom := range dnsSearches {
    30  			if dom == "." {
    31  				if len(dnsSearches) > 1 {
    32  					return errors.Errorf("cannot pass additional search domains when also specifying '.'")
    33  				}
    34  				continue
    35  			}
    36  			if _, err := parse.ValidateDomain(dom); err != nil {
    37  				return err
    38  			}
    39  		}
    40  	}
    41  	var imageVolType = map[string]string{
    42  		"bind":   "",
    43  		"tmpfs":  "",
    44  		"ignore": "",
    45  	}
    46  	if _, ok := imageVolType[c.ImageVolume]; !ok {
    47  		return errors.Errorf("invalid image-volume type %q. Pick one of bind, tmpfs, or ignore", c.ImageVolume)
    48  	}
    49  	return nil
    50  
    51  }