From 17d4968425699fb789f4c6519f861344b02f7144 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
<41898282+github-actions[bot]@users.noreply.github.com>
Date: Tue, 7 Jun 2022 06:16:00 +0000
Subject: [PATCH 1/2] docs(README): update contributors
---
README.md | 32 ++++++++++++++++++++++++--------
1 file changed, 24 insertions(+), 8 deletions(-)
diff --git a/README.md b/README.md
index 98738bc2..a0071208 100644
--- a/README.md
+++ b/README.md
@@ -415,6 +415,15 @@ make build
Carson Yang
+
+
+
+
+ kundel
+
+ |
+
+
@@ -422,8 +431,6 @@ make build
Felix Kronlage-Dammers
|
-
-
@@ -445,6 +452,13 @@ make build
Jamie Greeff
|
+
+
+
+
+ Jiang Zhu
+
+ |
@@ -452,6 +466,8 @@ make build
Jim Tittsler
|
+
+
@@ -466,8 +482,6 @@ make build
rcursaru
|
-
-
@@ -496,6 +510,8 @@ make build
Tanner
|
+
+
@@ -510,8 +526,6 @@ make build
The Gitter Badger
|
-
-
@@ -540,6 +554,8 @@ make build
Zakhar Bessarab
|
+
+
@@ -554,8 +570,6 @@ make build
derelm
|
-
-
@@ -584,6 +598,8 @@ make build
pernila
|
+
+
From 86ce0e0c66ac7e6b57a8ee43aa151d759b1c01cb Mon Sep 17 00:00:00 2001
From: Stefan Majer
Date: Wed, 8 Jun 2022 18:09:11 +0200
Subject: [PATCH 2/2] Use strings.Cut to simplify logic
---
api_key.go | 16 +++-------------
1 file changed, 3 insertions(+), 13 deletions(-)
diff --git a/api_key.go b/api_key.go
index 41c83857..c1bbce2d 100644
--- a/api_key.go
+++ b/api_key.go
@@ -13,7 +13,6 @@ import (
const (
apiPrefixLength = 7
apiKeyLength = 32
- apiKeyParts = 2
errAPIKeyFailedToParse = Error("Failed to parse ApiKey")
)
@@ -115,9 +114,9 @@ func (h *Headscale) ExpireAPIKey(key *APIKey) error {
}
func (h *Headscale) ValidateAPIKey(keyStr string) (bool, error) {
- prefix, hash, err := splitAPIKey(keyStr)
- if err != nil {
- return false, fmt.Errorf("failed to validate api key: %w", err)
+ prefix, hash, found := strings.Cut(keyStr, ".")
+ if !found {
+ return false, errAPIKeyFailedToParse
}
key, err := h.GetAPIKey(prefix)
@@ -136,15 +135,6 @@ func (h *Headscale) ValidateAPIKey(keyStr string) (bool, error) {
return true, nil
}
-func splitAPIKey(key string) (string, string, error) {
- parts := strings.Split(key, ".")
- if len(parts) != apiKeyParts {
- return "", "", errAPIKeyFailedToParse
- }
-
- return parts[0], parts[1], nil
-}
-
func (key *APIKey) toProto() *v1.ApiKey {
protoKey := v1.ApiKey{
Id: key.ID,
|