Skip to content

Conversation

@dblodgett-usgs
Copy link
Collaborator

Fixes #329 pending review.

@dblodgett-usgs dblodgett-usgs requested a review from amart90 April 16, 2025 15:36
Copy link
Contributor

@amart90 amart90 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for humoring my request! I tested the new functionality out on a reproducible example targets pipeline.

library(sbtools)
library(targets)

# Log-in during interactive session
# Change username to valid ScienceBase username
sbtools::initialize_sciencebase_session(username = "USERNAME REDACTED")

# Create and execute targets pipeline in temp directory
tar_dir({
	# Define targets pipeline
	tar_script({
		# Read ScienceBase token from cache
		sbtools::initialize_sciencebase_session(
			username = sbtools::get_username(),
			token_text = sbtools::get_cached_token()
		)
		
		# Target list
		list(
			tar_target(is_logged_in, sbtools::is_logged_in()),
			tar_target(
				secured_file,
				sbtools::item_list_files("66e05a7ed34ecba8b86765d5")[["fname"]][1]
			)
		)
	})
	
	# Execute targets pipeline
	tar_make()
	
	# Load targets into global environment
	tar_load(c(is_logged_in, secured_file))
})

is_logged_in
#> [1] TRUE

secured_file
#> [1] "NYC_reservoir_monthly_storage_change-Domber-mgal.csv"

Everything worked exactly how it was expected.

I had one very minor suggestion in the function documentation to keep the capitalization function with the rest of the documentation. In either case, approved! Thanks again!

#' username is found and `interactive()` is FALSE
#' @export
#'
get_username <- function(username = NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic in this function all makes sense to me.

Co-authored-by: Anthony Martinez <ajmartinez@usgs.gov>
@dblodgett-usgs dblodgett-usgs merged commit 2ffe275 into main Apr 16, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Customize token cache

3 participants