Content RunAs
RunAs Unix Accounts in Use
This recipe contains an R Markdown document that presents a table detailing the number of content items deployed to a Posit Connect server that have been configured to use a custom RunAs
Unix account.
The document uses the GET /v1/content
endpoint to obtain information about content. This API call returns every content item visible to your API key.
---
title: "RunAs in Use"
---
`RunAs` settings assigned to run content on the
This document analyzes the
Posit Connect server. The table presents the number of unique content items`RunAs` Unix account. Content using the default `RunAs`
currently using each `NA` value.
account is reported with an
```{r setup, echo = FALSE, include=FALSE}
::opts_chunk$set(echo = TRUE)
knitr```
```{r libraries, echo = FALSE, message = FALSE}
library(httr)
library(jsonlite)
library(magrittr)
library(dplyr)
library(knitr)
# Ignore summarise telling us about the grouping.
options(dplyr.summarise.inform = FALSE)
```
```{r verification, echo = FALSE}
# Confirm that environment variables are available.
<- Sys.getenv("CONNECT_SERVER")
connectServer if (nchar(connectServer) == 0) {
stop("Set the CONNECT_SERVER environment variable.")
}<- Sys.getenv("CONNECT_API_KEY")
connectAPIKey if (nchar(connectAPIKey) == 0) {
stop("Set the CONNECT_API_KEY environment variable.")
}<- paste0(connectServer, "/__api__/v1/content")
contentURL ```
```{r fetch, echo = FALSE}
# Fetch all content items from Posit Connect.
<- httr::GET(
res
contentURL,::add_headers(Authorization = paste("Key", connectAPIKey)),
httr::write_memory()
httr
)if (httr::http_error(res)) {
<- sprintf(
err "%s request failed with %s",
$request$url,
res::http_status(res)$message
httr
)message(capture.output(str(httr::content(res))))
stop(err)
}<- httr::content(res, as = "text")
payload <- jsonlite::fromJSON(payload, simplifyDataFrame = TRUE)
apps ```
```{r report, echo = FALSE}
# Report the number of content items with each RunAs user.
<- apps %>%
RunAs.accounts select(run_as) %>%
group_by(run_as) %>%
summarise(N = n()) %>%
arrange(desc(run_as)) %>%
ungroup()
kable(RunAs.accounts)
```