Beispiel #1
0
func (a *RestServer) etcdEndpoints(w http.ResponseWriter, r *http.Request) {
	logging.LogHTTPRequest(debugTag, r)

	endpointsJSON, err := json.Marshal(a.runtimeConfig.EtcdClient.Endpoints())
	if err != nil {
		io.WriteString(w, fmt.Sprintf("{'error': %s}", err))
		return
	}
	io.WriteString(w, string(endpointsJSON))
}
Beispiel #2
0
func (a *RestServer) nodesList(w http.ResponseWriter, r *http.Request) {
	logging.LogHTTPRequest(debugTag, r)

	leases, err := a.pool.Leases()
	if err != nil {
		http.Error(w, "Error in fetching lease data", 500)
	}
	nodesJSON, err := json.Marshal(leases)
	if err != nil {
		io.WriteString(w, fmt.Sprintf("{'error': %s}", err))
		return
	}
	io.WriteString(w, string(nodesJSON))
}
Beispiel #3
0
func (a *RestServer) deleteFile(w http.ResponseWriter, r *http.Request) {
	logging.LogHTTPRequest(debugTag, r)

	name := r.FormValue("name")

	if name != "" {
		err := os.Remove(filepath.Join(a.runtimeConfig.WorkspacePath, "files", name))

		if err != nil {
			http.Error(w, err.Error(), 404)

			return
		}
	} else {
		http.Error(w, "No file name specified.", 400)
	}

}
Beispiel #4
0
func (a *RestServer) upload(w http.ResponseWriter, r *http.Request) {
	logging.LogHTTPRequest(debugTag, r)

	const MaxFileSize = 1 << 30
	// This feels like a bad hack...
	if r.ContentLength > MaxFileSize {
		http.Error(w, "Request too large", 400)
		return
	}

	r.Body = http.MaxBytesReader(w, r.Body, MaxFileSize)

	err := r.ParseMultipartForm(1024)
	if err != nil {
		http.Error(w, "File too large", 400)
		return
	}

	file, header, err := r.FormFile("file")
	if err != nil {
		panic(err)
	}

	dst, err := os.Create(filepath.Join(a.runtimeConfig.WorkspacePath, "files", header.Filename))
	defer dst.Close()
	if err != nil {
		http.Error(w, err.Error(), 500)
	}

	written, err := io.Copy(dst, io.LimitReader(file, MaxFileSize))
	if err != nil {
		http.Error(w, err.Error(), 500)
	}

	if written == MaxFileSize {
		http.Error(w, "File too large", 400)
		return
	}
}
Beispiel #5
0
func (a *RestServer) files(w http.ResponseWriter, r *http.Request) {
	logging.LogHTTPRequest(debugTag, r)

	files, err := ioutil.ReadDir(filepath.Join(a.runtimeConfig.WorkspacePath, "files"))
	if err != nil {
		http.Error(w, err.Error(), 500)
	}

	var filesList []uploadedFile
	for _, f := range files {
		if f.Name()[0] == '.' {
			continue
		}
		var uploadedFile uploadedFile
		uploadedFile.Size = f.Size()
		uploadedFile.LastModificationDate = f.ModTime()
		uploadedFile.Name = f.Name()
		filesList = append(filesList, uploadedFile)
	}

	jsoned, _ := json.Marshal(filesList)
	io.WriteString(w, string(jsoned))
}
Beispiel #6
0
func (b *HTTPBooter) ldlinuxHandler(w http.ResponseWriter, r *http.Request) {
	logging.LogHTTPRequest("HTTPBOOTER", r)
	w.Header().Set("Content-Type", "application/octet-stream")
	io.Copy(w, b.ldlinux)
}