示例#1
0
文件: processes.go 项目: convox/rack
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
}
示例#2
0
文件: index.go 项目: cleblanc87/rack
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)
}
示例#3
0
文件: processes.go 项目: convox/rack
// 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)
}
示例#4
0
文件: processes.go 项目: convox/rack
// 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)
}
示例#5
0
文件: index.go 项目: gmelika/rack
// 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)
}
示例#6
0
文件: processes.go 项目: convox/rack
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
}