@Summary Post workspace agent log source @ID post-workspace-agent-log-source @Security CoderSessionToken @Accept json @Produce json @Tags Agents @Param request body agentsdk.PostLogSourceRequest true "Log source request" @Success 200 {object} codersdk.WorkspaceAgentLogSource @Router /api/v2/workspac
(rw http.ResponseWriter, r *http.Request)
| 1429 | // @Success 200 {object} codersdk.WorkspaceAgentLogSource |
| 1430 | // @Router /api/v2/workspaceagents/me/log-source [post] |
| 1431 | func (api *API) workspaceAgentPostLogSource(rw http.ResponseWriter, r *http.Request) { |
| 1432 | ctx := r.Context() |
| 1433 | var req agentsdk.PostLogSourceRequest |
| 1434 | if !httpapi.Read(ctx, rw, r, &req) { |
| 1435 | return |
| 1436 | } |
| 1437 | |
| 1438 | workspaceAgent := httpmw.WorkspaceAgent(r) |
| 1439 | |
| 1440 | sources, err := api.Database.InsertWorkspaceAgentLogSources(ctx, database.InsertWorkspaceAgentLogSourcesParams{ |
| 1441 | WorkspaceAgentID: workspaceAgent.ID, |
| 1442 | CreatedAt: dbtime.Now(), |
| 1443 | ID: []uuid.UUID{req.ID}, |
| 1444 | DisplayName: []string{req.DisplayName}, |
| 1445 | Icon: []string{req.Icon}, |
| 1446 | }) |
| 1447 | if err != nil { |
| 1448 | if database.IsUniqueViolation(err, "workspace_agent_log_sources_pkey") { |
| 1449 | httpapi.Write(ctx, rw, http.StatusCreated, codersdk.WorkspaceAgentLogSource{ |
| 1450 | WorkspaceAgentID: workspaceAgent.ID, |
| 1451 | CreatedAt: dbtime.Now(), |
| 1452 | ID: req.ID, |
| 1453 | DisplayName: req.DisplayName, |
| 1454 | Icon: req.Icon, |
| 1455 | }) |
| 1456 | return |
| 1457 | } |
| 1458 | httpapi.InternalServerError(rw, err) |
| 1459 | return |
| 1460 | } |
| 1461 | |
| 1462 | if len(sources) != 1 { |
| 1463 | httpapi.InternalServerError(rw, xerrors.Errorf("database should've returned 1 row, got %d", len(sources))) |
| 1464 | return |
| 1465 | } |
| 1466 | |
| 1467 | apiSource := convertLogSources(sources)[0] |
| 1468 | |
| 1469 | httpapi.Write(ctx, rw, http.StatusCreated, apiSource) |
| 1470 | } |
| 1471 | |
| 1472 | // @Summary Get workspace agent reinitialization |
| 1473 | // @ID get-workspace-agent-reinitialization |
nothing calls this directly
no test coverage detected