-
Notifications
You must be signed in to change notification settings - Fork 5
feat: aibrige BYOK #216
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
base: main
Are you sure you want to change the base?
feat: aibrige BYOK #216
Changes from all commits
5a0b836
597cbf5
c7f7b60
5bdd5a0
31630d0
2cf0c26
cb9ad02
194223d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package utils | ||
|
|
||
| // MaskSecret returns the first 4 and last 4 characters of s | ||
| // separated by "...", or the full string if 8 characters or fewer. | ||
| func MaskSecret(s string) string { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this a good idea? I think logging the auth mode ("centralized", "byok_bearer", "byok_apikey") rather than a hint of the secret might be cleaner 👀
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I will definitely log and store |
||
| if len(s) <= 8 { | ||
| return s | ||
| } | ||
| return s[:4] + "..." + s[len(s)-4:] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package utils_test | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/coder/aibridge/utils" | ||
| "github.com/stretchr/testify/assert" | ||
| ) | ||
|
|
||
| func TestMaskSecret(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| tests := []struct { | ||
| input string | ||
| expected string | ||
| }{ | ||
| {"", ""}, | ||
| {"short", "short"}, | ||
| {"exactly8", "exactly8"}, | ||
| {"sk-ant-api03-abcdefgh", "sk-a...efgh"}, | ||
| {"sk-ant-oat01-abcdefghijklmnop", "sk-a...mnop"}, | ||
| } | ||
|
|
||
| for _, tc := range tests { | ||
| t.Run(tc.input, func(t *testing.T) { | ||
| t.Parallel() | ||
| assert.Equal(t, tc.expected, utils.MaskSecret(tc.input)) | ||
| }) | ||
| } | ||
| } |
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.
From this point on, we no longer know whether this interception is using a centralized (global) key or a BYOK (user's personal) API key, right? This could be useful to store and to show in the logs (the same for BYOK oauth token). For example, if Anthropic returns a 401, we wouldn't know if the failing key is the global key (affecting everyone) or a single user's personal key.
Additionally, this is probably out of scope for this PR, but it might make sense to store this information in the interception so we can later surface it in the UI, wdyt?
Uh oh!
There was an error while loading. Please reload this page.
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.
Good comment - I’ll address it in the next PR, if that’s okay.
Yes, that's correct.