mirror of
https://github.com/coder/coder.git
synced 2026-06-04 13:38:21 +00:00
ff9ed91811
This makes it so we can test it directly without having to go through Tailnet, which appears to be causing flakes in CI where the requests time out and never make it to the agent. Takes inspiration from the container-related API endpoints. Would probably make sense to refactor the ls tests to also go through the API (rather than be internal tests like they are currently) but I left those alone for now to keep the diff minimal.
37 lines
699 B
Go
37 lines
699 B
Go
package agentfiles
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/go-chi/chi/v5"
|
|
"github.com/spf13/afero"
|
|
|
|
"cdr.dev/slog/v3"
|
|
)
|
|
|
|
// API exposes file-related operations performed through the agent.
|
|
type API struct {
|
|
logger slog.Logger
|
|
filesystem afero.Fs
|
|
}
|
|
|
|
func NewAPI(logger slog.Logger, filesystem afero.Fs) *API {
|
|
api := &API{
|
|
logger: logger,
|
|
filesystem: filesystem,
|
|
}
|
|
return api
|
|
}
|
|
|
|
// Routes returns the HTTP handler for file-related routes.
|
|
func (api *API) Routes() http.Handler {
|
|
r := chi.NewRouter()
|
|
|
|
r.Post("/list-directory", api.HandleLS)
|
|
r.Get("/read-file", api.HandleReadFile)
|
|
r.Post("/write-file", api.HandleWriteFile)
|
|
r.Post("/edit-files", api.HandleEditFiles)
|
|
|
|
return r
|
|
}
|