add white list to both master and volume servers

prepare for v0.41
This commit is contained in:
Chris Lu
2013-08-13 09:31:19 -07:00
parent 3572e1140e
commit e45c6b5e21
4 changed files with 46 additions and 41 deletions

View File

@@ -7,6 +7,7 @@ import (
"fmt"
"io"
"math/rand"
"net"
"net/http"
"os"
"strings"
@@ -223,3 +224,21 @@ func debug(params ...interface{}) {
glog.V(0).Infoln(params)
}
}
func secure(whiteList []string, f func(w http.ResponseWriter, r *http.Request)) func(w http.ResponseWriter, r *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
if len(whiteList) == 0 {
f(w, r)
return
}
host, _, err := net.SplitHostPort(r.RemoteAddr)
if err == nil {
for _, ip := range whiteList {
if ip == host {
f(w, r)
return
}
}
}
writeJsonQuiet(w, r, map[string]interface{}{"error": "No write permisson from " + host})
}
}