mirror of
https://github.com/wavetermdev/backup.git
synced 2026-04-22 15:26:58 -07:00
make auth key header a constant
This commit is contained in:
+12
-11
@@ -12,6 +12,18 @@ import (
|
||||
var authkey string
|
||||
|
||||
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 {
|
||||
authkey = os.Getenv(AuthKeyEnv)
|
||||
@@ -25,14 +37,3 @@ func SetAuthKeyFromEnv() error {
|
||||
func GetAuthKey() string {
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user