()
| 16 | ) |
| 17 | |
| 18 | func (a *agent) apiHandler() http.Handler { |
| 19 | r := chi.NewRouter() |
| 20 | r.Use( |
| 21 | httpmw.Recover(a.logger), |
| 22 | tracing.StatusWriterMiddleware, |
| 23 | loggermw.Logger(a.logger, nil), |
| 24 | agentchat.Middleware, |
| 25 | ) |
| 26 | r.Get("/", func(rw http.ResponseWriter, r *http.Request) { |
| 27 | httpapi.Write(r.Context(), rw, http.StatusOK, codersdk.Response{ |
| 28 | Message: "Hello from the agent!", |
| 29 | }) |
| 30 | }) |
| 31 | |
| 32 | r.Mount("/api/v0", a.filesAPI.Routes()) |
| 33 | r.Mount("/api/v0/git", a.gitAPI.Routes()) |
| 34 | r.Mount("/api/v0/processes", a.processAPI.Routes()) |
| 35 | r.Mount("/api/v0/desktop", a.desktopAPI.Routes()) |
| 36 | r.Mount("/api/v0/mcp", a.mcpAPI.Routes()) |
| 37 | r.Mount("/api/v0/context-config", a.contextConfigAPI.Routes()) |
| 38 | |
| 39 | if a.devcontainers { |
| 40 | r.Mount("/api/v0/containers", a.containerAPI.Routes()) |
| 41 | } else if manifest := a.manifest.Load(); manifest != nil && manifest.ParentID != uuid.Nil { |
| 42 | r.HandleFunc("/api/v0/containers", func(w http.ResponseWriter, r *http.Request) { |
| 43 | httpapi.Write(r.Context(), w, http.StatusForbidden, codersdk.Response{ |
| 44 | Message: "Dev Container feature not supported.", |
| 45 | Detail: "Dev Container integration inside other Dev Containers is explicitly not supported.", |
| 46 | }) |
| 47 | }) |
| 48 | } else { |
| 49 | r.HandleFunc("/api/v0/containers", func(w http.ResponseWriter, r *http.Request) { |
| 50 | httpapi.Write(r.Context(), w, http.StatusForbidden, codersdk.Response{ |
| 51 | Message: "Dev Container feature not enabled.", |
| 52 | Detail: "To enable this feature, set CODER_AGENT_DEVCONTAINERS_ENABLE=true in your template.", |
| 53 | }) |
| 54 | }) |
| 55 | } |
| 56 | |
| 57 | promHandler := PrometheusMetricsHandler(a.prometheusRegistry, a.logger) |
| 58 | |
| 59 | r.Get("/api/v0/listening-ports", a.listeningPortsHandler.handler) |
| 60 | r.Get("/api/v0/netcheck", a.HandleNetcheck) |
| 61 | r.Get("/debug/logs", a.HandleHTTPDebugLogs) |
| 62 | r.Get("/debug/magicsock", a.HandleHTTPDebugMagicsock) |
| 63 | r.Get("/debug/magicsock/debug-logging/{state}", a.HandleHTTPMagicsockDebugLoggingState) |
| 64 | r.Get("/debug/manifest", a.HandleHTTPDebugManifest) |
| 65 | r.Get("/debug/prometheus", promHandler.ServeHTTP) |
| 66 | |
| 67 | return r |
| 68 | } |
| 69 | |
| 70 | type ListeningPortsGetter interface { |
| 71 | GetListeningPorts() ([]codersdk.WorkspaceAgentListeningPort, error) |
no test coverage detected