feat: multi-profile auth via ~/.config/lineark/config.toml#115
feat: multi-profile auth via ~/.config/lineark/config.toml#115lightstrike wants to merge 3 commits intoflipbit03:mainfrom
Conversation
The single ~/.linear_api_token file only supports one workspace at a time. This adds TOML-based profile support (similar to AWS CLI profiles) so users can store multiple tokens and switch between them. Config file format: [profiles.default] api_token = "lin_api_..." [profiles.work] api_token = "lin_api_..." New auth precedence: 1. --api-token flag 2. $LINEAR_API_TOKEN env var 3. --profile flag / $LINEAR_PROFILE env var → named profile 4. [profiles.default] in config file 5. ~/.linear_api_token legacy fallback SDK: adds Client::from_profile(), updates Client::auto() to accept optional profile name, adds toml dependency. CLI: adds --profile global flag, updates usage output with config file documentation.
SDK unit tests (10 new): - token_from_config_at: default profile, named profile, missing profile, empty token, whitespace trimming, missing file, malformed TOML, no profiles section, empty file, multiple profiles - auto_token precedence: env beats config, explicit profile skips env, LINEAR_PROFILE env var, empty/whitespace LINEAR_PROFILE ignored CLI offline tests (8 new): - --profile flag appears in --help and usage output - usage shows config file example with [profiles.default] - --profile with missing config file gives clear error - --profile with valid temp config resolves token correctly - default profile used when no flags set - LINEAR_PROFILE env var selects named profile - --profile with nonexistent profile name shows "not found" error - --api-token overrides --profile Refactored auth.rs to extract token_from_config_at(path, profile) so config parsing is testable against temp files without relying on the real ~/.config/lineark/config.toml.
|
@lightstrike I think it would be best if we first opened issues for discussions for potentially breaking changes like this one. I'd like to keep lineark deliberately For the sake of this proposal and of course your effort in ideating this, I'd like to put forward an approach similar to the current approach, but with the following multi-profile (multi-token) mechanics" "profiles" are simply different With that, we have:
I don't think we should do this at all. The only reason to use a token as a env var is for token file-less programmatic usage that doesn't leaks the token secret in something like Also, we'd need the following tweaks:
I will use this comment + your initial PR as a base for creating an issue in the repo, and then I'll pick it up and drive it to completion. Thanks a lot @lightstrike for your efforts and comprehension! |
|
Closing in favor of #127, which has been merged. @lightstrike — thank you for your effort on this! Your PR was the catalyst for this feature. As discussed in the review thread, we went with a simpler, config-free approach: profiles are just separate token files ( Your original PR and the discussion around it directly shaped the design of #127 — much appreciated! |
Why
The single
~/.linear_api_tokenfile only supports one workspace at a time. Users working across multiple Linear workspaces (e.g. personal and work) have to manually swap tokens. This adds TOML-based profile support — similar to AWS CLI profiles or SSH config — so users can store multiple tokens and switch between them with a flag or env var.Config file
~/.config/lineark/config.toml:Usage
Auth precedence (updated)
--api-tokenflag (unchanged)$LINEAR_API_TOKENenv var (unchanged)--profileflag /$LINEAR_PROFILEenv var → named profile in config[profiles.default]in~/.config/lineark/config.toml~/.linear_api_tokenlegacy fallback (backward compatible)Changes
SDK (
lineark-sdk)auth.rs: Newtoken_from_config()/token_from_config_at()for TOML config parsing, updatedauto_token()to acceptOption<&str>profile,$LINEAR_PROFILEenv var supportclient.rs: NewClient::from_profile(), updatedClient::auto(profile: Option<&str>)blocking_client.rs: Mirroredfrom_profile()and updatedauto()signatureCargo.toml: Addedtomldependencyhelpers.rs: Updated doc examples for newauto()signatureCLI (
lineark)main.rs: Added--profileglobal flag, wired into client resolutioncommands/usage.rs: Updated auth docs with config file format,--profileflag,LINEAR_PROFILEhinttests/offline.rs: 8 new integration testsTest plan
auto_tokenprecedence (env vs config, explicit profile skips env,LINEAR_PROFILEenv var, empty/whitespace ignored)--api-tokenoverrides--profile)cargo clippy --workspace -- -D warningscleancargo fmt --checkclean