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

Method provisionerJobResources

coderd/provisionerjobs.go:213–357  ·  view source on GitHub ↗
(rw http.ResponseWriter, r *http.Request, job database.ProvisionerJob)

Source from the content-addressed store, hash-verified

211}
212
213func (api *API) provisionerJobResources(rw http.ResponseWriter, r *http.Request, job database.ProvisionerJob) {
214 ctx := r.Context()
215 if !job.CompletedAt.Valid {
216 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
217 Message: "Job hasn't completed!",
218 })
219 return
220 }
221
222 // nolint:gocritic // GetWorkspaceResourcesByJobID is a system function.
223 resources, err := api.Database.GetWorkspaceResourcesByJobID(dbauthz.AsSystemRestricted(ctx), job.ID)
224 if errors.Is(err, sql.ErrNoRows) {
225 err = nil
226 }
227 if err != nil {
228 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
229 Message: "Internal error fetching job resources.",
230 Detail: err.Error(),
231 })
232 return
233 }
234 resourceIDs := make([]uuid.UUID, 0)
235 for _, resource := range resources {
236 resourceIDs = append(resourceIDs, resource.ID)
237 }
238
239 // nolint:gocritic // GetWorkspaceAgentsByResourceIDs is a system function.
240 resourceAgents, err := api.Database.GetWorkspaceAgentsByResourceIDs(dbauthz.AsSystemRestricted(ctx), resourceIDs)
241 if errors.Is(err, sql.ErrNoRows) {
242 err = nil
243 }
244 if err != nil {
245 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
246 Message: "Internal error fetching workspace agent.",
247 Detail: err.Error(),
248 })
249 return
250 }
251 resourceAgentIDs := make([]uuid.UUID, 0)
252 for _, agent := range resourceAgents {
253 resourceAgentIDs = append(resourceAgentIDs, agent.ID)
254 }
255
256 // nolint:gocritic // GetWorkspaceAppsByAgentIDs is a system function.
257 apps, err := api.Database.GetWorkspaceAppsByAgentIDs(dbauthz.AsSystemRestricted(ctx), resourceAgentIDs)
258 if errors.Is(err, sql.ErrNoRows) {
259 err = nil
260 }
261 if err != nil {
262 httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
263 Message: "Internal error fetching workspace applications.",
264 Detail: err.Error(),
265 })
266 return
267 }
268
269 // nolint:gocritic // GetWorkspaceAgentScriptsByAgentIDs is a system function.
270 scripts, err := api.Database.GetWorkspaceAgentScriptsByAgentIDs(dbauthz.AsSystemRestricted(ctx), resourceAgentIDs)

Calls 15

DERPMapMethod · 0.95
WriteFunction · 0.92
AsSystemRestrictedFunction · 0.92
WorkspaceAgentFunction · 0.92
convertProvisionedAppsFunction · 0.85
convertScriptsFunction · 0.85
convertLogSourcesFunction · 0.85
convertWorkspaceResourceFunction · 0.85
ContextMethod · 0.65

Tested by

no test coverage detected