Finding Content with Custom Runtime Settings
Problem
You want to find the content items with customized runtime settings.
Content with custom runtime settings includes content with RunAsCurrentUser
enabled and content with a custom RunAs
Linux user account.
Solution
Get a table of data for all content on the server, and transform it into a table with columns for content GUID, RunAs
setting, title, owner username, and Dashboard URL. Filter it to include only content with custom RunAs
settings.
from posit import connect
import polars as pl
= connect.Client()
client
= client.content.find()
all_content = (pl.DataFrame(all_content, infer_schema_length=None)
content # combine RunAsCurrentUser and RunAs into a single column
"run_as_current_user") == "true")
.with_columns(pl.when(pl.col("RunAsCurrentUser"))
.then(pl.lit("run_as")).alias("run_as"))
.otherwise(pl.col(# `owner` is a dict of attributes, let's pull out the owner's username
"owner").map_elements(lambda x: x["username"], return_dtype=pl.String).alias("owner_username"))
.with_columns(pl.col(# filter and select relevant columns
filter(~pl.col("run_as").is_null())
."guid", "run_as", "title", "owner_username", "dashboard_url"])) .select([
The resulting table contains a list of all content on the server with custom runtime settings.
>>> content
3, 5)
shape: (
┌─────────────────────────────────┬──────────────────┬───────────────────────────────┬────────────────┬──────────────────┐
│ guid ┆ run_as ┆ title ┆ owner_username ┆ dashboard_url │--- ┆ --- ┆ --- ┆ --- ┆ --- │
│ str ┆ str ┆ str ┆ str ┆ str │
│
╞═════════════════════════════════╪══════════════════╪═══════════════════════════════╪════════════════╪══════════════════╡5258049f-fe5e-4d4e-9df1-e3e42c… ┆ RunAsCurrentUser ┆ Loan Risk Prediction Model ┆ publisher1 ┆ https://connect… │
│ 11471207-1059-413f-a13c-5a540f… ┆ sa-finance ┆ Evaluation Analysis Dashboard ┆ publisher2 ┆ https://connect… │
│ -3f14-43f5-8351-d44422… ┆ sa-finance ┆ Loan Risk API ┆ publisher3 ┆ https://connect… │
│ deec1ee8 └─────────────────────────────────┴──────────────────┴───────────────────────────────┴────────────────┴──────────────────┘
You can filter the table to see content for a single RunAs
setting.
> CUSTOM_RUN_AS = "sa-finance"
> print(content.filter(pl.col("run_as") == CUSTOM_RUN_AS))
2, 5)
shape: (
┌─────────────────────────────────┬────────────┬───────────────────────────────┬────────────────┬──────────────────┐
│ guid ┆ run_as ┆ title ┆ owner_username ┆ dashboard_url │--- ┆ --- ┆ --- ┆ --- ┆ --- │
│ str ┆ str ┆ str ┆ str ┆ str │
│
╞═════════════════════════════════╪════════════╪═══════════════════════════════╪════════════════╪══════════════════╡11471207-1059-413f-a13c-5a540f… ┆ sa-finance ┆ Evaluation Analysis Dashboard ┆ publisher2 ┆ https://connect… │
│ -3f14-43f5-8351-d44422… ┆ sa-finance ┆ Loan Risk API ┆ publisher3 ┆ https://connect… │
│ deec1ee8 └─────────────────────────────────┴────────────┴───────────────────────────────┴────────────────┴──────────────────┘
library(connectapi)
library(dplyr)
library(tidyr)
<- connect()
client
<- get_content(client) |>
content # combine RunAsCurrentUser and RunAs into a single column
mutate(run_as = case_when(run_as_current_user == TRUE ~ "RunAsCurrentUser", .default = run_as)) |>
# `owner` is a list of attributes, let's pull out the owner's username
hoist(owner, owner_username = "username") |>
drop_na(run_as) |>
select(guid, run_as, title, owner_username, dashboard_url)
The resulting table contains a list of all content on the server with custom runtime settings.
> content
# A tibble: 3 × 5
guid run_as title owner_username dashboard_url<chr> <chr> <chr> <chr> <chr>
1 95fcb004-4fc7-… RunAsCurrentUser Loan Risk Prediction Model publisher1 https://connect…
2 be1a08f1-b41a-… sa-finance Evaluation Analysis Dashboard publisher3 https://connect…
3 75a340d8-1454-… sa-finance Loan Risk API publisher3 https://connect…
You can filter the table to see content for a single RunAs setting
.
> CUSTOM_RUN_AS <- "sa-finance"
> filter(content, run_as == !!CUSTOM_RUN_AS)
# A tibble: 3 × 5
guid run_as title owner_username dashboard_url<chr> <chr> <chr> <chr> <chr>
2 be1a08f1-b41a-… sa-finance Evaluation Analysis Dashboard publisher3 https://connect…
3 75a340d8-1454-… sa-finance Loan Risk API publisher3 https://connect…
See also
- Viewing Content Runtime Settings to create a table totaling the usage of custom runtime settings on your Connect server.