Exemplo n.º 1
0
func ninjalogUpload(w http.ResponseWriter, req *http.Request) {
	ctx := appengine.NewContext(req)
	u := user.Current(ctx)
	if u == nil {
		http.Error(w, "unauthorized", http.StatusUnauthorized)
		return
	}
	// TODO(ukai): allow only @google.com and @chromium.org?
	ctx.Infof("upload by %s", u.Email)
	f, _, err := req.FormFile("file")
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}
	defer f.Close()
	njl, err := ninjalog.Parse("ninja_log", f)
	if err != nil {
		ctx.Errorf("bad format: %v", err)
		http.Error(w, fmt.Sprintf("malformed ninja_log file %v", err), http.StatusBadRequest)
		return
	}
	var data bytes.Buffer
	err = ninjalog.Dump(&data, njl.Steps)
	if err != nil {
		ctx.Errorf("dump error: %v", err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	config := google.NewAppEngineConfig(ctx, []string{
		"https://www.googleapis.com/auth/devstorage.read_write",
	})
	client := &http.Client{Transport: config.NewTransport()}

	logPath, err := logstore.Upload(client, "ninja_log", data.Bytes())
	if err != nil {
		ctx.Errorf("upload error: %v", err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	ctx.Infof("%s upload to %s", u.Email, logPath)

	if req.FormValue("trace") != "" {
		http.Redirect(w, req, "/ninja_log/"+logPath+"/trace.html", http.StatusSeeOther)
		return
	}
	http.Redirect(w, req, "/ninja_log/"+logPath, http.StatusSeeOther)
}
Exemplo n.º 2
0
func lastBuild(w http.ResponseWriter, logPath string, njl *ninjalog.NinjaLog) error {
	w.Header().Set("Content-Type", "text/plain")
	w.WriteHeader(http.StatusOK)
	return ninjalog.Dump(w, njl.Steps)
}