From 0ec20d30934a1bee42afa2859dc7cf9bb9385693 Mon Sep 17 00:00:00 2001 From: Anthony Lapenna Date: Sun, 31 Jul 2016 17:46:05 +1200 Subject: [PATCH] refactor(api): update the way keyFile parameter is managed --- api/csrf.go | 8 ++++---- api/handler.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/api/csrf.go b/api/csrf.go index 0cc8bc740..4377ee343 100644 --- a/api/csrf.go +++ b/api/csrf.go @@ -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), diff --git a/api/handler.go b/api/handler.go index 6bb16a6d5..9a6ca1059 100644 --- a/api/handler.go +++ b/api/handler.go @@ -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)