vscode-coder
vscode-coder copied to clipboard
Reconfigure if cli config was deleted from disk
You can get into a slightly weird state where VS Code is logged in but the cli configuration has been deleted. We could try logging the cli back in when this happens.
In my case, it happened when I was trying to update the plugin manually and it wiped the state directory in between. The plugin was still logged in, but when I tried to connect it said I was not logged in, which was confusing.
Or maybe we could at least update the wording to be "cli needs to be configured again".
This is caused by the fact that there are two login states that we maintain:
- Session token secret (with URL memento) -> Contains the currently logged in session, used by the view container
- Per URL session file -> Used by the CLI when remotely connecting to the workspace
You could technically delete (2) while having (1) working and thus get this confusing state. Potentially, we should just store a map of URL -> token in the secrets instead of plain text files.
The issue I think will be how to get the cli to use those memento-based map of secrets. Right now we use the file, maybe we could set the token as an environment variable instead? Except the remote extension controls the spawn, so I think we are not able to do that.
Maybe the new keyring stuff will help, although only on Windows for now.
If we are launching the CLI from VS Code then we can set environment variables for the token then we do not need the files. Unless the user depends on those files to launch the CLI from the terminal? (In that case it's not great because the OAuth access token is short lived, 24h only)
We do not control the SSH spawn though, so how do we set environment variables for the sub-process? Even if we set them in the current process (which may not be a good idea), there is no guarantee the environment will be inherited (depends on what the remote SSH plugin is doing).
Good point about the terminal as well, we do have that one issue about adding the cli to the PATH, so we might need to authorize the cli for usage in the terminal. 🤔
I think we might need to keep the file for now till we figure out a way to transmit that information or share environment variables in a more secure way. But for now, what we can do is make the source of truth the VS Code secret storage and only write to file when we connect to a deployment. That way, the sidebar and the CLI would both use the secret storage as the source so we don't encounter this issue.