mirror of
https://github.com/wavetermdev/waveterm.git
synced 2025-01-02 18:39:05 +01:00
make auth key header a constant
This commit is contained in:
parent
2118c24c0d
commit
4e68211f22
@ -12,6 +12,18 @@ import (
|
|||||||
var authkey string
|
var authkey string
|
||||||
|
|
||||||
const AuthKeyEnv = "AUTH_KEY"
|
const AuthKeyEnv = "AUTH_KEY"
|
||||||
|
const AuthKeyHeader = "X-AuthKey"
|
||||||
|
|
||||||
|
func ValidateIncomingRequest(r *http.Request) error {
|
||||||
|
reqAuthKey := r.Header.Get(AuthKeyHeader)
|
||||||
|
if reqAuthKey == "" {
|
||||||
|
return fmt.Errorf("no x-authkey header")
|
||||||
|
}
|
||||||
|
if reqAuthKey != GetAuthKey() {
|
||||||
|
return fmt.Errorf("x-authkey header is invalid")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func SetAuthKeyFromEnv() error {
|
func SetAuthKeyFromEnv() error {
|
||||||
authkey = os.Getenv(AuthKeyEnv)
|
authkey = os.Getenv(AuthKeyEnv)
|
||||||
@ -25,14 +37,3 @@ func SetAuthKeyFromEnv() error {
|
|||||||
func GetAuthKey() string {
|
func GetAuthKey() string {
|
||||||
return authkey
|
return authkey
|
||||||
}
|
}
|
||||||
|
|
||||||
func ValidateIncomingRequest(r *http.Request) error {
|
|
||||||
reqAuthKey := r.Header.Get("X-AuthKey")
|
|
||||||
if reqAuthKey == "" {
|
|
||||||
return fmt.Errorf("no x-authkey header")
|
|
||||||
}
|
|
||||||
if reqAuthKey != GetAuthKey() {
|
|
||||||
return fmt.Errorf("x-authkey header is invalid")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user