ropensci / piggyback

:package: for using large(r) data files on GitHub
https://docs.ropensci.org/piggyback
GNU General Public License v3.0
185 stars 26 forks source link

Asset download fails without cached credentials even for tokens given explicitly #88

Closed mbirkett-liv closed 2 years ago

mbirkett-liv commented 2 years ago

Thanks to Carl and everyone else for piggyback - very much appreciated. We found an issue recently which may impact others.

On hosts which do not cache GitHub credentials, i.e. where gh::gh_token() returns <no PAT>, asset downloads will fail with HTTP 404, even when an explicit personal access token (PAT) is passed into pb_download(). This occurs as pb_download.R:pb_download() doesn't pass its PAT .token parameter onwards into gh_download_asset(). So, currently gh_download_asset() always uses gh::gh_token().

Our fix involves simply passing this .token object as an argument to gh_download_asset() at pb_download.R:86:

    gh_download_asset(df$owner[[1]],
                      df$repo[[1]],
                      id = df$id[i],
                      destfile = df$dest[i],
                      overwrite = overwrite,
                      .token= .token, # CHANGE: forward the PAT object
                      progress = progress
    ))

This should work for PATs originating from gh::gh_token() or passed explicitly into pb_download(). Can provide a pull request if wanted? Thanks again.

tanho63 commented 2 years ago

Oops, yep that looks like a great idea...and actually may resolve some test bugs I'd been puzzled about!