MCPcopy Index your code
hub / github.com/coder/coder / ListApps

Function ListApps

coderd/oauth2provider/apps.go:23–59  ·  view source on GitHub ↗

ListApps returns an http.HandlerFunc that handles GET /oauth2-provider/apps

(db database.Store, accessURL *url.URL)

Source from the content-addressed store, hash-verified

21
22// ListApps returns an http.HandlerFunc that handles GET /oauth2-provider/apps
23func ListApps(db database.Store, accessURL *url.URL) http.HandlerFunc {
24 return func(rw http.ResponseWriter, r *http.Request) {
25 ctx := r.Context()
26
27 rawUserID := r.URL.Query().Get("user_id")
28 if rawUserID == "" {
29 dbApps, err := db.GetOAuth2ProviderApps(ctx)
30 if err != nil {
31 httpapi.InternalServerError(rw, err)
32 return
33 }
34 httpapi.Write(ctx, rw, http.StatusOK, db2sdk.OAuth2ProviderApps(accessURL, dbApps))
35 return
36 }
37
38 userID, err := uuid.Parse(rawUserID)
39 if err != nil {
40 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
41 Message: "Invalid user UUID",
42 Detail: fmt.Sprintf("queried user_id=%q", userID),
43 })
44 return
45 }
46
47 userApps, err := db.GetOAuth2ProviderAppsByUserID(ctx, userID)
48 if err != nil {
49 httpapi.InternalServerError(rw, err)
50 return
51 }
52
53 sdkApps := make([]codersdk.OAuth2ProviderApp, 0, len(userApps))
54 for _, app := range userApps {
55 sdkApps = append(sdkApps, db2sdk.OAuth2ProviderApp(accessURL, app.OAuth2ProviderApp))
56 }
57 httpapi.Write(ctx, rw, http.StatusOK, sdkApps)
58 }
59}
60
61// GetApp returns an http.HandlerFunc that handles GET /oauth2-provider/apps/{app}
62func GetApp(accessURL *url.URL) http.HandlerFunc {

Callers 1

oAuth2ProviderAppsMethod · 0.92

Calls 9

InternalServerErrorFunction · 0.92
WriteFunction · 0.92
OAuth2ProviderAppsFunction · 0.92
OAuth2ProviderAppFunction · 0.92
ContextMethod · 0.65
GetMethod · 0.65
GetOAuth2ProviderAppsMethod · 0.65
ParseMethod · 0.65

Tested by

no test coverage detected