make auth key header a constant

This commit is contained in:
Evan Simkowitz
2024-08-26 13:55:47 -07:00
parent 2118c24c0d
commit 4e68211f22
+12 -11
View File
@@ -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
}