// fileHandler handles /<path> to access gs://chrome-goma-log/<path>. func fileHandler(w http.ResponseWriter, req *http.Request) { ctx := appengine.NewContext(req) user := user.Current(ctx) if user == nil { http.Error(w, "Login required", http.StatusUnauthorized) return } if !strings.HasSuffix(user.Email, "@chromium.org") && strings.HasSuffix(user.Email, "@google.com") { http.Error(w, "Unauthorized to access", http.StatusUnauthorized) return } config := google.NewAppEngineConfig(ctx, []string{ "https://www.googleapis.com/auth/devstorage.read_only", }) client := &http.Client{Transport: config.NewTransport()} path := req.URL.Path resp, err := logstore.Fetch(client, path) if err != nil { ctx.Errorf("failed to fetch %s: %v", path, err) http.Error(w, err.Error(), http.StatusInternalServerError) return } defer resp.Body.Close() copyHeader(w.Header(), resp.Header) w.WriteHeader(resp.StatusCode) _, err = io.Copy(w, resp.Body) if err != nil { ctx.Errorf("failed to copy %s: %v", path, err) } }
func ninjalogFetch(client *http.Client, logPath string) (*ninjalog.NinjaLog, http.Header, error) { resp, err := logstore.Fetch(client, logPath) if err != nil { return nil, nil, err } defer resp.Body.Close() const bufsize = 512 * 1024 rd, err := gzip.NewReader(bufio.NewReaderSize(resp.Body, bufsize)) if err != nil { return nil, nil, err } nl, err := ninjalog.Parse(logPath, rd) return nl, resp.Header, err }
func compilerProxyLogFetch(client *http.Client, logPath string) (*compilerproxylog.CompilerProxyLog, error) { resp, err := logstore.Fetch(client, logPath) if err != nil { return nil, err } defer resp.Body.Close() const bufsize = 512 * 1024 rd, err := gzip.NewReader(bufio.NewReaderSize(resp.Body, bufsize)) if err != nil { return nil, err } cpl, err := compilerproxylog.Parse(logPath, rd) return cpl, nil }