GetAppSecrets returns an http.HandlerFunc that handles GET /oauth2-provider/apps/{app}/secrets
(db database.Store)
| 16 | |
| 17 | // GetAppSecrets returns an http.HandlerFunc that handles GET /oauth2-provider/apps/{app}/secrets |
| 18 | func GetAppSecrets(db database.Store) http.HandlerFunc { |
| 19 | return func(rw http.ResponseWriter, r *http.Request) { |
| 20 | ctx := r.Context() |
| 21 | app := httpmw.OAuth2ProviderApp(r) |
| 22 | dbSecrets, err := db.GetOAuth2ProviderAppSecretsByAppID(ctx, app.ID) |
| 23 | if err != nil { |
| 24 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 25 | Message: "Internal error getting OAuth2 client secrets.", |
| 26 | Detail: err.Error(), |
| 27 | }) |
| 28 | return |
| 29 | } |
| 30 | secrets := []codersdk.OAuth2ProviderAppSecret{} |
| 31 | for _, secret := range dbSecrets { |
| 32 | secrets = append(secrets, codersdk.OAuth2ProviderAppSecret{ |
| 33 | ID: secret.ID, |
| 34 | LastUsedAt: codersdk.NullTime{NullTime: secret.LastUsedAt}, |
| 35 | ClientSecretTruncated: secret.DisplaySecret, |
| 36 | }) |
| 37 | } |
| 38 | httpapi.Write(ctx, rw, http.StatusOK, secrets) |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | // CreateAppSecret returns an http.HandlerFunc that handles POST /oauth2-provider/apps/{app}/secrets |
| 43 | func CreateAppSecret(db database.Store, auditor *audit.Auditor, logger slog.Logger) http.HandlerFunc { |
no test coverage detected