Skip to content

Commit

Permalink
fix extraction of sandbox token
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge committed Dec 5, 2023
1 parent ef2a2c1 commit 6cceb02
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: deposits
Title: A universal client for depositing and accessing research data
anywhere
Version: 0.2.1.046
Version: 0.2.1.047
Authors@R:
person("Mark", "Padgham", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-2172-5265"))
Expand Down
2 changes: 1 addition & 1 deletion R/client-main.R
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ depositsClient <- R6::R6Class ( # nolint (not snake_case)

if (is.null (headers)) {
service <- add_service_sandbox (self$service, self$sandbox)
token <- get_deposits_token (service = service)
token <- get_deposits_token (service = service, sandbox = self$sandbox)
self$headers <- list (Authorization = paste0 ("Bearer ", token))
}

Expand Down
9 changes: 7 additions & 2 deletions R/tokens.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#'
#' @param service Name of desired service; must be a value in the "name" column
#' of \link{deposits_services}.
#' @param sandbox If `TRUE`, retrieve token for sandbox, rather than actual API.
#' @return API token for nominated service.
#'
#' @examples
Expand All @@ -15,7 +16,7 @@
#' }
#' @family auth
#' @export
get_deposits_token <- function (service = NULL) {
get_deposits_token <- function (service = NULL, sandbox = FALSE) {

checkmate::assert_character (service, len = 1L)

Expand All @@ -24,7 +25,11 @@ get_deposits_token <- function (service = NULL) {
e <- e [grep (service, names (e), ignore.case = TRUE)]
if (length (e) != 1L) {
if (grepl ("^zenodo$", service, ignore.case = TRUE)) {
e <- e [which (!grepl ("sandbox", names (e), ignore.case = TRUE))]
if (sandbox && any (grepl ("sandbox", names (e), ignore.case = TRUE))) {
e <- e [grep ("sandbox", names (e), ignore.case = TRUE)]
} else {
e <- e [which (!grepl ("sandbox", names (e), ignore.case = TRUE))]
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"codeRepository": "https://github.com/ropenscilabs/deposits",
"issueTracker": "https://github.com/ropenscilabs/deposits/issues",
"license": "https://spdx.org/licenses/MIT",
"version": "0.2.1.046",
"version": "0.2.1.047",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down

0 comments on commit 6cceb02

Please sign in to comment.