Example #1
0
func rktCmdCatmanifest(r *http.Request) error {
	var cmdStr string
	var rktID []string

	requestBody, err := ioutil.ReadAll(r.Body)
	if err != nil {
		logrus.Errorf("Read request body error: %s", err)
		return err
	}

	cmdStr = strings.TrimRight(string(requestBody), "\n")
	logrus.Debugf("Transforwarding request body: %s", cmdStr)

	rktID = strings.SplitAfter(r.URL.Path, "images/")
	if len(rktID) < 2 {
		return nil
	}

	rktID = strings.Split(rktID[1], "/json")
	if len(rktID) < 1 {
		return nil
	}

	cmdStr = "rkt image cat-manifest " + rktID[0]

	logrus.Debugf("The operation for rkt is : %s", cmdStr)

	err = utils.Run(exec.Command("/bin/sh", "-c", cmdStr))

	return err
}
Example #2
0
func rktCmdRmi(r *http.Request) error {
	var cmdStr string
	var imgID []string

	requestBody, err := ioutil.ReadAll(r.Body)
	if err != nil {
		logrus.Errorf("Read request body error: %s", err)
		return err
	}

	cmdStr = strings.TrimRight(string(requestBody), "\n")
	logrus.Debugf("Transforwarding request body: %s", cmdStr)

	imgID = strings.SplitAfter(r.URL.Path, "images/")
	if len(imgID) < 2 {
		return nil
	}

	if imgID[1] == "all" {
		cmdStr = "rkt image gc"
	} else {
		cmdStr = "rkt image rm " + imgID[1]
	}

	logrus.Debugf("The operation for rkt is : %s", cmdStr)

	err = utils.Run(exec.Command("/bin/sh", "-c", cmdStr))

	return err
}
Example #3
0
func rktCmdRm(r *http.Request) error {
	var cmdStr string
	var rktID []string

	requestBody, err := ioutil.ReadAll(r.Body)
	if err != nil {
		logrus.Errorf("Read request body error: %s", err)
		return err
	}

	cmdStr = strings.TrimRight(string(requestBody), "\n")
	logrus.Debugf("Transforwarding request body: %s", cmdStr)

	rktID = strings.SplitAfter(r.URL.Path, "containers/")
	if len(rktID) < 2 {
		return nil
	}

	if rktID[1] == "all" {
		cmdStr = "rkt gc"
	} else {
		cmdStr = "rkt rm --insecure-skip-verify " + rktID[1]
	}

	logrus.Debugf("The operation for rkt is : %s", cmdStr)

	err = utils.Run(exec.Command("/bin/sh", "-c", cmdStr))

	return err
}
Example #4
0
func rktCmdRun(r *http.Request) error {
	var cmdStr string
	var config UserConfig

	requestBody, err := ioutil.ReadAll(r.Body)
	if err != nil {
		logrus.Errorf("Read request body error: %s", err)
		return err
	}

	cmdStr = strings.TrimRight(string(requestBody), "\n")
	logrus.Debugf("Transforwarding request body: %s", cmdStr)
	json.Unmarshal([]byte(cmdStr), &config)

	cmdStr = "rkt " + "--interactive " + "--insecure-skip-verify " + "--mds-register=false " + "run "

	imgMatch, _ := regexp.MatchString("coreos.com", config.Image)
	if !imgMatch {
		cmdStr += "docker://" + config.Image
	} else {
		cmdStr += config.Image
	}

	logrus.Debugf("The operation for rkt is : %s", cmdStr)

	err = utils.Run(exec.Command("/bin/sh", "-c", cmdStr))

	return err
}
Example #5
0
func rktCmdVersion(r *http.Request) error {
	var cmdStr string

	requestBody, err := ioutil.ReadAll(r.Body)
	if err != nil {
		logrus.Errorf("Read request body error: %s", err)
		return err
	}

	cmdStr = strings.TrimRight(string(requestBody), "\n")
	logrus.Debugf("Transforwarding request body: %s", cmdStr)

	cmdStr = "rkt version"

	logrus.Debugf("The operation for rkt is : %s", cmdStr)

	err = utils.Run(exec.Command("/bin/sh", "-c", cmdStr))

	return err
}
Example #6
0
func rktCmdFetch(r *http.Request) error {
	var cmdStr string
	var imgID []string
	var imgStr string

	requestBody, err := ioutil.ReadAll(r.Body)
	if err != nil {
		logrus.Errorf("Read request body error: %s", err)
		return err
	}

	cmdStr = strings.TrimRight(string(requestBody), "\n")
	logrus.Debugf("Transforwarding request body: %s", cmdStr)

	url := r.URL.Query()
	imgID = url["fromImage"]

	if len(imgID) < 1 {
		return nil
	} else {
		imgStr = imgID[0]
	}

	urlMatch, _ := regexp.MatchString("coreos.com", imgStr)
	if !urlMatch {
		imgStr = "docker://" + imgStr
	}

	logrus.Debugf("The image for rkt is : %s", imgStr)

	cmdStr = "rkt fetch --insecure-skip-verify " + imgStr

	logrus.Debugf("The operation for rkt is : %s", cmdStr)

	err = utils.Run(exec.Command("/bin/sh", "-c", cmdStr))

	return err
}