From 656e18389b3e74807e7a23f20637b593995b2453 Mon Sep 17 00:00:00 2001 From: Amelia <30877272+amsnyder@users.noreply.github.com> Date: Thu, 30 Mar 2023 17:49:41 -0400 Subject: [PATCH] excise dssecrets copying changes from https://github.com/USGS-R/slim-data-release-template/pull/23 --- src/sb_utils.R | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/sb_utils.R b/src/sb_utils.R index 11fa603..e31f616 100644 --- a/src/sb_utils.R +++ b/src/sb_utils.R @@ -39,6 +39,7 @@ sb_replace_files <- function(sb_id, ..., file_hash){ if (!sbtools::is_logged_in()){ sb_secret <- dssecrets::get_dssecret("cidamanager-sb-srvc-acct") + message(paste("Using the secret dated", sb_secret$timeStamp, "to log in.")) sbtools::authenticate_sb(username = sb_secret$username, password = sb_secret$password) } @@ -128,8 +129,12 @@ do_item_replace_tasks <- function(sb_id, files, sources) { upload_and_record <- function(sb_id, filepath) { # First verify that you are logged into SB. Need to do this for each task that calls - sb_secret_login() - + if (!sbtools::is_logged_in()) { + if (suppressWarnings(suppressMessages(require(dssecrets)))) { + message("ScienceBase is not logged in. Using dssecrets to log in with the cidamanager-sb-srvc-acct secret") + sb_secret_login() + } + } # Second, upload the file item_replace_files(sb_id, files = filepath) @@ -153,7 +158,13 @@ upload_and_record <- function(sb_id, filepath) { #' or if any duplicated file names exist on sciencebase for this `sb_id`. verify_uploads <- function(file_tbl, tgt_names, remake_file){ - sb_secret_login() + # First verify that you are logged into SB. Need to do this for each task that calls + if (!sbtools::is_logged_in()) { + if (suppressWarnings(suppressMessages(require(dssecrets)))) { + message("ScienceBase is not logged in. Using dssecrets to log in with the cidamanager-sb-srvc-acct secret") + sb_secret_login() + } + } sb_id <- unique(file_tbl$sb_id) # this call is not robust to a tbl w/ more than one unique sb_id stopifnot(length(sb_id) == 1)