feat: read session token from file, if present#521
Conversation
| if (is.null(content_session_token)) { | ||
| token_file <- Sys.getenv("CONNECT_CONTENT_SESSION_TOKEN_FILE") | ||
| if (nzchar(token_file)) { | ||
| content_session_token <- readLines(token_file, n = 1, warn = FALSE) |
There was a problem hiding this comment.
I don't know R primitives very well. Does the nzchar equality check handle conditions where the file specified at CONNECT_CONTENT_SESSION_TOKEN_FILE is missing? Also, will if (is.null(content_session_token)) evaluate to false if the file is empty?
There was a problem hiding this comment.
nzchar is handling "is the env var set and not empty". If the file it points to does not exist, readLines() will throw an error. If the file exists but is empty, that would return a 0-length string, which would be an invalid token but not NULL so it wouldn't fall back to checking the CONNECT_CONTENT_SESSION_TOKEN env var.
We could be more defensive around those, I suppose, but what other than raising a different error message would we do? If the session token file is invalid, why should we expect anything else to work?
There was a problem hiding this comment.
yeah yeah, I just wanted to make sure that it handled empty files in the same way as the Python implementation for consistency.
Intent
Closes #518
Approach
Write a failing test, make it pass, update the docs
Checklist
NEWS.md(referencing the connected issue if necessary)?devtools::document()?connectapi.