Esempio n. 1
0
func prepareAppString(app string) (string, error) {
	if err := checkColon(app); err != nil {
		return "", err
	}

	app = "name=" + strings.Replace(app, ":", ",version=", 1)
	return common.MakeQueryString(app)
}
Esempio n. 2
0
// PortFromString takes a command line port parameter and returns a port
//
// It is useful for actool patch-manifest --ports
//
// Example port parameters:
//      health-check,protocol=udp,port=8000
// 	query,protocol=tcp,port=8080,count=1,socketActivated=true
func PortFromString(pt string) (*Port, error) {
	var port Port

	pt = "name=" + pt
	ptQuery, err := common.MakeQueryString(pt)
	if err != nil {
		return nil, err
	}

	v, err := url.ParseQuery(ptQuery)
	if err != nil {
		return nil, err
	}
	for key, val := range v {
		if len(val) > 1 {
			return nil, fmt.Errorf("label %s with multiple values %q", key, val)
		}

		switch key {
		case "name":
			acn, err := NewACName(val[0])
			if err != nil {
				return nil, err
			}
			port.Name = *acn
		case "protocol":
			port.Protocol = val[0]
		case "port":
			p, err := strconv.ParseUint(val[0], 10, 16)
			if err != nil {
				return nil, err
			}
			port.Port = uint(p)
		case "count":
			cnt, err := strconv.ParseUint(val[0], 10, 16)
			if err != nil {
				return nil, err
			}
			port.Count = uint(cnt)
		case "socketActivated":
			sa, err := strconv.ParseBool(val[0])
			if err != nil {
				return nil, err
			}
			port.SocketActivated = sa
		default:
			return nil, fmt.Errorf("unknown port parameter %q", key)
		}
	}
	err = port.assertValid()
	if err != nil {
		return nil, err
	}

	return &port, nil
}
Esempio n. 3
0
// VolumeFromString takes a command line volume parameter and returns a volume
//
// Example volume parameters:
// 	database,kind=host,source=/tmp,readOnly=true,recursive=true
func VolumeFromString(vp string) (*Volume, error) {
	vp = "name=" + vp
	vpQuery, err := common.MakeQueryString(vp)
	if err != nil {
		return nil, err
	}

	v, err := url.ParseQuery(vpQuery)
	if err != nil {
		return nil, err
	}
	return VolumeFromParams(v)
}
Esempio n. 4
0
// MountPointFromString takes a command line mountpoint parameter and returns a mountpoint
//
// It is useful for actool patch-manifest --mounts
//
// Example mountpoint parameters:
// 	database,path=/tmp,readOnly=true
func MountPointFromString(mp string) (*MountPoint, error) {
	var mount MountPoint

	mp = "name=" + mp
	mpQuery, err := common.MakeQueryString(mp)
	if err != nil {
		return nil, err
	}

	v, err := url.ParseQuery(mpQuery)
	if err != nil {
		return nil, err
	}
	for key, val := range v {
		if len(val) > 1 {
			return nil, fmt.Errorf("label %s with multiple values %q", key, val)
		}

		switch key {
		case "name":
			acn, err := NewACName(val[0])
			if err != nil {
				return nil, err
			}
			mount.Name = *acn
		case "path":
			mount.Path = val[0]
		case "readOnly":
			ro, err := strconv.ParseBool(val[0])
			if err != nil {
				return nil, err
			}
			mount.ReadOnly = ro
		default:
			return nil, fmt.Errorf("unknown mountpoint parameter %q", key)
		}
	}
	err = mount.assertValid()
	if err != nil {
		return nil, err
	}

	return &mount, nil
}
Esempio n. 5
0
File: volume.go Progetto: nak3/rkt
// VolumeFromString takes a command line volume parameter and returns a volume
//
// Example volume parameters:
// 	database,kind=host,source=/tmp,readOnly=true,recursive=true
func VolumeFromString(vp string) (*Volume, error) {
	var vol Volume

	vp = "name=" + vp
	vpQuery, err := common.MakeQueryString(vp)
	if err != nil {
		return nil, err
	}

	v, err := url.ParseQuery(vpQuery)
	if err != nil {
		return nil, err
	}
	for key, val := range v {
		val := val
		if len(val) > 1 {
			return nil, fmt.Errorf("label %s with multiple values %q", key, val)
		}

		switch key {
		case "name":
			acn, err := NewACName(val[0])
			if err != nil {
				return nil, err
			}
			vol.Name = *acn
		case "kind":
			vol.Kind = val[0]
		case "source":
			vol.Source = val[0]
		case "readOnly":
			ro, err := strconv.ParseBool(val[0])
			if err != nil {
				return nil, err
			}
			vol.ReadOnly = &ro
		case "recursive":
			rec, err := strconv.ParseBool(val[0])
			if err != nil {
				return nil, err
			}
			vol.Recursive = &rec
		case "mode":
			vol.Mode = &val[0]
		case "uid":
			u, err := strconv.Atoi(val[0])
			if err != nil {
				return nil, err
			}
			vol.UID = &u
		case "gid":
			g, err := strconv.Atoi(val[0])
			if err != nil {
				return nil, err
			}
			vol.GID = &g
		default:
			return nil, fmt.Errorf("unknown volume parameter %q", key)
		}
	}

	maybeSetDefaults(&vol)

	err = vol.assertValid()
	if err != nil {
		return nil, err
	}

	return &vol, nil
}
Esempio n. 6
0
// VolumeFromString takes a command line volume parameter and returns a volume
//
// Example volume parameters:
// 	database,kind=host,source=/tmp,readOnly=true
func VolumeFromString(vp string) (*Volume, error) {
	vol := Volume{
		Mode: "0755",
		UID:  0,
		GID:  0,
	}

	vp = "name=" + vp
	vpQuery, err := common.MakeQueryString(vp)
	if err != nil {
		return nil, err
	}

	v, err := url.ParseQuery(vpQuery)
	if err != nil {
		return nil, err
	}
	for key, val := range v {
		if len(val) > 1 {
			return nil, fmt.Errorf("label %s with multiple values %q", key, val)
		}

		switch key {
		case "name":
			acn, err := NewACName(val[0])
			if err != nil {
				return nil, err
			}
			vol.Name = *acn
		case "kind":
			vol.Kind = val[0]
		case "source":
			vol.Source = val[0]
		case "readOnly":
			ro, err := strconv.ParseBool(val[0])
			if err != nil {
				return nil, err
			}
			vol.ReadOnly = &ro
		case "mode":
			vol.Mode = val[0]
		case "uid":
			u, err := strconv.Atoi(val[0])
			if err != nil {
				return nil, err
			}
			vol.UID = u
		case "gid":
			g, err := strconv.Atoi(val[0])
			if err != nil {
				return nil, err
			}
			vol.GID = g
		default:
			return nil, fmt.Errorf("unknown volume parameter %q", key)
		}
	}
	err = vol.assertValid()
	if err != nil {
		return nil, err
	}
	if vol.Kind != "empty" {
		vol.Mode = ""
		vol.UID = -1
		vol.GID = -1
	}

	return &vol, nil
}