Skip to content

Commit 506ea20

Browse files
authored
chore: remove GitHub group support (#763)
Signed-off-by: Grant Linville <grant@acorn.io>
1 parent 7859d4b commit 506ea20

File tree

2 files changed

+0
-139
lines changed

2 files changed

+0
-139
lines changed

github-auth-provider/main.go

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
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

2422
type 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-
}

github-auth-provider/pkg/profile/profile.go

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ import (
66
"fmt"
77
"io"
88
"net/http"
9-
"slices"
10-
"strings"
11-
12-
"github.com/obot-platform/tools/auth-providers-common/pkg/state"
139
)
1410

1511
var githubBaseURL = "https://api.github.com"
@@ -49,18 +45,6 @@ type githubUserProfile struct {
4945
UpdatedAt string `json:"updated_at"`
5046
}
5147

52-
type githubOrganization struct {
53-
ID int64 `json:"id"`
54-
Login string `json:"login"`
55-
AvatarURL string `json:"avatar_url"`
56-
}
57-
58-
type githubTeam struct {
59-
ID int64 `json:"id"`
60-
Slug string `json:"slug"`
61-
Organization githubOrganization `json:"organization"`
62-
}
63-
6448
func FetchUserProfile(ctx context.Context, accessToken string) (*githubUserProfile, error) {
6549
var result githubUserProfile
6650
err := makeGitHubRequest(ctx, accessToken, "user", &result)
@@ -70,44 +54,6 @@ func FetchUserProfile(ctx context.Context, accessToken string) (*githubUserProfi
7054
return &result, nil
7155
}
7256

73-
func FetchUserGroupInfos(ctx context.Context, accessToken string) (state.GroupInfoList, error) {
74-
var (
75-
infos state.GroupInfoList
76-
orgs []githubOrganization
77-
)
78-
err := makeGitHubRequest(ctx, accessToken, "user/orgs", &orgs)
79-
if err != nil {
80-
return nil, fmt.Errorf("failed to fetch user organizations: %w", err)
81-
}
82-
for _, org := range orgs {
83-
infos = append(infos, state.GroupInfo{
84-
ID: fmt.Sprintf("github/org/%d", org.ID),
85-
Name: org.Login,
86-
IconURL: &org.AvatarURL,
87-
})
88-
}
89-
90-
var teams []githubTeam
91-
err = makeGitHubRequest(ctx, accessToken, "user/teams", &teams)
92-
if err != nil {
93-
return nil, fmt.Errorf("failed to fetch user teams: %w", err)
94-
}
95-
for _, team := range teams {
96-
infos = append(infos, state.GroupInfo{
97-
ID: fmt.Sprintf("github/org/%d/team/%d", team.Organization.ID, team.ID),
98-
Name: fmt.Sprintf("%s/%s", team.Organization.Login, team.Slug),
99-
IconURL: &team.Organization.AvatarURL,
100-
})
101-
}
102-
103-
// Sort groups by ID lexicographically
104-
slices.SortFunc(infos, func(a, b state.GroupInfo) int {
105-
return strings.Compare(a.ID, b.ID)
106-
})
107-
108-
return infos, nil
109-
}
110-
11157
func makeGitHubRequest(ctx context.Context, accessToken, path string, result any) error {
11258
req, err := http.NewRequestWithContext(ctx, http.MethodGet, fmt.Sprintf("%s/%s", githubBaseURL, path), nil)
11359
if err != nil {

0 commit comments

Comments
 (0)