Skip to content

Commit

Permalink
accountInfo() produces name and username fields (#1025)
Browse files Browse the repository at this point in the history
  • Loading branch information
aronatkins authored Nov 8, 2023
1 parent 98ccc9a commit d7a92bf
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
* `deployApp()` and friends record multi-value `metadata` entries as
comma-separated values. (#1017)

* `accountInfo()` includes `name` and `username` fields. Older versions of
rsconnect store account records with a `username` field. Recent rsconnect
versions record `name`. Both `name` and `username` should contain the same
value. (#1024)

# rsconnect 1.1.1

* Added `space` parameter to deploy directly to a space in Posit Cloud.
Expand Down
6 changes: 6 additions & 0 deletions R/accounts.R
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,12 @@ findAccountInfo <- function(name = NULL, server = NULL, error_call = caller_env(

accountDcf <- read.dcf(configFile, all = TRUE)
info <- as.list(accountDcf)

# Account records previously had username, now have name. Internal callers expect "name", but
# external callers may expect "username". (#1024)
info$name <- info$name %||% info$username
info$username <- info$name

# remove all whitespace from private key
if (!is.null(info$private_key)) {
info$private_key <- gsub("[[:space:]]", "", info$private_key)
Expand Down
46 changes: 46 additions & 0 deletions tests/testthat/test-accounts.R
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,49 @@ test_that("secrets are hidden from casual inspection", {
test_that("setAccountInfo() gives nice error on bad copy and paste", {
expect_snapshot(setAccountInfo("name", "token", "<SECRET>"), error = TRUE)
})

test_that("accountInfo() returns account information", {
local_temp_config()
addTestServer()
addTestAccount("john")

accountDetails <- accountInfo("john", "example.com")
expect_equal(accountDetails$name, "john")
expect_equal(accountDetails$username, "john")
expect_equal(accountDetails$server, "example.com")
})

test_that("accountInfo() returns account information", {
local_temp_config()
addTestServer()
addTestAccount("john")

accountDetails <- accountInfo("john", "example.com")
expect_equal(accountDetails$name, "john")
# username is included for backwards compatibility. (#1024)
expect_equal(accountDetails$username, "john")
expect_equal(accountDetails$server, "example.com")
})

test_that("accountInfo() returns pre-rsconnect-1.0.0 account information", {
local_temp_config()
addTestServer()

# Subset of rsconnect-0.8.29 account fields.
fields <- list(
username = "john",
server = "example.com",
accountId = "john"
)

path <- accountConfigFile("john", "example.com")
dir.create(dirname(path), recursive = TRUE, showWarnings = FALSE)
write.dcf(compact(fields), path, width = 100)

accountDetails <- accountInfo("john", "example.com")
# name copied from username, as "name" is the current field name.
expect_equal(accountDetails$name, "john")
# username retained for backwards compatibility.
expect_equal(accountDetails$username, "john")
expect_equal(accountDetails$server, "example.com")
})

0 comments on commit d7a92bf

Please sign in to comment.