@Summary Get connection logs @ID get-connection-logs @Security CoderSessionToken @Produce json @Tags Enterprise @Param q query string false "Search query" @Param limit query int true "Page limit" @Param offset query int false "Page offset" @Success 200 {object} codersdk.ConnectionLogResponse @Router
(rw http.ResponseWriter, r *http.Request)
| 30 | // @Success 200 {object} codersdk.ConnectionLogResponse |
| 31 | // @Router /api/v2/connectionlog [get] |
| 32 | func (api *API) connectionLogs(rw http.ResponseWriter, r *http.Request) { |
| 33 | ctx := r.Context() |
| 34 | apiKey := httpmw.APIKey(r) |
| 35 | |
| 36 | page, ok := agpl.ParsePagination(rw, r) |
| 37 | if !ok { |
| 38 | return |
| 39 | } |
| 40 | |
| 41 | queryStr := r.URL.Query().Get("q") |
| 42 | filter, countFilter, errs := searchquery.ConnectionLogs(ctx, api.Database, queryStr, apiKey) |
| 43 | if len(errs) > 0 { |
| 44 | httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ |
| 45 | Message: "Invalid connection search query.", |
| 46 | Validations: errs, |
| 47 | }) |
| 48 | return |
| 49 | } |
| 50 | // #nosec G115 - Safe conversion as pagination offset is expected to be within int32 range |
| 51 | filter.OffsetOpt = int32(page.Offset) |
| 52 | // #nosec G115 - Safe conversion as pagination limit is expected to be within int32 range |
| 53 | filter.LimitOpt = int32(page.Limit) |
| 54 | |
| 55 | countFilter.CountCap = connectionLogCountCap |
| 56 | count, err := api.Database.CountConnectionLogs(ctx, countFilter) |
| 57 | if dbauthz.IsNotAuthorizedError(err) { |
| 58 | httpapi.Forbidden(rw) |
| 59 | return |
| 60 | } |
| 61 | if err != nil { |
| 62 | httpapi.InternalServerError(rw, err) |
| 63 | return |
| 64 | } |
| 65 | |
| 66 | if count == 0 { |
| 67 | httpapi.Write(ctx, rw, http.StatusOK, codersdk.ConnectionLogResponse{ |
| 68 | ConnectionLogs: []codersdk.ConnectionLog{}, |
| 69 | Count: 0, |
| 70 | CountCap: connectionLogCountCap, |
| 71 | }) |
| 72 | return |
| 73 | } |
| 74 | |
| 75 | dblogs, err := api.Database.GetConnectionLogsOffset(ctx, filter) |
| 76 | if dbauthz.IsNotAuthorizedError(err) { |
| 77 | httpapi.Forbidden(rw) |
| 78 | return |
| 79 | } |
| 80 | if err != nil { |
| 81 | httpapi.InternalServerError(rw, err) |
| 82 | return |
| 83 | } |
| 84 | |
| 85 | httpapi.Write(ctx, rw, http.StatusOK, codersdk.ConnectionLogResponse{ |
| 86 | ConnectionLogs: convertConnectionLogs(dblogs), |
| 87 | Count: count, |
| 88 | CountCap: connectionLogCountCap, |
| 89 | }) |
nothing calls this directly
no test coverage detected