From 4e68211f227730ceadcac282b1e291095b7679ef Mon Sep 17 00:00:00 2001 From: Evan Simkowitz Date: Mon, 26 Aug 2024 13:55:47 -0700 Subject: [PATCH] make auth key header a constant --- pkg/authkey/authkey.go | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/pkg/authkey/authkey.go b/pkg/authkey/authkey.go index 26ec4a6f7..50c566d1a 100644 --- a/pkg/authkey/authkey.go +++ b/pkg/authkey/authkey.go @@ -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 -}