go.tools/dashboard/app: reject /commit requests from old builders
This is so that we don't corrupt our commit history with reports from old builders, after the migration to the latest build dashboard. LGTM=dvyukov R=dvyukov CC=golang-codereviews https://golang.org/cl/130300043
This commit is contained in:
parent
5d476c5293
commit
c21a767b2c
|
|
@ -7,11 +7,13 @@
|
||||||
package build
|
package build
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"crypto/hmac"
|
"crypto/hmac"
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode/utf8"
|
"unicode/utf8"
|
||||||
|
|
@ -58,9 +60,17 @@ func commitHandler(r *http.Request) (interface{}, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// POST request
|
// POST request
|
||||||
defer r.Body.Close()
|
body, err := ioutil.ReadAll(r.Body)
|
||||||
if err := json.NewDecoder(r.Body).Decode(com); err != nil {
|
r.Body.Close()
|
||||||
return nil, fmt.Errorf("decoding Body: %v", err)
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("reading Body: %v", err)
|
||||||
|
}
|
||||||
|
if !bytes.Contains(body, needsBenchmarkingBytes) {
|
||||||
|
c.Warningf("old builder detected at %v", r.RemoteAddr)
|
||||||
|
return nil, fmt.Errorf("rejecting old builder request, body does not contain %s: %q", needsBenchmarkingBytes, body)
|
||||||
|
}
|
||||||
|
if err := json.Unmarshal(body, com); err != nil {
|
||||||
|
return nil, fmt.Errorf("unmarshaling body %q: %v", body, err)
|
||||||
}
|
}
|
||||||
com.Desc = limitStringLength(com.Desc, maxDatastoreStringLen)
|
com.Desc = limitStringLength(com.Desc, maxDatastoreStringLen)
|
||||||
if err := com.Valid(); err != nil {
|
if err := com.Valid(); err != nil {
|
||||||
|
|
@ -73,6 +83,8 @@ func commitHandler(r *http.Request) (interface{}, error) {
|
||||||
return nil, datastore.RunInTransaction(c, tx, nil)
|
return nil, datastore.RunInTransaction(c, tx, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var needsBenchmarkingBytes = []byte(`"NeedsBenchmarking"`)
|
||||||
|
|
||||||
// addCommit adds the Commit entity to the datastore and updates the tip Tag.
|
// addCommit adds the Commit entity to the datastore and updates the tip Tag.
|
||||||
// It must be run inside a datastore transaction.
|
// It must be run inside a datastore transaction.
|
||||||
func addCommit(c appengine.Context, com *Commit) error {
|
func addCommit(c appengine.Context, com *Commit) error {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue