refactor(api): update the way keyFile parameter is managed

pull/94/head
Anthony Lapenna 2016-07-31 17:46:05 +12:00
parent c5ddae12cf
commit 0ec20d3093
2 changed files with 5 additions and 5 deletions

View File

@ -8,10 +8,10 @@ import (
"net/http"
)
const authKeyFile = "authKey.dat"
const keyFile = "authKey.dat"
// newAuthKey reuses an existing CSRF authkey if present or generates a new one
func newAuthKey(path string, keyFile string) []byte {
func newAuthKey(path string) []byte {
var authKey []byte
authKeyPath := path + "/" + keyFile
data, err := ioutil.ReadFile(authKeyPath)
@ -30,8 +30,8 @@ func newAuthKey(path string, keyFile string) []byte {
}
// newCSRF initializes a new CSRF handler
func newCSRFHandler(path string, keyFile string) func(h http.Handler) http.Handler {
authKey := newAuthKey(path, keyFile)
func newCSRFHandler(keyPath string) func(h http.Handler) http.Handler {
authKey := newAuthKey(keyPath)
return csrf.Protect(
authKey,
csrf.HttpOnly(false),

View File

@ -21,7 +21,7 @@ func newHandler(dir string, d string, e string, c Config, tlsFlags TLSFlags) htt
}
handler := newAPIHandler(u, tlsFlags)
CSRFHandler := newCSRFHandler(d, authKeyFile)
CSRFHandler := newCSRFHandler(d)
mux.Handle("/dockerapi/", http.StripPrefix("/dockerapi", handler))
mux.Handle("/", fileHandler)