Skip to content

Commit 1060ae8

Browse files
authored
feat: add function to get integrations (#426)
1 parent bd33d2b commit 1060ae8

16 files changed

+340
-0
lines changed

DESCRIPTION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ Collate:
7878
'get.R'
7979
'git.R'
8080
'groups.R'
81+
'integrations.R'
8182
'lazy.R'
8283
'page.R'
8384
'parse.R'

NAMESPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ S3method("[[",connect_tag_tree)
66
S3method(api_build,op_base_connect)
77
S3method(api_build,op_head)
88
S3method(as.data.frame,connect_list_hits)
9+
S3method(as.data.frame,connect_list_integrations)
910
S3method(as.data.frame,tbl_connect)
1011
S3method(as_tibble,connect_list_hits)
12+
S3method(as_tibble,connect_list_integrations)
1113
S3method(connect_vars,op_base)
1214
S3method(connect_vars,op_single)
1315
S3method(connect_vars,tbl_connect)
@@ -84,6 +86,7 @@ export(get_group_members)
8486
export(get_group_permission)
8587
export(get_groups)
8688
export(get_image)
89+
export(get_integrations)
8790
export(get_job)
8891
export(get_job_list)
8992
export(get_jobs)

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
- New `get_usage()` function returns content usage data from Connect's `GET
66
v1/instrumentation/content/hits` endpoint on Connect v2025.04.0 and higher.
77
(#390)
8+
- New `get_integrations()` function lists all OAuth integrations available on the
9+
Connect server from the `GET v1/oauth/integrations` endpoint on Connect v2024.12.0
10+
and higher. (#413)
811

912
## Enhancements and fixes
1013

R/get.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,8 @@ get_procs <- function(src) {
820820
#' Please see https://docs.posit.co/connect/user/oauth-integrations/#obtaining-a-viewer-oauth-access-token
821821
#' for more information.
822822
#'
823+
#' @seealso [get_integrations()], [get_oauth_content_credentials()]
824+
#'
823825
#' @export
824826
get_oauth_credentials <- function(
825827
connect,
@@ -886,6 +888,8 @@ get_oauth_credentials <- function(
886888
#' Please see https://docs.posit.co/connect/user/oauth-integrations/#obtaining-a-service-account-oauth-access-token
887889
#' for more information.
888890
#'
891+
#' @seealso [get_integrations()], [get_oauth_credentials()]
892+
#'
889893
#' @export
890894
get_oauth_content_credentials <- function(
891895
connect,

R/integrations.R

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#' List all OAuth integrations on the Connect server
2+
#'
3+
#' @description
4+
#' Retrieve information about all OAuth integrations available to Posit Connect.
5+
#' You must have administrator or publisher privileges to perform this action.
6+
#'
7+
#' @param client A `Connect` R6 client object.
8+
#'
9+
#' @return A list of OAuth integrations. Each integration is a list with the
10+
#' following elements (all character strings unless indicated otherwise):
11+
#'
12+
#' * `id`: The internal identifier of this OAuth integration.
13+
#' * `guid`: The GUID of this OAuth integration.
14+
#' * `created_time`: The timestamp (RFC3339) indicating when this integration
15+
#' was created.
16+
#' * `updated_time`: The timestamp (RFC3339) indicating when this integration
17+
#' was last updated
18+
#' * `name`: A descriptive name to identify the OAuth integration.
19+
#' * `description`: A brief text to describe the OAuth integration.
20+
#' * `template`: The template used to configure this OAuth integration.
21+
#' * `auth_type`: The authentication type indicates which OAuth flow is used by
22+
#' this integration.
23+
#' * `config`: A sub-list list with the OAuth integration configuration. Fields
24+
#' differ between integrations.
25+
#'
26+
#' Use [as.data.frame()] or [tibble::as_tibble()] to convert to a data frame with
27+
#' parsed types. In the resulting data frame:
28+
#'
29+
#' * `created_time` and `updated_time` are parsed to `POSIXct`.
30+
#' * `config` remains as a list-column.
31+
#'
32+
#' @seealso [get_oauth_credentials()], [get_oauth_content_credentials()]
33+
#'
34+
#' @examples
35+
#' \dontrun{
36+
#' client <- connect()
37+
#'
38+
#' # Fetch all OAuth integrations
39+
#' integrations <- get_integrations(client)
40+
#'
41+
#'
42+
#' # Update the configuration and metadata for a subset of integrations.
43+
#' json_payload <- toJSON(list(
44+
#' description = "New Description",
45+
#' config = list(
46+
#' client_secret = "new-client-secret"
47+
#' )
48+
#' ), auto_unbox = TRUE)
49+
#'
50+
#' results <- integrations |>
51+
#' purrr::keep(\(x) x$template == "service_to_update") |>
52+
#' purrr::map(\(x) client$PATCH(paste0("v1/oauth/integrations/", x$guid), body = json_payload))
53+
#'
54+
#'
55+
#' # Convert to tibble or data frame
56+
#' integrations_df <- tibble::as_tibble(integrations)
57+
#' }
58+
#'
59+
#' @export
60+
get_integrations <- function(client) {
61+
error_if_less_than(client$version, "2024.12.0")
62+
integrations <- client$GET(v1_url("oauth", "integrations"))
63+
class(integrations) <- c("connect_list_integrations", class(integrations))
64+
integrations
65+
}
66+
67+
#' Convert integrations data to a data frame
68+
#'
69+
#' @description
70+
#' Converts an list returned by [get_integrations()] into a data frame.
71+
#'
72+
#' @param x A `connect_list_integrations` object (from [get_integrations()]).
73+
#' @param row.names Passed to [base::as.data.frame()].
74+
#' @param optional Passed to [base::as.data.frame()].
75+
#' @param ... Passed to [base::as.data.frame()].
76+
#'
77+
#' @return A `data.frame` with one row per integration.
78+
#' @export
79+
as.data.frame.connect_list_integrations <- function(
80+
x,
81+
row.names = NULL, # nolint
82+
optional = FALSE,
83+
...
84+
) {
85+
integrations_tbl <- as_tibble(x)
86+
as.data.frame(
87+
integrations_tbl,
88+
row.names = row.names,
89+
optional = optional,
90+
...
91+
)
92+
}
93+
94+
#' Convert integrations data to a tibble
95+
#'
96+
#' @description
97+
#' Converts a list returned by [get_integrations()] to a tibble.
98+
#'
99+
#' @param x A `connect_list_integrations` object.
100+
#' @param ... Unused.
101+
#'
102+
#' @return A tibble with one row per integration.
103+
#' @export
104+
as_tibble.connect_list_integrations <- function(x, ...) {
105+
parse_connectapi_typed(x, connectapi_ptypes$integrations)
106+
}

R/ptype.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,5 +271,16 @@ connectapi_ptypes <- list(
271271
name = NA_character_,
272272
version = NA_character_,
273273
hash = NA_character_
274+
),
275+
integrations = tibble::tibble(
276+
id = NA_character_,
277+
guid = NA_character_,
278+
created_time = NA_datetime_,
279+
updated_time = NA_datetime_,
280+
name = NA_character_,
281+
description = NA_character_,
282+
template = NA_character_,
283+
auth_type = NA_character_,
284+
config = NA_list_
274285
)
275286
)

_pkgdown.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ reference:
6969
- starts_with("get")
7070
- as.data.frame.connect_list_hits
7171
- as_tibble.connect_list_hits
72+
- as.data.frame.connect_list_integrations
73+
- as_tibble.connect_list_integrations
7274

7375
- title: "Other"
7476
desc: >

man/as.data.frame.connect_list_integrations.Rd

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/as_tibble.connect_list_integrations.Rd

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/get_integrations.Rd

Lines changed: 70 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)