As someone who loves a good CLI, I definitely appreciate your work here! A couple of best practices to note:
- please do not delete things out of
/var/lib/rstudio-connect/apps, /var/lib/rstudio-connect/bundles or /var/lib/rstudio-connect/jobs. Ultimately, these directories also have components in the database, so you will be potentially leaving cruft scattered throughout your system that could cause problems and weird edge cases
- Also, today there is not a way to purge the packrat cache for a given application. The reason here is that the packrat cache creates potentially complex build dependencies / build trees, and we want to be very careful about creating problems.
Ultimately, if either of these directories are becoming concerning, there are many "ReapFrequency" settings that you can tweak / change inside of Connect (how long are reports maintained, how long are bundles maintained, etc.). We have several environments that we maintain internally to keep an eye out for places that are becoming concerning with respect to disk size. If something seems concerning to you, please share that feedback with us so that we can take a look at how to expose that functionality in the product in a safe fashion!
https://docs.rstudio.com/connect/admin/appendix/configuration/#Applications.BundleReapFrequency
https://docs.rstudio.com/connect/admin/appendix/configuration/#Applications.RenderingSweepLimit
That said, to your topic of a CLI to delete content. Today, I would recommend your having a look at the RStudio Connect Server API, a REST API that can be used for this type of operation. In particular, we have a publicly documented "content delete" endpoint that you can use for this task with curl. Unfortunately, the reference here is with GUIDs, which will be challenging to retrieve from disk.
https://docs.rstudio.com/connect/api/#deleteContent
There are also two common clients for this REST API. One is for use less as a CLI and more in R: https://github.com/rstudio/connectapi
The other is written in python and has a CLI associated with it: https://pypi.org/project/rsconnect-python/
However, I am not sure that it has a content delete implementation either.
What I would recommend is using the experimental "content list" endpoint if you need to get IDs and GUIDs. Since we do not have public API documentation for this endpoint, you can either look at the client implementation here:
Or build a CSV with the mapping using something like this in R:
remotes::install_github("rstuido/connectapi")
library(connectapi)
client <- connect(host = "https://myconnect.com", api_key = "my-api-key")
all_content <- get_content(client, limit = Inf)
readr::write_csv(all_content, "myfile.csv")
More details on using the RStudio Connect Server API is here: https://docs.rstudio.com/connect/cookbook/
We are definitely looking forward to improving this story by publicly documenting more of our API and increasing coverage in the various API clients. I hope this helps!! Please let us know if you run into any issues or have any follow-up questions! I will ensure this use case is shared with developers as they are taking a look at improving this part of the management ecosystem!