77 "fmt"
88 "net/http"
99 "os"
10- "slices"
1110 "strings"
1211 "time"
1312
@@ -18,7 +17,6 @@ import (
1817 "github.com/obot-platform/tools/auth-providers-common/pkg/env"
1918 "github.com/obot-platform/tools/auth-providers-common/pkg/state"
2019 "github.com/obot-platform/tools/github-auth-provider/pkg/profile"
21- "github.com/sahilm/fuzzy"
2220)
2321
2422type Options struct {
@@ -132,8 +130,6 @@ func main() {
132130 }
133131 json .NewEncoder (w ).Encode (userInfo )
134132 })
135- mux .HandleFunc ("/obot-list-auth-groups" , listGroups (opts .GitHubOrg ))
136- mux .HandleFunc ("/obot-list-user-auth-groups" , listUserGroups )
137133 mux .HandleFunc ("/" , oauthProxy .ServeHTTP )
138134
139135 fmt .Printf ("listening on 127.0.0.1:%s\n " , port )
@@ -208,84 +204,3 @@ func getState(p *oauth2proxy.OAuthProxy) http.HandlerFunc {
208204 }
209205 }
210206}
211-
212- func listGroups (restrictOrg * string ) http.HandlerFunc {
213- return func (w http.ResponseWriter , r * http.Request ) {
214- token := r .Header .Get ("Authorization" )
215- if token == "" {
216- http .Error (w , "no authorization token provided" , http .StatusUnauthorized )
217- return
218- }
219-
220- groups , err := profile .FetchUserGroupInfos (r .Context (), token )
221- if err != nil {
222- http .Error (w , fmt .Sprintf ("failed to fetch user auth groups: %v" , err ), http .StatusInternalServerError )
223- return
224- }
225-
226- // Handle nil groups slice
227- if groups == nil {
228- groups = state.GroupInfoList {}
229- }
230-
231- if restrictOrg != nil && * restrictOrg != "" {
232- // Elide all org and team groups that don't match the restrictOrg when set
233- groups = slices .DeleteFunc (groups , func (g state.GroupInfo ) bool {
234- orgLogin , _ , _ := strings .Cut (g .Name , "/" )
235- return orgLogin != * restrictOrg
236- })
237- }
238-
239- // Get the name query parameter for filtering
240- nameFilter := r .URL .Query ().Get ("name" )
241- if nameFilter != "" && len (groups ) > 0 {
242- // Create a slice of group names for fuzzy matching
243- groupNames := make ([]string , len (groups ))
244- for i , group := range groups {
245- groupNames [i ] = group .Name
246- }
247-
248- // Perform fuzzy search - results are automatically ranked by relevance
249- matches := fuzzy .Find (nameFilter , groupNames )
250-
251- // Filter groups based on fuzzy matches, preserving the relevance order
252- var filteredGroups state.GroupInfoList
253- for _ , match := range matches {
254- filteredGroups = append (filteredGroups , groups [match .Index ])
255- }
256- groups = filteredGroups
257- }
258-
259- if err := json .NewEncoder (w ).Encode (groups ); err != nil {
260- http .Error (w , fmt .Sprintf ("failed to encode groups: %v" , err ), http .StatusInternalServerError )
261- return
262- }
263- }
264- }
265-
266- func listUserGroups (w http.ResponseWriter , r * http.Request ) {
267- token := r .Header .Get ("Authorization" )
268- if token == "" {
269- http .Error (w , "no authorization token provided" , http .StatusUnauthorized )
270- return
271- }
272-
273- groups , err := profile .FetchUserGroupInfos (r .Context (), token )
274- if err != nil {
275- http .Error (w , fmt .Sprintf ("failed to fetch user auth groups: %v" , err ), http .StatusInternalServerError )
276- return
277- }
278-
279- // Handle nil groups slice
280- if groups == nil {
281- groups = state.GroupInfoList {}
282- }
283-
284- // Note: Don't elide org and team groups because removing them here would cause Obot to drop
285- // group membership for the respective user and would cause ACR's to garbage collect MCP servers and
286- // server instances. In this case we want admins to manually clean up group based ACRs.
287- if err := json .NewEncoder (w ).Encode (groups ); err != nil {
288- http .Error (w , fmt .Sprintf ("failed to encode groups: %v" , err ), http .StatusInternalServerError )
289- return
290- }
291- }
0 commit comments