Skip to content

Commit

Permalink
Merge pull request #154 from natverse/fix/windows-tokens
Browse files Browse the repository at this point in the history
Better reporting on token locations
  • Loading branch information
jefferis authored May 12, 2022
2 parents 01c8a46 + 51f7549 commit c2f4e15
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ Suggests:
arrow,
glue,
lubridate,
tidyr
tidyr,
fs
VignetteBuilder:
knitr
Remotes:
Expand Down
14 changes: 12 additions & 2 deletions R/cloudvolume.R
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,18 @@ flywire_set_token <- function(token=NULL, domain=NULL) {
invisible(cv_write_secret(list(token=token), fqdn=domain, type="cave"))
}

cv_secretdir <- function() {
d=normalizePath("~/.cloudvolume/secrets/", mustWork = F, winslash = "/")
cv_secretdir <- function(use_cloudvolume=NA) {
if(is.na(use_cloudvolume)) {
use_cloudvolume=!is.na(cloudvolume_version())
}
if(use_cloudvolume) {
secrets=reticulate::import('cloudvolume.secrets')
d=secrets$secretpath('secrets')
} else {
if(!requireNamespace('fs', quietly = TRUE))
stop("Please install suggested fs package!")
d=as.character(fs::path_home('.cloudvolume','secrets'))
}
d
}

Expand Down
26 changes: 18 additions & 8 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,27 +42,37 @@ google_report <- function() {
#' @importFrom usethis ui_todo ui_code
flywire_report <- function() {
message("FlyWire\n----")

cat("Checking secrets folder for tokens from R:", cv_secretdir(), "\n")
token=try(chunkedgraph_token(cached = F), silent = FALSE)
token_ok=isFALSE(inherits(token, "try-error"))
cvv=cloudvolume_version()
if(token_ok) {
extest=try(flywire_expandurl("https://globalv1.flywire-daf.com/nglstate/5747205470158848"), silent = T)
if(inherits(extest, 'try-error')) {

ui_todo(paste('FlyWire token exists but is not authorised. Set a new token with:\n',
ui_todo(paste('FlyWire token was found by R but is not authorised. Set a new token with:\n',
"{ui_code('flywire_set_token()')}"))
token_ok=FALSE
} else
cat("Valid FlyWire ChunkedGraph token is set!\n")
cat("Valid FlyWire ChunkedGraph token is set and found by R!\n")
if(is.na(cvv)) {
cat("Please use simple_python to install python+cloudvolume for full access to flywire API!")
cat("Please use simple_python to install python+cloudvolume for full access to flywire API!\n")
} else {
rootid_test=try(flywire_rootid("81489548781649724", method = 'cloudvolume'))
if(inherits(rootid_test, 'try-error'))
message("You have a valid token but python+cloudvolume access to FlyWire API is still failing!\n",

secrets=reticulate::import('cloudvolume.secrets')
cvtoken=secrets$secretpath('secrets/cave-secret.json')
cvtokenok=file.exists(cvtoken)
if(!cvtokenok)
message("cloudvolume cannot find a token at ", cvtoken)
else {
cat("cloudvolume found a token at ", cvtoken, "\n")
# try using said token
rootid_test=try(flywire_rootid("81489548781649724", method = 'cloudvolume'))
if(inherits(rootid_test, 'try-error'))
message("token found but python+cloudvolume access to FlyWire API is still failing!\n",
"Please ask for help at https://groups.google.com/g/nat-user using the full output of dr_fafbseg.")
else cat("Flywire API access via python+cloudvolume is working.")
else cat("Flywire API access via python+cloudvolume is working.")
}
}
} else{
ui_todo(paste('No valid FlyWire token found. Set your token by doing:\n',
Expand Down

0 comments on commit c2f4e15

Please sign in to comment.