mirror of https://github.com/portainer/portainer
refactor(api): update the way keyFile parameter is managed
parent
c5ddae12cf
commit
0ec20d3093
|
@ -8,10 +8,10 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
const authKeyFile = "authKey.dat"
|
const keyFile = "authKey.dat"
|
||||||
|
|
||||||
// newAuthKey reuses an existing CSRF authkey if present or generates a new one
|
// 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
|
var authKey []byte
|
||||||
authKeyPath := path + "/" + keyFile
|
authKeyPath := path + "/" + keyFile
|
||||||
data, err := ioutil.ReadFile(authKeyPath)
|
data, err := ioutil.ReadFile(authKeyPath)
|
||||||
|
@ -30,8 +30,8 @@ func newAuthKey(path string, keyFile string) []byte {
|
||||||
}
|
}
|
||||||
|
|
||||||
// newCSRF initializes a new CSRF handler
|
// newCSRF initializes a new CSRF handler
|
||||||
func newCSRFHandler(path string, keyFile string) func(h http.Handler) http.Handler {
|
func newCSRFHandler(keyPath string) func(h http.Handler) http.Handler {
|
||||||
authKey := newAuthKey(path, keyFile)
|
authKey := newAuthKey(keyPath)
|
||||||
return csrf.Protect(
|
return csrf.Protect(
|
||||||
authKey,
|
authKey,
|
||||||
csrf.HttpOnly(false),
|
csrf.HttpOnly(false),
|
||||||
|
|
|
@ -21,7 +21,7 @@ func newHandler(dir string, d string, e string, c Config, tlsFlags TLSFlags) htt
|
||||||
}
|
}
|
||||||
|
|
||||||
handler := newAPIHandler(u, tlsFlags)
|
handler := newAPIHandler(u, tlsFlags)
|
||||||
CSRFHandler := newCSRFHandler(d, authKeyFile)
|
CSRFHandler := newCSRFHandler(d)
|
||||||
|
|
||||||
mux.Handle("/dockerapi/", http.StripPrefix("/dockerapi", handler))
|
mux.Handle("/dockerapi/", http.StripPrefix("/dockerapi", handler))
|
||||||
mux.Handle("/", fileHandler)
|
mux.Handle("/", fileHandler)
|
||||||
|
|
Loading…
Reference in New Issue