Groups#
Create an RStudio Connect Group from LDAP#
The following snippets search for a group in LDAP and then create an RStudio Connect group for that LDAP group.
Workflow#
There are three steps:
-
Search for the group via the
GET /v1/groups/remoteendpoint.Note
A group that does not exist on Connect will lack a
guid. -
Note the
temp_ticketfor the desired group. - Use the
PUT /v1/groupsendpoint with thetemp_ticketto create a corresponding group on RStudio Connect.
Search for a Group#
First, search for a group via the GET
/v1/groups/remote endpoint:
library(httr)
# The connectServer URL must have a trailing slash.
connectServer <- Sys.getenv("CONNECT_SERVER")
connectAPIKey <- Sys.getenv("CONNECT_API_KEY")
# set the search parameter
prefix <- "accounting"
# make the query request
response <- GET(
paste0(connectServer, "__api__/v1/groups/remote"),
add_headers(Authorization = paste("Key", connectAPIKey)),
query = list(prefix = prefix)
)
results <- content(response)$results
# print the results of the API call
formatGuid <- function(guid) {
if (is.null(guid)) {
"NULL"
} else {
guid
}
}
cat(sprintf("NAME\tGUID\n"))
for (group in results) {
cat(sprintf("%s\t%s\n", group$name, formatGuid(group$guid)))
}
The output looks like the following:
NAME GUID
accounting1 15f5f51d-08ff-4e5b-beba-4ccf24e248dd
accounting2 NULL
Let's break this down:
- In this particular case, there are two groups matching the search for the
prefix
accounting:accounting1accounting2
- The group
accounting1has aGUIDvalue, which means that this group already exists in RStudio Connect. - The group
accounting2does not have aGUIDvalue, which means that this group does not have a corresponding group in RStudio Connect.
Included in the API response for each group is a temp_ticket value
that can be used to create the group in RStudio Connect. In the
example above, the second group, accounting2, does not exist in
RStudio Connect, so you will need the temp_ticket for this group:
tempTicket <- results[[2]]$temp_ticket
You can use this tempTicket value in the next section to create the
group.
Create an RStudio Connect Group#
Using the tempTicket value from the previous section, you can create
an RStudio Connect group with a PUT /v1/groups:
library(httr)
# The connectServer URL must have a trailing slash.
connectServer <- Sys.getenv("CONNECT_SERVER")
connectAPIKey <- Sys.getenv("CONNECT_API_KEY")
# The 'tempTicket' value comes from an earlier /groups/remote search.
response <- PUT(
paste0(connectServer, "__api__/v1/groups"),
add_headers(Authorization = paste("Key", connectAPIKey)),
body = list(temp_ticket = tempTicket),
encode = "json"
)
print(content(response))
When the call succeeds, the response will contain a non-NULL guid value,
which is a unique identifier for the group.
If the group already exists in Connect, the response will contain an error:
$error
[1] "The requested group name is already in use."