Skip to content

feat: read session token from file, if present#521

Merged
nealrichardson merged 2 commits intomainfrom
session-token-file
Mar 24, 2026
Merged

feat: read session token from file, if present#521
nealrichardson merged 2 commits intomainfrom
session-token-file

Conversation

@nealrichardson
Copy link
Copy Markdown
Collaborator

@nealrichardson nealrichardson commented Mar 23, 2026

Intent

Closes #518

Approach

Write a failing test, make it pass, update the docs

Checklist

  • Does this change update NEWS.md (referencing the connected issue if necessary)?
  • Does this change need documentation? Have you run devtools::document()?
  • Does this change resolve integration test failures for a preview build of Connect? If so (and if you are on the Connect team), please be sure to update the Connect changelog to reflect that users will need to upgrade their version of connectapi.

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)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

yeah yeah, I just wanted to make sure that it handled empty files in the same way as the Python implementation for consistency.

@nealrichardson nealrichardson merged commit 55ec3bb into main Mar 24, 2026
23 checks passed
@nealrichardson nealrichardson deleted the session-token-file branch March 24, 2026 21:39
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.

feat: read session token from file, if present

2 participants