Skip to content

implementation of multi-session support and non-interactive login#34

Open
RafsanNeloy wants to merge 5 commits intoaces:mainfrom
RafsanNeloy:session
Open

implementation of multi-session support and non-interactive login#34
RafsanNeloy wants to merge 5 commits intoaces:mainfrom
RafsanNeloy:session

Conversation

@RafsanNeloy
Copy link
Copy Markdown

@RafsanNeloy RafsanNeloy commented Mar 4, 2026

Implemented multi-session concurrency by storing credentials in a keyed ~/.config/cbrain.json file, accessible via the new --session flag. It also adds non-interactive login support using --username, --password, and --server arguments for better automation. Additionally, logout now intelligently handles clearing multiple sessions, and the version command has been moved to a public access level.

updated the session command like -

cbrain --session prod login --user rafsan --password 'pass!' --server http://server:3001
cbrain --session prod whoami
cbrain --session prod logout
cbrain logout (clears all session)

closes #28

Signed-off-by: rafsanneloy <rafsanneloy@gmail.com>
@RafsanNeloy
Copy link
Copy Markdown
Author

Mistakenly removed some lines which are not supposed to be removed..adding right away asap

Signed-off-by: rafsanneloy <rafsanneloy@gmail.com>
@AviJxn
Copy link
Copy Markdown

AviJxn commented Mar 7, 2026

Nice work on the multi-session support! I noticed that in your main.py changes, the version command still seems to be located after some initial setup logic. In my PR for Issue #28, I found that moving it to the absolute top of main() and redirecting its output to stderr was necessary to satisfy the automated capture tests. Might be worth coordinating our changes to ensure we hit those TOFIX requirements!

Signed-off-by: RafsanNeloy <rafsanneloy@gmail.com>
@RafsanNeloy
Copy link
Copy Markdown
Author

Login to a named session

cbrain --session prod login --user rafsan --password 'Cbrain123' --server http://127.0.0.1:3001
cbrain login --session prod --user rafsan --password 'Cbrain123' --server http://127.0.0.1:3001

Logout a specific session

cbrain --session prod logout
cbrain logout --session prod

Logout ALL sessions

cbrain logout

Switch the default session (no --session needed for future commands)

cbrain switch_session prod

After switching, bare commands auto-use that session

cbrain whoami
cbrain file list

List all saved sessions (shows active one with *)

cbrain session list

Show who you're logged in as (for current/active session)

cbrain whoami
cbrain whoami --session prod

Verbose token verification

cbrain whoami --version
cbrain whoami --session prod --version

See both sessions

cbrain session list

Switch default to prod

cbrain switch_session prod

All future commands use prod without typing --session

cbrain file list
cbrain whoami

Implemented switch command

@RafsanNeloy
Copy link
Copy Markdown
Author

Nice work on the multi-session support! I noticed that in your main.py changes, the version command still seems to be located after some initial setup logic. In my PR for Issue #28, I found that moving it to the absolute top of main() and redirecting its output to stderr was necessary to satisfy the automated capture tests. Might be worth coordinating our changes to ensure we hit those TOFIX requirements!

Sorry, I am not sure what are you trying to say. Can you elaborate more please??

@AviJxn
Copy link
Copy Markdown

AviJxn commented Mar 10, 2026

Hey @RafsanNeloy great implementation! To clarify that automated capture tests for this project expect the "--version" flag to be handled with zero overhead.

Currently, in your main.py the code performs some initialization (like checking config files or setting up the API client) before it check for the version flag if a user does not have a config file yet "cbrain --version" might throw an error or warning which it should not.

In my PR for #28 I moved the version check to the very first line of the execution entry point i also ensured it prints to stderr so that when researchers use pipes (eg. cbrain list > files.txt) the version info does not accidentally end up inside their data files.

since your PR is quite large and touches main.py we should make sure that your new --session logic does not bury that version check again. happy to help you look at the specific lines if you did like!

@RafsanNeloy
Copy link
Copy Markdown
Author

Command.prompt.mp4

Tried to use switch and others commands after implementing

@MontrealSergiy
Copy link
Copy Markdown
Contributor

not sure why use .config/cbrain.json instead .config/cbrain/credentials?

btw I think version command was fixed already

@RafsanNeloy
Copy link
Copy Markdown
Author

not sure why use .config/cbrain.json instead .config/cbrain/credentials?

In the issue #28 body I see the comment like -

the cbrain command would store in ~/.config/cbrain.json two distinct session structures,

Should we want to make the credential file name like ~/.config/credentials.json ?

@MontrealSergiy
Copy link
Copy Markdown
Contributor

At the moment I just trying to see are there any serious benefits in the suggested solution. Present solution ~/.config/cbrain/ folders follows XDG, a widespread Linux standard, and allows adding more files (such as preferences, history, cache
) in the future without clutter.

Signed-off-by: RafsanNeloy <rafsanneloy@gmail.com>
Signed-off-by: RafsanNeloy <rafsanneloy@gmail.com>
@prioux
Copy link
Copy Markdown
Member

prioux commented Mar 17, 2026

I agree with Sergiy that if we can follow a standard, we should.

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.

Required Corrections and Improvements for CBRAIN CLI Project Completion

4 participants