-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* New `add_headers()` argument for `board_url()` * Test headers handling * Redocument * Add docs section for using new `add_headers` * Add `board_connect_url()` and `connect_auth_headers()`, plus test the new auth * Add tests for new auth in `board_url()` via `board_connect_url()` * Redocument * Update NEWS * Use same args in `board_connect_url()` as `board_url()` * Reuse param from `board_connect()` * Add new board to pkgdown * Skip if no rsconnect (because of checking for Colorado) * Improve docs * Apply suggestions from code review Co-authored-by: Hadley Wickham <[email protected]> * Switch to `headers`, a named character vector, and update tests --------- Co-authored-by: Hadley Wickham <[email protected]>
- Loading branch information
1 parent
7a6d34d
commit 72621cd
Showing
15 changed files
with
315 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ Suggests: | |
filelock, | ||
gitcreds, | ||
googleCloudStorageR, | ||
ids, | ||
knitr, | ||
Microsoft365R, | ||
mime, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
#' Use a vector of Posit Connect vanity URLs as a board | ||
#' | ||
#' @description | ||
#' `board_connect_url()` lets you build up a board from individual | ||
#' [vanity urls](https://docs.posit.co/connect/user/content-settings/#custom-url). | ||
#' | ||
#' `board_connect_url()` is read only, and does not support versioning. | ||
#' | ||
#' @param vanity_urls A named character vector of | ||
#' [Connect vanity URLs](https://docs.posit.co/connect/user/content-settings/#custom-url). | ||
#' This board is read only, and the best way to write to a pin on Connect is | ||
#' [board_connect()]. | ||
#' @family boards | ||
#' @inheritParams new_board | ||
#' @inheritParams board_url | ||
#' @inheritParams board_connect | ||
#' @details | ||
#' This board is a thin wrapper around [board_url()] which uses | ||
#' `connect_auth_headers()` for authentication via environment variable. | ||
#' @export | ||
#' @examplesIf interactive() | ||
#' connect_auth_headers() | ||
#' | ||
#' board <- board_connect_url(c( | ||
#' my_vanity_url_pin = "https://colorado.posit.co/rsc/great-numbers/" | ||
#' )) | ||
#' | ||
#' board %>% pin_read("my_vanity_url_pin") | ||
#' | ||
board_connect_url <- function(vanity_urls, | ||
cache = NULL, | ||
use_cache_on_failure = is_interactive(), | ||
headers = connect_auth_headers()) { | ||
board_url( | ||
urls = vanity_urls, | ||
cache = cache, | ||
use_cache_on_failure = use_cache_on_failure, | ||
headers = headers | ||
) | ||
} | ||
|
||
#' @export | ||
#' @rdname board_connect_url | ||
connect_auth_headers <- function(key = Sys.getenv("CONNECT_API_KEY")) { | ||
c(Authorization = paste("Key", key)) | ||
} | ||
|
||
|
||
vanity_url_test <- function(env = parent.frame()) { | ||
board <- board_connect_test() | ||
name <- pin_write(board, 1:10, random_pin_name()) | ||
withr::defer(if (pin_exists(board, name)) pin_delete(board, name), env) | ||
|
||
vanity_slug <- ids::adjective_animal() | ||
body_path <- withr::local_tempfile() | ||
body <- list(force = FALSE, path = glue("/{vanity_slug}/")) | ||
jsonlite::write_json(body, body_path, auto_unbox = TRUE) | ||
body <- httr::upload_file(body_path, "application/json") | ||
|
||
meta <- pin_meta(board, name) | ||
path <- glue("v1/content/{meta$local$content_id}/vanity") | ||
path <- rsc_path(board, path) | ||
auth <- rsc_auth(board, path, "PUT", body_path) | ||
resp <- httr::PUT(board$url, path = path, body = body, auth) | ||
httr::stop_for_status(resp) | ||
|
||
glue("{board$url}/{vanity_slug}/") | ||
} | ||
|
||
board_connect_url_test <- function(...) { | ||
if (connect_has_colorado()) { | ||
board_connect_url_colorado(...) | ||
} else { | ||
board_connect_url_susan(...) | ||
} | ||
} | ||
|
||
board_connect_url_colorado <- function(...) { | ||
if (!connect_has_colorado()) { | ||
testthat::skip("board_connect_url_colorado() only works with Posit's demo server") | ||
} | ||
board_connect_url(..., cache = fs::file_temp()) | ||
} | ||
|
||
board_connect_url_susan <- function(...) { | ||
creds <- read_creds() | ||
board_connect_url( | ||
..., | ||
headers = connect_auth_headers(creds$susan_key) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.