-
Notifications
You must be signed in to change notification settings - Fork 26
feat: add function to get integrations #426
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
3419593
47b5138
2f393c7
0c1edd0
da188bf
b94f7d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -78,6 +78,7 @@ Collate: | |
'get.R' | ||
'git.R' | ||
'groups.R' | ||
'integrations.R' | ||
'lazy.R' | ||
'page.R' | ||
'parse.R' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
#' List all OAuth integrations on the Connect server | ||
#' | ||
#' @description | ||
#' Retrieve information about all OAuth integrations available to Posit Connect. | ||
#' You must have administrator or publisher privileges to perform this action. | ||
#' | ||
#' @param client A `Connect` R6 client object. | ||
#' | ||
#' @return A list of OAuth integrations. Each integration is a list with the | ||
#' following elements (all character strings unless indicated otherwise): | ||
#' | ||
#' * `id`: The internal identifier of this OAuth integration. | ||
#' * `guid`: The GUID of this OAuth integration. | ||
#' * `created_time`: The timestamp (RFC3339) indicating when this integration | ||
#' was created. | ||
#' * `updated_time`: The timestamp (RFC3339) indicating when this integration | ||
#' was last updated | ||
#' * `name`: A descriptive name to identify the OAuth integration. | ||
#' * `description`: A brief text to describe the OAuth integration. | ||
#' * `template`: The template used to configure this OAuth integration. | ||
#' * `auth_type`: The authentication type indicates which OAuth flow is used by | ||
#' this integration. | ||
#' * `config`: A sub-list list with the OAuth integration configuration. Fields | ||
#' differ between integrations. | ||
#' | ||
#' Use [as.data.frame()] or [tibble::as_tibble()] to convert to a data frame with | ||
#' parsed types. In the resulting data frame: | ||
#' | ||
#' * `created_time` and `updated_time` are parsed to `POSIXct`. | ||
#' * `config` remains as a list-column. | ||
#' | ||
#' @seealso [get_oauth_credentials()], [get_oauth_content_credentials()] | ||
#' | ||
#' @examples | ||
#' \dontrun{ | ||
#' client <- connect() | ||
#' | ||
#' # Fetch all OAuth integrations | ||
#' integrations <- get_integrations(client) | ||
#' | ||
#' | ||
#' # Update the configuration and metadata for a subset of integrations. | ||
#' json_payload <- toJSON(list( | ||
#' description = "New Description", | ||
#' config = list( | ||
#' client_secret = "new-client-secret" | ||
#' ) | ||
#' ), auto_unbox = TRUE) | ||
#' | ||
#' results <- integrations |> | ||
#' purrr::keep(\(x) x$template == "service_to_update") |> | ||
#' purrr::map(\(x) client$PATCH(paste0("v1/oauth/integrations/", x$guid), body = json_payload)) | ||
#' | ||
#' | ||
#' # Convert to tibble or data frame | ||
#' integrations_df <- tibble::as_tibble(integrations) | ||
#' } | ||
#' | ||
#' @export | ||
get_integrations <- function(client) { | ||
error_if_less_than(client$version, "2024.12.0") | ||
integrations <- client$GET(v1_url("oauth", "integrations")) | ||
class(integrations) <- c("connect_list_integrations", class(integrations)) | ||
integrations | ||
} | ||
|
||
#' Convert integrations data to a data frame | ||
#' | ||
#' @description | ||
#' Converts an list returned by [get_integrations()] into a data frame. | ||
#' | ||
#' @param x A `connect_list_integrations` object (from [get_integrations()]). | ||
#' @param row.names Passed to [base::as.data.frame()]. | ||
#' @param optional Passed to [base::as.data.frame()]. | ||
#' @param ... Passed to [base::as.data.frame()]. | ||
#' | ||
#' @return A `data.frame` with one row per integration. | ||
#' @export | ||
as.data.frame.connect_list_integrations <- function( | ||
x, | ||
row.names = NULL, # nolint | ||
optional = FALSE, | ||
... | ||
) { | ||
integrations_tbl <- as_tibble(x) | ||
as.data.frame( | ||
toph-allen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
integrations_tbl, | ||
row.names = row.names, | ||
optional = optional, | ||
... | ||
) | ||
} | ||
|
||
#' Convert integrations data to a tibble | ||
#' | ||
#' @description | ||
#' Converts a list returned by [get_integrations()] to a tibble. | ||
#' | ||
#' @param x A `connect_list_integrations` object. | ||
#' @param ... Unused. | ||
#' | ||
#' @return A tibble with one row per integration. | ||
#' @export | ||
as_tibble.connect_list_integrations <- function(x, ...) { | ||
parse_connectapi_typed(x, connectapi_ptypes$integrations) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"version": "2024.12.0" | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
[ | ||
{ | ||
"id": "4", | ||
"guid": "f8688548", | ||
"created_time": "2024-08-01T20:14:31Z", | ||
"updated_time": "2025-03-25T19:08:26Z", | ||
"name": "GitHub Integration", | ||
"description": "with refresh support ", | ||
"template": "custom", | ||
"auth_type": "Viewer", | ||
"config": { | ||
"auth_mode": "Confidential", | ||
"auth_type": "Viewer", | ||
"authorization_uri": "https://github.com/login/oauth/authorize", | ||
"client_id": "client_id_123", | ||
"scopes": "offline_access openid profile email repo read:user", | ||
"token_endpoint_auth_method": "client_secret_post", | ||
"token_uri": "https://github.com/login/oauth/access_token", | ||
"use_pkce": true | ||
} | ||
}, | ||
{ | ||
"id": "5", | ||
"guid": "cacc0cf1", | ||
"created_time": "2024-09-09T15:01:29Z", | ||
"updated_time": "2025-03-25T19:07:01Z", | ||
"name": "Example Service", | ||
"description": "The service provides utility to your company", | ||
"template": "generic_service", | ||
"auth_type": "Viewer", | ||
"config": { | ||
"account_url": "https://service.example.com", | ||
"auth_mode": "Confidential", | ||
"client_id": "client_id_456", | ||
"scopes": "refresh_token" | ||
} | ||
} | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
toph-allen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
} |
Uh oh!
There was an error while loading. Please reload this page.