handleAuthAndFetchProvisionerJobs is an internal method shared by provisionerJob and provisionerJobs. If ok is false the caller should return immediately because the response has already been written.
(rw http.ResponseWriter, r *http.Request, ids []uuid.UUID)
| 94 | // provisionerJob and provisionerJobs. If ok is false the caller should |
| 95 | // return immediately because the response has already been written. |
| 96 | func (api *API) handleAuthAndFetchProvisionerJobs(rw http.ResponseWriter, r *http.Request, ids []uuid.UUID) (_ []database.GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisionerRow, ok bool) { |
| 97 | ctx := r.Context() |
| 98 | org := httpmw.OrganizationParam(r) |
| 99 | |
| 100 | // For now, only owners and template admins can access provisioner jobs. |
| 101 | if !api.Authorize(r, policy.ActionRead, rbac.ResourceProvisionerJobs.InOrg(org.ID)) { |
| 102 | httpapi.ResourceNotFound(rw) |
| 103 | return nil, false |
| 104 | } |
| 105 | |
| 106 | qp := r.URL.Query() |
| 107 | p := httpapi.NewQueryParamParser() |
| 108 | limit := p.PositiveInt32(qp, 50, "limit") |
| 109 | status := p.Strings(qp, nil, "status") |
| 110 | if ids == nil { |
| 111 | ids = p.UUIDs(qp, nil, "ids") |
| 112 | } |
| 113 | tags := p.JSONStringMap(qp, database.StringMap{}, "tags") |
| 114 | initiatorID := p.UUID(qp, uuid.Nil, "initiator") |
| 115 | p.ErrorExcessParams(qp) |
| 116 | if len(p.Errors) > 0 { |
| 117 | httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{ |
| 118 | Message: "Invalid query parameters.", |
| 119 | Validations: p.Errors, |
| 120 | }) |
| 121 | return nil, false |
| 122 | } |
| 123 | |
| 124 | jobs, err := api.Database.GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisioner(ctx, database.GetProvisionerJobsByOrganizationAndStatusWithQueuePositionAndProvisionerParams{ |
| 125 | OrganizationID: org.ID, |
| 126 | Status: slice.StringEnums[database.ProvisionerJobStatus](status), |
| 127 | Limit: sql.NullInt32{Int32: limit, Valid: limit > 0}, |
| 128 | IDs: ids, |
| 129 | Tags: tags, |
| 130 | InitiatorID: initiatorID, |
| 131 | }) |
| 132 | if err != nil { |
| 133 | if httpapi.Is404Error(err) { |
| 134 | httpapi.ResourceNotFound(rw) |
| 135 | return nil, false |
| 136 | } |
| 137 | |
| 138 | httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{ |
| 139 | Message: "Internal error fetching provisioner jobs.", |
| 140 | Detail: err.Error(), |
| 141 | }) |
| 142 | return nil, false |
| 143 | } |
| 144 | |
| 145 | return jobs, true |
| 146 | } |
| 147 | |
| 148 | // Returns provisioner logs based on query parameters. |
| 149 | // The intended usage for a client to stream all logs (with JS API): |
no test coverage detected