Esempio n. 1
0
func ProcessRunAttached(ws *websocket.Conn) *httperr.Error {
	vars := mux.Vars(ws.Request())
	header := ws.Request().Header

	app := vars["app"]
	process := vars["process"]
	command := header.Get("Command")
	release := header.Get("Release")
	height, _ := strconv.Atoi(header.Get("Height"))
	width, _ := strconv.Atoi(header.Get("Width"))

	_, err := models.Provider().ProcessRun(app, process, structs.ProcessRunOptions{
		Command: command,
		Height:  height,
		Width:   width,
		Release: release,
		Stream:  ws,
	})
	if provider.ErrorNotFound(err) {
		return httperr.New(404, err)
	}
	if err != nil {
		return httperr.Server(err)
	}

	return nil
}
Esempio n. 2
0
func IndexUpload(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	hash := mux.Vars(r)["hash"]

	file, _, err := r.FormFile("data")
	if err != nil {
		return httperr.Server(err)
	}

	data, err := ioutil.ReadAll(file)
	if err != nil {
		return httperr.Server(err)
	}

	sum := sha256.Sum256(data)

	if hash != hex.EncodeToString(sum[:]) {
		return httperr.New(403, fmt.Errorf("invalid hash"))
	}

	err = provider.IndexUpload(hash, data)
	if err != nil {
		return httperr.Server(err)
	}

	return RenderSuccess(rw)
}
Esempio n. 3
0
// ProcessStop stops a Process
func ProcessStop(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	vars := mux.Vars(r)
	app := vars["app"]
	process := vars["process"]

	err := models.Provider().ProcessStop(app, process)
	if provider.ErrorNotFound(err) {
		return httperr.New(404, err)
	}
	if err != nil {
		return httperr.Server(err)
	}

	return RenderSuccess(rw)
}
Esempio n. 4
0
// ProcessRunDetached runs a process in the background
func ProcessRunDetached(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	vars := mux.Vars(r)
	app := vars["app"]
	process := vars["process"]
	command := GetForm(r, "command")
	release := GetForm(r, "release")

	_, err := models.Provider().ProcessRun(app, process, structs.ProcessRunOptions{
		Command: command,
		Release: release,
	})
	if provider.ErrorNotFound(err) {
		return httperr.New(404, err)
	}
	if err != nil {
		return httperr.Server(err)
	}

	return RenderSuccess(rw)
}
Esempio n. 5
0
// IndexUpdate accepts a tarball of changes to the index
func IndexUpdate(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	update, _, err := r.FormFile("update")
	if err != nil {
		return httperr.Server(err)
	}

	gz, err := gzip.NewReader(update)
	if err != nil {
		return httperr.Server(err)
	}

	tr := tar.NewReader(gz)

	for {
		header, err := tr.Next()
		if err == io.EOF {
			break
		}
		if err != nil {
			return httperr.Server(err)
		}

		switch header.Typeflag {
		case tar.TypeReg:
			buf := &bytes.Buffer{}
			io.Copy(buf, tr)

			hash := sha256.Sum256(buf.Bytes())

			if header.Name != hex.EncodeToString(hash[:]) {
				return httperr.New(403, fmt.Errorf("invalid hash"))
			}

			if err := models.Provider().IndexUpload(header.Name, buf.Bytes()); err != nil {
				return httperr.Server(err)
			}
		}
	}

	return RenderSuccess(rw)
}
Esempio n. 6
0
func ProcessExecAttached(ws *websocket.Conn) *httperr.Error {
	vars := mux.Vars(ws.Request())
	header := ws.Request().Header

	app := vars["app"]
	pid := vars["pid"]
	command := header.Get("Command")
	height, _ := strconv.Atoi(header.Get("Height"))
	width, _ := strconv.Atoi(header.Get("Width"))

	err := models.Provider().ProcessExec(app, pid, command, ws, structs.ProcessExecOptions{
		Height: height,
		Width:  width,
	})
	if provider.ErrorNotFound(err) {
		return httperr.New(404, err)
	}
	if err != nil {
		return httperr.Server(err)
	}

	return nil
}