-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🔥 Feature: Add support for multiple keys in the KeyAuth middleware #3027
🔥 Feature: Add support for multiple keys in the KeyAuth middleware #3027
Conversation
…e way Signed-off-by: Dave Lee <[email protected]>
Signed-off-by: Dave Lee <[email protected]>
Signed-off-by: Dave Lee <[email protected]>
Thanks for opening this pull request! 🎉 Please check out our contributing guidelines. If you need help or want to chat with us, join us on Discord https://gofiber.io/discord |
WalkthroughThe recent updates enhance the Changes
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (3)
- docs/api/middleware/keyauth.md (1 hunks)
- middleware/keyauth/keyauth.go (6 hunks)
- middleware/keyauth/keyauth_test.go (1 hunks)
Additional context used
LanguageTool
docs/api/middleware/keyauth.md
[uncategorized] ~7-~7: This expression is usually spelled with a hyphen. (BASED_HYPHEN)
Context: ...Keyauth Key auth middleware provides a key based authentication. ## Signatures ```go f...
[uncategorized] ~77-~77: The abbreviation “e.g.” (= for example) requires two periods. (E_G)
Context: ...of keyauth and apply a filter function (eg.authFilter
) like so ```go package ma...
Markdownlint
docs/api/middleware/keyauth.md
21-21: Column: 1 (MD010, no-hard-tabs)
Hard tabs
22-22: Column: 1 (MD010, no-hard-tabs)
Hard tabs
23-23: Column: 1 (MD010, no-hard-tabs)
Hard tabs
24-24: Column: 1 (MD010, no-hard-tabs)
Hard tabs
28-28: Column: 1 (MD010, no-hard-tabs)
Hard tabs
32-32: Column: 1 (MD010, no-hard-tabs)
Hard tabs
33-33: Column: 1 (MD010, no-hard-tabs)
Hard tabs
35-35: Column: 1 (MD010, no-hard-tabs)
Hard tabs
36-36: Column: 1 (MD010, no-hard-tabs)
Hard tabs
37-37: Column: 1 (MD010, no-hard-tabs)
Hard tabs
38-38: Column: 1 (MD010, no-hard-tabs)
Hard tabs
42-42: Column: 1 (MD010, no-hard-tabs)
Hard tabs
44-44: Column: 1 (MD010, no-hard-tabs)
Hard tabs
45-45: Column: 1 (MD010, no-hard-tabs)
Hard tabs
46-46: Column: 1 (MD010, no-hard-tabs)
Hard tabs
47-47: Column: 1 (MD010, no-hard-tabs)
Hard tabs
48-48: Column: 1 (MD010, no-hard-tabs)
Hard tabs
50-50: Column: 1 (MD010, no-hard-tabs)
Hard tabs
51-51: Column: 1 (MD010, no-hard-tabs)
Hard tabs
52-52: Column: 1 (MD010, no-hard-tabs)
Hard tabs
54-54: Column: 1 (MD010, no-hard-tabs)
Hard tabs
83-83: Column: 1 (MD010, no-hard-tabs)
Hard tabs
84-84: Column: 1 (MD010, no-hard-tabs)
Hard tabs
85-85: Column: 1 (MD010, no-hard-tabs)
Hard tabs
86-86: Column: 1 (MD010, no-hard-tabs)
Hard tabs
87-87: Column: 1 (MD010, no-hard-tabs)
Hard tabs
88-88: Column: 1 (MD010, no-hard-tabs)
Hard tabs
92-92: Column: 1 (MD010, no-hard-tabs)
Hard tabs
93-93: Column: 1 (MD010, no-hard-tabs)
Hard tabs
94-94: Column: 1 (MD010, no-hard-tabs)
Hard tabs
95-95: Column: 1 (MD010, no-hard-tabs)
Hard tabs
96-96: Column: 1 (MD010, no-hard-tabs)
Hard tabs
100-100: Column: 1 (MD010, no-hard-tabs)
Hard tabs
101-101: Column: 1 (MD010, no-hard-tabs)
Hard tabs
103-103: Column: 1 (MD010, no-hard-tabs)
Hard tabs
104-104: Column: 1 (MD010, no-hard-tabs)
Hard tabs
105-105: Column: 1 (MD010, no-hard-tabs)
Hard tabs
106-106: Column: 1 (MD010, no-hard-tabs)
Hard tabs
110-110: Column: 1 (MD010, no-hard-tabs)
Hard tabs
112-112: Column: 1 (MD010, no-hard-tabs)
Hard tabs
113-113: Column: 1 (MD010, no-hard-tabs)
Hard tabs
114-114: Column: 1 (MD010, no-hard-tabs)
Hard tabs
115-115: Column: 1 (MD010, no-hard-tabs)
Hard tabs
116-116: Column: 1 (MD010, no-hard-tabs)
Hard tabs
117-117: Column: 1 (MD010, no-hard-tabs)
Hard tabs
121-121: Column: 1 (MD010, no-hard-tabs)
Hard tabs
123-123: Column: 1 (MD010, no-hard-tabs)
Hard tabs
124-124: Column: 1 (MD010, no-hard-tabs)
Hard tabs
125-125: Column: 1 (MD010, no-hard-tabs)
Hard tabs
126-126: Column: 1 (MD010, no-hard-tabs)
Hard tabs
127-127: Column: 1 (MD010, no-hard-tabs)
Hard tabs
129-129: Column: 1 (MD010, no-hard-tabs)
Hard tabs
130-130: Column: 1 (MD010, no-hard-tabs)
Hard tabs
131-131: Column: 1 (MD010, no-hard-tabs)
Hard tabs
132-132: Column: 1 (MD010, no-hard-tabs)
Hard tabs
133-133: Column: 1 (MD010, no-hard-tabs)
Hard tabs
134-134: Column: 1 (MD010, no-hard-tabs)
Hard tabs
135-135: Column: 1 (MD010, no-hard-tabs)
Hard tabs
136-136: Column: 1 (MD010, no-hard-tabs)
Hard tabs
137-137: Column: 1 (MD010, no-hard-tabs)
Hard tabs
139-139: Column: 1 (MD010, no-hard-tabs)
Hard tabs
165-165: Column: 1 (MD010, no-hard-tabs)
Hard tabs
166-166: Column: 1 (MD010, no-hard-tabs)
Hard tabs
167-167: Column: 1 (MD010, no-hard-tabs)
Hard tabs
168-168: Column: 1 (MD010, no-hard-tabs)
Hard tabs
176-176: Column: 1 (MD010, no-hard-tabs)
Hard tabs
178-178: Column: 1 (MD010, no-hard-tabs)
Hard tabs
179-179: Column: 1 (MD010, no-hard-tabs)
Hard tabs
180-180: Column: 1 (MD010, no-hard-tabs)
Hard tabs
181-181: Column: 1 (MD010, no-hard-tabs)
Hard tabs
183-183: Column: 1 (MD010, no-hard-tabs)
Hard tabs
184-184: Column: 1 (MD010, no-hard-tabs)
Hard tabs
185-185: Column: 1 (MD010, no-hard-tabs)
Hard tabs
186-186: Column: 1 (MD010, no-hard-tabs)
Hard tabs
187-187: Column: 1 (MD010, no-hard-tabs)
Hard tabs
188-188: Column: 1 (MD010, no-hard-tabs)
Hard tabs
190-190: Column: 1 (MD010, no-hard-tabs)
Hard tabs
191-191: Column: 1 (MD010, no-hard-tabs)
Hard tabs
192-192: Column: 1 (MD010, no-hard-tabs)
Hard tabs
194-194: Column: 1 (MD010, no-hard-tabs)
Hard tabs
195-195: Column: 1 (MD010, no-hard-tabs)
Hard tabs
196-196: Column: 1 (MD010, no-hard-tabs)
Hard tabs
198-198: Column: 1 (MD010, no-hard-tabs)
Hard tabs
230-230: Column: 1 (MD010, no-hard-tabs)
Hard tabs
231-231: Column: 1 (MD010, no-hard-tabs)
Hard tabs
232-232: Column: 1 (MD010, no-hard-tabs)
Hard tabs
233-233: Column: 1 (MD010, no-hard-tabs)
Hard tabs
234-234: Column: 1 (MD010, no-hard-tabs)
Hard tabs
235-235: Column: 1 (MD010, no-hard-tabs)
Hard tabs
236-236: Column: 1 (MD010, no-hard-tabs)
Hard tabs
237-237: Column: 1 (MD010, no-hard-tabs)
Hard tabs
238-238: Column: 1 (MD010, no-hard-tabs)
Hard tabs
239-239: Column: 1 (MD010, no-hard-tabs)
Hard tabs
240-240: Column: 1 (MD010, no-hard-tabs)
Hard tabs
241-241: Column: 1 (MD010, no-hard-tabs)
Hard tabs
74-74: Expected: 1; Actual: 2 (MD012, no-multiple-blanks)
Multiple consecutive blank lines
221-221: Expected: 4; Actual: 5; Too many cells, extra data will be missing (MD056, table-column-count)
Table column count
Additional comments not posted (5)
middleware/keyauth/keyauth.go (3)
22-22
: The new typeextractorFunc
standardizes the function signature for key extraction, which is a good practice for maintainability and consistency.
95-95
: ThekeyFromHeader
function correctly handles different authentication schemes. Good use of string slicing for extracting the token.
Line range hint
110-143
: The key extraction functions (keyFromQuery
,keyFromForm
,keyFromParam
,keyFromCookie
) are implemented consistently and handle missing keys appropriately.docs/api/middleware/keyauth.md (1)
221-221
: The updated documentation forKeyLookup
clearly explains the new functionality of supporting multiple keys separated by a pipe character. This aligns well with the code changes.Tools
Markdownlint
221-221: Expected: 4; Actual: 5; Too many cells, extra data will be missing (MD056, table-column-count)
Table column countmiddleware/keyauth/keyauth_test.go (1)
134-177
: TheTestMultipleKeyLookup
function effectively tests the new functionality of handling multiple key sources. It covers both successful and unsuccessful scenarios, ensuring robust testing.
Signed-off-by: Dave Lee <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (4)
- docs/api/middleware/keyauth.md (1 hunks)
- middleware/keyauth/config.go (2 hunks)
- middleware/keyauth/keyauth.go (7 hunks)
- middleware/keyauth/keyauth_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (2)
- middleware/keyauth/keyauth.go
- middleware/keyauth/keyauth_test.go
Additional context used
LanguageTool
docs/api/middleware/keyauth.md
[uncategorized] ~7-~7: This expression is usually spelled with a hyphen. (BASED_HYPHEN)
Context: ...Keyauth Key auth middleware provides a key based authentication. ## Signatures ```go f...
[uncategorized] ~77-~77: The abbreviation “e.g.” (= for example) requires two periods. (E_G)
Context: ...of keyauth and apply a filter function (eg.authFilter
) like so ```go package ma...
[uncategorized] ~217-~217: A punctuation mark might be missing here. (AI_EN_LECTOR_MISSING_PUNCTUATION)
Context: ...-------|:------------------------------| | Next | `func(*fiber.Ctx) boo...
[uncategorized] ~221-~221: Possible missing article found. (AI_HYDRA_LEO_MISSING_THE)
Context: ...ource>:`" that is used to extract key from the request. | "header:Authorizati...
Markdownlint
docs/api/middleware/keyauth.md
21-21: Column: 1 (MD010, no-hard-tabs)
Hard tabs
22-22: Column: 1 (MD010, no-hard-tabs)
Hard tabs
23-23: Column: 1 (MD010, no-hard-tabs)
Hard tabs
24-24: Column: 1 (MD010, no-hard-tabs)
Hard tabs
28-28: Column: 1 (MD010, no-hard-tabs)
Hard tabs
32-32: Column: 1 (MD010, no-hard-tabs)
Hard tabs
33-33: Column: 1 (MD010, no-hard-tabs)
Hard tabs
35-35: Column: 1 (MD010, no-hard-tabs)
Hard tabs
36-36: Column: 1 (MD010, no-hard-tabs)
Hard tabs
37-37: Column: 1 (MD010, no-hard-tabs)
Hard tabs
38-38: Column: 1 (MD010, no-hard-tabs)
Hard tabs
42-42: Column: 1 (MD010, no-hard-tabs)
Hard tabs
44-44: Column: 1 (MD010, no-hard-tabs)
Hard tabs
45-45: Column: 1 (MD010, no-hard-tabs)
Hard tabs
46-46: Column: 1 (MD010, no-hard-tabs)
Hard tabs
47-47: Column: 1 (MD010, no-hard-tabs)
Hard tabs
48-48: Column: 1 (MD010, no-hard-tabs)
Hard tabs
50-50: Column: 1 (MD010, no-hard-tabs)
Hard tabs
51-51: Column: 1 (MD010, no-hard-tabs)
Hard tabs
52-52: Column: 1 (MD010, no-hard-tabs)
Hard tabs
54-54: Column: 1 (MD010, no-hard-tabs)
Hard tabs
83-83: Column: 1 (MD010, no-hard-tabs)
Hard tabs
84-84: Column: 1 (MD010, no-hard-tabs)
Hard tabs
85-85: Column: 1 (MD010, no-hard-tabs)
Hard tabs
86-86: Column: 1 (MD010, no-hard-tabs)
Hard tabs
87-87: Column: 1 (MD010, no-hard-tabs)
Hard tabs
88-88: Column: 1 (MD010, no-hard-tabs)
Hard tabs
92-92: Column: 1 (MD010, no-hard-tabs)
Hard tabs
93-93: Column: 1 (MD010, no-hard-tabs)
Hard tabs
94-94: Column: 1 (MD010, no-hard-tabs)
Hard tabs
95-95: Column: 1 (MD010, no-hard-tabs)
Hard tabs
96-96: Column: 1 (MD010, no-hard-tabs)
Hard tabs
100-100: Column: 1 (MD010, no-hard-tabs)
Hard tabs
101-101: Column: 1 (MD010, no-hard-tabs)
Hard tabs
103-103: Column: 1 (MD010, no-hard-tabs)
Hard tabs
104-104: Column: 1 (MD010, no-hard-tabs)
Hard tabs
105-105: Column: 1 (MD010, no-hard-tabs)
Hard tabs
106-106: Column: 1 (MD010, no-hard-tabs)
Hard tabs
110-110: Column: 1 (MD010, no-hard-tabs)
Hard tabs
112-112: Column: 1 (MD010, no-hard-tabs)
Hard tabs
113-113: Column: 1 (MD010, no-hard-tabs)
Hard tabs
114-114: Column: 1 (MD010, no-hard-tabs)
Hard tabs
115-115: Column: 1 (MD010, no-hard-tabs)
Hard tabs
116-116: Column: 1 (MD010, no-hard-tabs)
Hard tabs
117-117: Column: 1 (MD010, no-hard-tabs)
Hard tabs
121-121: Column: 1 (MD010, no-hard-tabs)
Hard tabs
123-123: Column: 1 (MD010, no-hard-tabs)
Hard tabs
124-124: Column: 1 (MD010, no-hard-tabs)
Hard tabs
125-125: Column: 1 (MD010, no-hard-tabs)
Hard tabs
126-126: Column: 1 (MD010, no-hard-tabs)
Hard tabs
127-127: Column: 1 (MD010, no-hard-tabs)
Hard tabs
129-129: Column: 1 (MD010, no-hard-tabs)
Hard tabs
130-130: Column: 1 (MD010, no-hard-tabs)
Hard tabs
131-131: Column: 1 (MD010, no-hard-tabs)
Hard tabs
132-132: Column: 1 (MD010, no-hard-tabs)
Hard tabs
133-133: Column: 1 (MD010, no-hard-tabs)
Hard tabs
134-134: Column: 1 (MD010, no-hard-tabs)
Hard tabs
135-135: Column: 1 (MD010, no-hard-tabs)
Hard tabs
136-136: Column: 1 (MD010, no-hard-tabs)
Hard tabs
137-137: Column: 1 (MD010, no-hard-tabs)
Hard tabs
139-139: Column: 1 (MD010, no-hard-tabs)
Hard tabs
165-165: Column: 1 (MD010, no-hard-tabs)
Hard tabs
166-166: Column: 1 (MD010, no-hard-tabs)
Hard tabs
167-167: Column: 1 (MD010, no-hard-tabs)
Hard tabs
168-168: Column: 1 (MD010, no-hard-tabs)
Hard tabs
176-176: Column: 1 (MD010, no-hard-tabs)
Hard tabs
178-178: Column: 1 (MD010, no-hard-tabs)
Hard tabs
179-179: Column: 1 (MD010, no-hard-tabs)
Hard tabs
180-180: Column: 1 (MD010, no-hard-tabs)
Hard tabs
181-181: Column: 1 (MD010, no-hard-tabs)
Hard tabs
183-183: Column: 1 (MD010, no-hard-tabs)
Hard tabs
184-184: Column: 1 (MD010, no-hard-tabs)
Hard tabs
185-185: Column: 1 (MD010, no-hard-tabs)
Hard tabs
186-186: Column: 1 (MD010, no-hard-tabs)
Hard tabs
187-187: Column: 1 (MD010, no-hard-tabs)
Hard tabs
188-188: Column: 1 (MD010, no-hard-tabs)
Hard tabs
190-190: Column: 1 (MD010, no-hard-tabs)
Hard tabs
191-191: Column: 1 (MD010, no-hard-tabs)
Hard tabs
192-192: Column: 1 (MD010, no-hard-tabs)
Hard tabs
194-194: Column: 1 (MD010, no-hard-tabs)
Hard tabs
195-195: Column: 1 (MD010, no-hard-tabs)
Hard tabs
196-196: Column: 1 (MD010, no-hard-tabs)
Hard tabs
198-198: Column: 1 (MD010, no-hard-tabs)
Hard tabs
231-231: Column: 1 (MD010, no-hard-tabs)
Hard tabs
232-232: Column: 1 (MD010, no-hard-tabs)
Hard tabs
233-233: Column: 1 (MD010, no-hard-tabs)
Hard tabs
234-234: Column: 1 (MD010, no-hard-tabs)
Hard tabs
235-235: Column: 1 (MD010, no-hard-tabs)
Hard tabs
236-236: Column: 1 (MD010, no-hard-tabs)
Hard tabs
237-237: Column: 1 (MD010, no-hard-tabs)
Hard tabs
238-238: Column: 1 (MD010, no-hard-tabs)
Hard tabs
239-239: Column: 1 (MD010, no-hard-tabs)
Hard tabs
240-240: Column: 1 (MD010, no-hard-tabs)
Hard tabs
241-241: Column: 1 (MD010, no-hard-tabs)
Hard tabs
242-242: Column: 1 (MD010, no-hard-tabs)
Hard tabs
74-74: Expected: 1; Actual: 2 (MD012, no-multiple-blanks)
Multiple consecutive blank lines
Additional comments not posted (3)
middleware/keyauth/config.go (2)
35-38
: The addition ofAdditionalKeyLookups
enhances the flexibility of key source specification. Good implementation and documentation.
91-93
: InitializingAdditionalKeyLookups
to an empty slice by default is a prudent defensive programming practice.docs/api/middleware/keyauth.md (1)
222-222
: The documentation update forAdditionalKeyLookups
is clear and informative, correctly reflecting the new functionality.
Signed-off-by: Dave Lee <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- middleware/keyauth/keyauth.go (7 hunks)
Files skipped from review as they are similar to previous changes (1)
- middleware/keyauth/keyauth.go
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just two minor comments
Signed-off-by: Dave Lee <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (4)
- docs/api/middleware/keyauth.md (2 hunks)
- middleware/keyauth/config.go (2 hunks)
- middleware/keyauth/keyauth.go (7 hunks)
- middleware/keyauth/keyauth_test.go (1 hunks)
Files skipped from review as they are similar to previous changes (3)
- middleware/keyauth/config.go
- middleware/keyauth/keyauth.go
- middleware/keyauth/keyauth_test.go
Additional context used
LanguageTool
docs/api/middleware/keyauth.md
[uncategorized] ~7-~7: This expression is usually spelled with a hyphen. (BASED_HYPHEN)
Context: ...Keyauth Key auth middleware provides a key based authentication. ## Signatures ```go f...
[uncategorized] ~77-~77: The abbreviation “e.g.” (= for example) requires two periods. (E_G)
Context: ...of keyauth and apply a filter function (eg.authFilter
) like so ```go package ma...
[uncategorized] ~217-~217: A punctuation mark might be missing here. (AI_EN_LECTOR_MISSING_PUNCTUATION)
Context: ...-------|:------------------------------| | Next | `func(*fiber.Ctx) boo...
[uncategorized] ~221-~221: Possible missing article found. (AI_HYDRA_LEO_MISSING_THE)
Context: ...ource>:`" that is used to extract key from the request. | "header:Authorizati...
Markdownlint
docs/api/middleware/keyauth.md
21-21: Column: 1 (MD010, no-hard-tabs)
Hard tabs
22-22: Column: 1 (MD010, no-hard-tabs)
Hard tabs
23-23: Column: 1 (MD010, no-hard-tabs)
Hard tabs
24-24: Column: 1 (MD010, no-hard-tabs)
Hard tabs
28-28: Column: 1 (MD010, no-hard-tabs)
Hard tabs
32-32: Column: 1 (MD010, no-hard-tabs)
Hard tabs
33-33: Column: 1 (MD010, no-hard-tabs)
Hard tabs
35-35: Column: 1 (MD010, no-hard-tabs)
Hard tabs
36-36: Column: 1 (MD010, no-hard-tabs)
Hard tabs
37-37: Column: 1 (MD010, no-hard-tabs)
Hard tabs
38-38: Column: 1 (MD010, no-hard-tabs)
Hard tabs
42-42: Column: 1 (MD010, no-hard-tabs)
Hard tabs
44-44: Column: 1 (MD010, no-hard-tabs)
Hard tabs
45-45: Column: 1 (MD010, no-hard-tabs)
Hard tabs
46-46: Column: 1 (MD010, no-hard-tabs)
Hard tabs
47-47: Column: 1 (MD010, no-hard-tabs)
Hard tabs
48-48: Column: 1 (MD010, no-hard-tabs)
Hard tabs
50-50: Column: 1 (MD010, no-hard-tabs)
Hard tabs
51-51: Column: 1 (MD010, no-hard-tabs)
Hard tabs
52-52: Column: 1 (MD010, no-hard-tabs)
Hard tabs
54-54: Column: 1 (MD010, no-hard-tabs)
Hard tabs
83-83: Column: 1 (MD010, no-hard-tabs)
Hard tabs
84-84: Column: 1 (MD010, no-hard-tabs)
Hard tabs
85-85: Column: 1 (MD010, no-hard-tabs)
Hard tabs
86-86: Column: 1 (MD010, no-hard-tabs)
Hard tabs
87-87: Column: 1 (MD010, no-hard-tabs)
Hard tabs
88-88: Column: 1 (MD010, no-hard-tabs)
Hard tabs
92-92: Column: 1 (MD010, no-hard-tabs)
Hard tabs
93-93: Column: 1 (MD010, no-hard-tabs)
Hard tabs
94-94: Column: 1 (MD010, no-hard-tabs)
Hard tabs
95-95: Column: 1 (MD010, no-hard-tabs)
Hard tabs
96-96: Column: 1 (MD010, no-hard-tabs)
Hard tabs
100-100: Column: 1 (MD010, no-hard-tabs)
Hard tabs
101-101: Column: 1 (MD010, no-hard-tabs)
Hard tabs
103-103: Column: 1 (MD010, no-hard-tabs)
Hard tabs
104-104: Column: 1 (MD010, no-hard-tabs)
Hard tabs
105-105: Column: 1 (MD010, no-hard-tabs)
Hard tabs
106-106: Column: 1 (MD010, no-hard-tabs)
Hard tabs
110-110: Column: 1 (MD010, no-hard-tabs)
Hard tabs
112-112: Column: 1 (MD010, no-hard-tabs)
Hard tabs
113-113: Column: 1 (MD010, no-hard-tabs)
Hard tabs
114-114: Column: 1 (MD010, no-hard-tabs)
Hard tabs
115-115: Column: 1 (MD010, no-hard-tabs)
Hard tabs
116-116: Column: 1 (MD010, no-hard-tabs)
Hard tabs
117-117: Column: 1 (MD010, no-hard-tabs)
Hard tabs
121-121: Column: 1 (MD010, no-hard-tabs)
Hard tabs
123-123: Column: 1 (MD010, no-hard-tabs)
Hard tabs
124-124: Column: 1 (MD010, no-hard-tabs)
Hard tabs
125-125: Column: 1 (MD010, no-hard-tabs)
Hard tabs
126-126: Column: 1 (MD010, no-hard-tabs)
Hard tabs
127-127: Column: 1 (MD010, no-hard-tabs)
Hard tabs
129-129: Column: 1 (MD010, no-hard-tabs)
Hard tabs
130-130: Column: 1 (MD010, no-hard-tabs)
Hard tabs
131-131: Column: 1 (MD010, no-hard-tabs)
Hard tabs
132-132: Column: 1 (MD010, no-hard-tabs)
Hard tabs
133-133: Column: 1 (MD010, no-hard-tabs)
Hard tabs
134-134: Column: 1 (MD010, no-hard-tabs)
Hard tabs
135-135: Column: 1 (MD010, no-hard-tabs)
Hard tabs
136-136: Column: 1 (MD010, no-hard-tabs)
Hard tabs
137-137: Column: 1 (MD010, no-hard-tabs)
Hard tabs
139-139: Column: 1 (MD010, no-hard-tabs)
Hard tabs
165-165: Column: 1 (MD010, no-hard-tabs)
Hard tabs
166-166: Column: 1 (MD010, no-hard-tabs)
Hard tabs
167-167: Column: 1 (MD010, no-hard-tabs)
Hard tabs
168-168: Column: 1 (MD010, no-hard-tabs)
Hard tabs
176-176: Column: 1 (MD010, no-hard-tabs)
Hard tabs
178-178: Column: 1 (MD010, no-hard-tabs)
Hard tabs
179-179: Column: 1 (MD010, no-hard-tabs)
Hard tabs
180-180: Column: 1 (MD010, no-hard-tabs)
Hard tabs
181-181: Column: 1 (MD010, no-hard-tabs)
Hard tabs
183-183: Column: 1 (MD010, no-hard-tabs)
Hard tabs
184-184: Column: 1 (MD010, no-hard-tabs)
Hard tabs
185-185: Column: 1 (MD010, no-hard-tabs)
Hard tabs
186-186: Column: 1 (MD010, no-hard-tabs)
Hard tabs
187-187: Column: 1 (MD010, no-hard-tabs)
Hard tabs
188-188: Column: 1 (MD010, no-hard-tabs)
Hard tabs
190-190: Column: 1 (MD010, no-hard-tabs)
Hard tabs
191-191: Column: 1 (MD010, no-hard-tabs)
Hard tabs
192-192: Column: 1 (MD010, no-hard-tabs)
Hard tabs
194-194: Column: 1 (MD010, no-hard-tabs)
Hard tabs
195-195: Column: 1 (MD010, no-hard-tabs)
Hard tabs
196-196: Column: 1 (MD010, no-hard-tabs)
Hard tabs
198-198: Column: 1 (MD010, no-hard-tabs)
Hard tabs
231-231: Column: 1 (MD010, no-hard-tabs)
Hard tabs
232-232: Column: 1 (MD010, no-hard-tabs)
Hard tabs
233-233: Column: 1 (MD010, no-hard-tabs)
Hard tabs
234-234: Column: 1 (MD010, no-hard-tabs)
Hard tabs
235-235: Column: 1 (MD010, no-hard-tabs)
Hard tabs
236-236: Column: 1 (MD010, no-hard-tabs)
Hard tabs
237-237: Column: 1 (MD010, no-hard-tabs)
Hard tabs
238-238: Column: 1 (MD010, no-hard-tabs)
Hard tabs
239-239: Column: 1 (MD010, no-hard-tabs)
Hard tabs
240-240: Column: 1 (MD010, no-hard-tabs)
Hard tabs
241-241: Column: 1 (MD010, no-hard-tabs)
Hard tabs
242-242: Column: 1 (MD010, no-hard-tabs)
Hard tabs
243-243: Column: 1 (MD010, no-hard-tabs)
Hard tabs
74-74: Expected: 1; Actual: 2 (MD012, no-multiple-blanks)
Multiple consecutive blank lines
@coderabbitai full review |
Actions performedFull review triggered. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (4)
- docs/api/middleware/keyauth.md (2 hunks)
- middleware/keyauth/config.go (2 hunks)
- middleware/keyauth/keyauth.go (7 hunks)
- middleware/keyauth/keyauth_test.go (1 hunks)
Additional context used
LanguageTool
docs/api/middleware/keyauth.md
[uncategorized] ~7-~7: This expression is usually spelled with a hyphen. (BASED_HYPHEN)
Context: ...Keyauth Key auth middleware provides a key based authentication. ## Signatures ```go f...
[uncategorized] ~77-~77: The abbreviation “e.g.” (= for example) requires two periods. (E_G)
Context: ...of keyauth and apply a filter function (eg.authFilter
) like so ```go package ma...
Markdownlint
docs/api/middleware/keyauth.md
21-21: Column: 1 (MD010, no-hard-tabs)
Hard tabs
22-22: Column: 1 (MD010, no-hard-tabs)
Hard tabs
23-23: Column: 1 (MD010, no-hard-tabs)
Hard tabs
24-24: Column: 1 (MD010, no-hard-tabs)
Hard tabs
28-28: Column: 1 (MD010, no-hard-tabs)
Hard tabs
32-32: Column: 1 (MD010, no-hard-tabs)
Hard tabs
33-33: Column: 1 (MD010, no-hard-tabs)
Hard tabs
35-35: Column: 1 (MD010, no-hard-tabs)
Hard tabs
36-36: Column: 1 (MD010, no-hard-tabs)
Hard tabs
37-37: Column: 1 (MD010, no-hard-tabs)
Hard tabs
38-38: Column: 1 (MD010, no-hard-tabs)
Hard tabs
42-42: Column: 1 (MD010, no-hard-tabs)
Hard tabs
44-44: Column: 1 (MD010, no-hard-tabs)
Hard tabs
45-45: Column: 1 (MD010, no-hard-tabs)
Hard tabs
46-46: Column: 1 (MD010, no-hard-tabs)
Hard tabs
47-47: Column: 1 (MD010, no-hard-tabs)
Hard tabs
48-48: Column: 1 (MD010, no-hard-tabs)
Hard tabs
50-50: Column: 1 (MD010, no-hard-tabs)
Hard tabs
51-51: Column: 1 (MD010, no-hard-tabs)
Hard tabs
52-52: Column: 1 (MD010, no-hard-tabs)
Hard tabs
54-54: Column: 1 (MD010, no-hard-tabs)
Hard tabs
83-83: Column: 1 (MD010, no-hard-tabs)
Hard tabs
84-84: Column: 1 (MD010, no-hard-tabs)
Hard tabs
85-85: Column: 1 (MD010, no-hard-tabs)
Hard tabs
86-86: Column: 1 (MD010, no-hard-tabs)
Hard tabs
87-87: Column: 1 (MD010, no-hard-tabs)
Hard tabs
88-88: Column: 1 (MD010, no-hard-tabs)
Hard tabs
92-92: Column: 1 (MD010, no-hard-tabs)
Hard tabs
93-93: Column: 1 (MD010, no-hard-tabs)
Hard tabs
94-94: Column: 1 (MD010, no-hard-tabs)
Hard tabs
95-95: Column: 1 (MD010, no-hard-tabs)
Hard tabs
96-96: Column: 1 (MD010, no-hard-tabs)
Hard tabs
100-100: Column: 1 (MD010, no-hard-tabs)
Hard tabs
101-101: Column: 1 (MD010, no-hard-tabs)
Hard tabs
103-103: Column: 1 (MD010, no-hard-tabs)
Hard tabs
104-104: Column: 1 (MD010, no-hard-tabs)
Hard tabs
105-105: Column: 1 (MD010, no-hard-tabs)
Hard tabs
106-106: Column: 1 (MD010, no-hard-tabs)
Hard tabs
110-110: Column: 1 (MD010, no-hard-tabs)
Hard tabs
112-112: Column: 1 (MD010, no-hard-tabs)
Hard tabs
113-113: Column: 1 (MD010, no-hard-tabs)
Hard tabs
114-114: Column: 1 (MD010, no-hard-tabs)
Hard tabs
115-115: Column: 1 (MD010, no-hard-tabs)
Hard tabs
116-116: Column: 1 (MD010, no-hard-tabs)
Hard tabs
117-117: Column: 1 (MD010, no-hard-tabs)
Hard tabs
121-121: Column: 1 (MD010, no-hard-tabs)
Hard tabs
123-123: Column: 1 (MD010, no-hard-tabs)
Hard tabs
124-124: Column: 1 (MD010, no-hard-tabs)
Hard tabs
125-125: Column: 1 (MD010, no-hard-tabs)
Hard tabs
126-126: Column: 1 (MD010, no-hard-tabs)
Hard tabs
127-127: Column: 1 (MD010, no-hard-tabs)
Hard tabs
129-129: Column: 1 (MD010, no-hard-tabs)
Hard tabs
130-130: Column: 1 (MD010, no-hard-tabs)
Hard tabs
131-131: Column: 1 (MD010, no-hard-tabs)
Hard tabs
132-132: Column: 1 (MD010, no-hard-tabs)
Hard tabs
133-133: Column: 1 (MD010, no-hard-tabs)
Hard tabs
134-134: Column: 1 (MD010, no-hard-tabs)
Hard tabs
135-135: Column: 1 (MD010, no-hard-tabs)
Hard tabs
136-136: Column: 1 (MD010, no-hard-tabs)
Hard tabs
137-137: Column: 1 (MD010, no-hard-tabs)
Hard tabs
139-139: Column: 1 (MD010, no-hard-tabs)
Hard tabs
165-165: Column: 1 (MD010, no-hard-tabs)
Hard tabs
166-166: Column: 1 (MD010, no-hard-tabs)
Hard tabs
167-167: Column: 1 (MD010, no-hard-tabs)
Hard tabs
168-168: Column: 1 (MD010, no-hard-tabs)
Hard tabs
176-176: Column: 1 (MD010, no-hard-tabs)
Hard tabs
178-178: Column: 1 (MD010, no-hard-tabs)
Hard tabs
179-179: Column: 1 (MD010, no-hard-tabs)
Hard tabs
180-180: Column: 1 (MD010, no-hard-tabs)
Hard tabs
181-181: Column: 1 (MD010, no-hard-tabs)
Hard tabs
183-183: Column: 1 (MD010, no-hard-tabs)
Hard tabs
184-184: Column: 1 (MD010, no-hard-tabs)
Hard tabs
185-185: Column: 1 (MD010, no-hard-tabs)
Hard tabs
186-186: Column: 1 (MD010, no-hard-tabs)
Hard tabs
187-187: Column: 1 (MD010, no-hard-tabs)
Hard tabs
188-188: Column: 1 (MD010, no-hard-tabs)
Hard tabs
190-190: Column: 1 (MD010, no-hard-tabs)
Hard tabs
191-191: Column: 1 (MD010, no-hard-tabs)
Hard tabs
192-192: Column: 1 (MD010, no-hard-tabs)
Hard tabs
194-194: Column: 1 (MD010, no-hard-tabs)
Hard tabs
195-195: Column: 1 (MD010, no-hard-tabs)
Hard tabs
196-196: Column: 1 (MD010, no-hard-tabs)
Hard tabs
198-198: Column: 1 (MD010, no-hard-tabs)
Hard tabs
231-231: Column: 1 (MD010, no-hard-tabs)
Hard tabs
232-232: Column: 1 (MD010, no-hard-tabs)
Hard tabs
233-233: Column: 1 (MD010, no-hard-tabs)
Hard tabs
234-234: Column: 1 (MD010, no-hard-tabs)
Hard tabs
235-235: Column: 1 (MD010, no-hard-tabs)
Hard tabs
236-236: Column: 1 (MD010, no-hard-tabs)
Hard tabs
237-237: Column: 1 (MD010, no-hard-tabs)
Hard tabs
238-238: Column: 1 (MD010, no-hard-tabs)
Hard tabs
239-239: Column: 1 (MD010, no-hard-tabs)
Hard tabs
240-240: Column: 1 (MD010, no-hard-tabs)
Hard tabs
241-241: Column: 1 (MD010, no-hard-tabs)
Hard tabs
242-242: Column: 1 (MD010, no-hard-tabs)
Hard tabs
243-243: Column: 1 (MD010, no-hard-tabs)
Hard tabs
74-74: Expected: 1; Actual: 2 (MD012, no-multiple-blanks)
Multiple consecutive blank lines
Additional comments not posted (7)
middleware/keyauth/config.go (2)
35-37
: AddedFallbackKeyLookups
to handle multiple key sources.This addition aligns with the PR's objective to enhance key extraction flexibility. Ensure that the documentation and usage examples are updated accordingly to reflect this new capability.
91-93
: Ensure default value forFallbackKeyLookups
is an empty slice.This default setting prevents any unintended behavior when this field is not explicitly configured by the user.
middleware/keyauth/keyauth.go (3)
23-23
: IntroducedextractorFunc
type for key extraction functions.This type definition helps in maintaining a clean and understandable code structure by abstracting the function signature.
32-56
: EnhancedNew
function to handle multiple key sources.The implementation correctly initializes and manages multiple extractors based on the configuration. The use of a map and a loop to handle fallbacks is efficient and clear.
82-99
: Refactored key extraction intoparseSingleExtractor
.This function simplifies the process of setting up key extractors based on the
KeyLookup
configuration. The error handling and switch-case structure are appropriately used.docs/api/middleware/keyauth.md (1)
222-222
: Updated documentation to includeFallbackKeyLookups
.The documentation correctly describes the new configuration option, enhancing the understanding of the middleware's capabilities.
middleware/keyauth/keyauth_test.go (1)
134-178
: AddedTestMultipleKeyLookup
to verify multiple key lookup functionality.This test effectively checks the functionality of extracting keys from multiple sources, ensuring that the middleware behaves as expected under different configurations.
@dave-gray101 I just realized this is on the v2 branch, we are not adding any new features for v2. The target branch would have to be changed to v3 |
Ah, that's unfortunate. I had dropped a question in the discord a few days ago regarding that, and didn't get a reply and figured I'd just create it rather than wait :D I based this branch off of v2, mostly as a guess. I'll try changing the target here, but it may be cleaner to re-apply off v3. Edit: It's a huge mess due to the age of the source branch. I'll create a new one based on main and link it below. |
Description
I'm working on a project that must accept api keys from multiple possible sources, such as different header names. I've implemented this by slightly modifying the existing keyauth middleware, and I'd like to contribute it upstream.
Changes introduced
This is a fairly minimal enhancement to the existing
keyauth
middleware. I have extracted the existingextractor
assignment code into a private function, and added a new[]string
parameter to Config namedAdditionalKeyLookups
. Any values set here are interpreted just likeKeyLookup
, and are checked in order if there is no API key found atKeyLookup
Type of change
Please delete options that are not relevant.