Commit 03805054 authored by Andrew Gerrand's avatar Andrew Gerrand

dashboard: add /key handler

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5504066
parent ddc85f41
...@@ -10,6 +10,6 @@ handlers: ...@@ -10,6 +10,6 @@ handlers:
script: _go_app script: _go_app
- url: /(|commit|packages|result|tag|todo) - url: /(|commit|packages|result|tag|todo)
script: _go_app script: _go_app
- url: /(init|buildtest|_ah/queue/go/delay) - url: /(init|buildtest|key|_ah/queue/go/delay)
script: _go_app script: _go_app
login: admin login: admin
...@@ -321,13 +321,10 @@ func AuthHandler(h dashHandler) http.HandlerFunc { ...@@ -321,13 +321,10 @@ func AuthHandler(h dashHandler) http.HandlerFunc {
// Validate key query parameter for POST requests only. // Validate key query parameter for POST requests only.
key := r.FormValue("key") key := r.FormValue("key")
if r.Method == "POST" && key != secretKey && !appengine.IsDevAppServer() { builder := r.FormValue("builder")
h := hmac.NewMD5([]byte(secretKey)) if r.Method == "POST" && !validKey(key, builder) {
h.Write([]byte(r.FormValue("builder")))
if key != fmt.Sprintf("%x", h.Sum()) {
err = os.NewError("invalid key: " + key) err = os.NewError("invalid key: " + key)
} }
}
// Call the original HandlerFunc and return the response. // Call the original HandlerFunc and return the response.
if err == nil { if err == nil {
...@@ -365,9 +362,19 @@ func initHandler(w http.ResponseWriter, r *http.Request) { ...@@ -365,9 +362,19 @@ func initHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, "OK") fmt.Fprint(w, "OK")
} }
func keyHandler(w http.ResponseWriter, r *http.Request) {
builder := r.FormValue("builder")
if builder == "" {
logErr(w, r, os.NewError("must supply builder in query string"))
return
}
fmt.Fprint(w, builderKey(builder))
}
func init() { func init() {
// admin handlers // admin handlers
http.HandleFunc("/init", initHandler) http.HandleFunc("/init", initHandler)
http.HandleFunc("/key", keyHandler)
// authenticated handlers // authenticated handlers
http.HandleFunc("/commit", AuthHandler(commitHandler)) http.HandleFunc("/commit", AuthHandler(commitHandler))
...@@ -385,6 +392,22 @@ func validHash(hash string) bool { ...@@ -385,6 +392,22 @@ func validHash(hash string) bool {
return hash != "" return hash != ""
} }
func validKey(key, builder string) bool {
if appengine.IsDevAppServer() {
return true
}
if key == secretKey {
return true
}
return key == builderKey(builder)
}
func builderKey(builder string) string {
h := hmac.NewMD5([]byte(secretKey))
h.Write([]byte(builder))
return fmt.Sprintf("%x", h.Sum())
}
func logErr(w http.ResponseWriter, r *http.Request, err os.Error) { func logErr(w http.ResponseWriter, r *http.Request, err os.Error) {
appengine.NewContext(r).Errorf("Error: %v", err) appengine.NewContext(r).Errorf("Error: %v", err)
w.WriteHeader(http.StatusInternalServerError) w.WriteHeader(http.StatusInternalServerError)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment