Skip to content
This repository has been archived by the owner on Jun 2, 2023. It is now read-only.

Investigate diff between sb_replace_files() and sb_replace_files_log() #6

Open
msleckman opened this issue Dec 22, 2022 · 2 comments
Open

Comments

@msleckman
Copy link
Collaborator

msleckman commented Dec 22, 2022

There is some confusion around the existence and versioning of sb_replace_files_log() and sb_replace_files() in the src/sb_utiles.R of this template repo.

Couples thoughts and discussion questions:

-sb_replace_files_log() in this hierarchical data release repo is identical to the sb_replace_files() function that is in the slim-data-release src/sb_utils.R and this function was used in recently published data release repos (drb-temp-v2, @padilla410's lake-temp data release repo).

To align with slim-data-release-template and recent data releases, I've renamed this repo's sb_replace_files_log() --> sb_replace_files() (commit edd6df0 PR #9), and this repo's sb_replace_files() --> sb_replace_files_old().

  • sb_replace_files() vs. _old:
    [1]
sb_replace_files <- function(filename, sb_id, ..., file_hash, sources = c()){
  files <- c(...)
  if (!missing(file_hash)){
    files <- c(files, names(yaml.load_file(file_hash))) %>% sort() 
  }

  # Throw error if there are no files given to push
  stopifnot(length(files) > 0)
  do_item_replace_tasks(sb_id, files, sources) %>% 
    write_csv(filename)
}
  • The old version includes several additional lines of codes, and conditional statements such as checking the dssecrets authentication:
    [2]
sb_replace_files_old <- function(sb_id, ..., file_hash){ 
  if (!sbtools::is_logged_in()){ 
    sb_secret <- dssecrets::get_dssecret("cidamanager-sb-srvc-acct")
    sbtools::authenticate_sb(username = sb_secret$username, password = sb_secret$password)   
  } 
  hashed_filenames <- c()
  if (!missing(file_hash)){
    hashed_filenames <- yaml.load_file(file_hash) %>% names %>% sort() %>% rev()
    for (file in hashed_filenames){
      item_replace_files(sb_id, files = file)
    }
  }
  files <- c(...)
  if (length(files) > 0){
    item_replace_files(sb_id, files = files)
  }
}

@limnoliver, if you know, can you share why this function was updated to the one above [1] ? Are there any elements of this old function [2] that are worth keeping (e.g. should we be checking the sb authentication status in sb_replace_files()) ? Can I delete this function code entirely?

@jesse-ross,:

  • Surprisingly, this function sb_replace_files_old() works for making changes on a sciencebase locally, but does not work when using it in an interactive R console in Caldera. Might you know why this is?
  • sb_replace_files() works with Caldera (and locally), but I must run authenticate_sb() in the console in order for it to work.
  • How can we make sure dssecrets is up to date in the appropriate repos in the iidd/data_releases/ in caldera?
@jesse-ross
Copy link
Contributor

jesse-ross commented Jan 9, 2023

Sorry for the delay in replying to this - it escaped my notice somehow!

I think that the issue you're running into is probably related to the sciencebase credentials having changed. These will need to be updated in your dssecrets installation on tallgrass. Note that in order to update your dsssecrets you'll need to follow the instructions here to make sure your library paths are set up correctly. Once you have successfully done this and verified it works, it would be good to add a section to your data releases docs in the DSP manual, so that people don't have to refer to that old page. I've created an issue for that and assigned it to you.

Please let me know if you have any questions or run into any problems!

@padilla410
Copy link

FYI, I intend to rotate this secrets in ds-secrets later this week

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants