posit-dev / publisher

MIT License
3 stars 0 forks source link

Add subdirectory support to config API #1860

Closed mmarchetti closed 6 days ago

mmarchetti commented 1 week ago

Intent

This PR adds support for an optional dir query parameter to the configuration API endpoints:

The directory is relative to the workspace root directory, and cannot escape it (the API should return a 400 if you provide a path that would be outside of the workspace root).

It also populates the returned configuration DTO with a new projectDir field that contains the subdirectory (again, relative to the workspace root).

This is part of #1844 and part of #1851.

Type of Change

Automated Tests

Existing tests have been updated to assert that the projectDir is correct when no dir is specified. New tests have been added specifically to test the subdirectory case for each API.

Directions for Reviewers

Run the agent in a parent directory (one or more levels up from your deployable projects). Access configuration info from subdirectories using the various APIs:

$publisher ui -vv --listen=localhost:9001 &
curl localhost:9001/api/configurations?dir=test/sample-content/quarto-proj-py | jq
curl localhost:9001/api/configurations?dir=test/sample-content/quarto-proj-none | jq

etc.

Attempt to break out of the root directory using ...

mmarchetti commented 1 week ago

If this pattern holds up, will follow up with a PR to do this for the remaining APIs called out in the linked issues.

mmarchetti commented 6 days ago

This is pretty minor all things considered, and I'm totally fine doing this as a follow-up.

I ended up implementing a fix for this, and while I was doing that, added a helper function to set up the directory and check for errors. This will also make it easier to extend the same behavior to other APIs.