feat(auth): add yt-cli style auth login --base-url #10
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/auth-login"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Adds
youtrack-cli auth login --base-url <url>matching the yt-cli flow. Trims trailing slashes off the URL, prompts for the API token with no echo (rpassword), verifies it against the server, and only then writes URL + token to~/.youtrack-cli.yaml(still 0600 via the existingConfig::save). Existingconfig set/view/showleft alone for board/sprint defaults; only the "missing config" error hint now points atauth login.Flow
On 401 or 403 the message is
token rejected by <url> (HTTP 401); not savedand the config file is untouched. On other non-2xx the response body is echoed back. Empty token after trim is rejected before any HTTP call.What changed
src/cli.rs: newAuth { cmd: AuthCommands }variant withLogin(AuthLoginArgs { base_url }).src/commands/auth/: new module.login.rsdoes the prompt + verify (GET /api/users/me?fields=login,fullName) + save;mod.rsdispatches.src/commands/mod.rs: register and dispatch the new module.src/config.rs: error hint when the config file is missing now points atauth login --base-url <url>.Cargo.toml/Cargo.lock: addrpassword = "7". No other deps changed.Tests
verify_token_returns_user_on_200wiremock-asserts the exact URL/query/header shape and parses the response.verify_token_rejects_401: 401 surfaces "token rejected" and never writes.verify_token_rejects_500: non-401/403 errors include status + body in the message.trim_trailing_slashunit test on the URL normalizer.cargo fmt --check,cargo clippy --all-targets -- -D warnings,cargo test --all-targetsall green locally.Test plan
cargo run -- auth login --base-url https://<your-instance>with a real token: confirms the masked-prompt UX and the saved YAML.cargo run -- auth login --base-url https://<your-instance>with a deliberately bad token: confirms the file is not touched (stat -c %Y ~/.youtrack-cli.yamlbefore and after).cargo run -- config showafter a successful login still renders the masked token from the new YAML.Follow-ups (out of scope)
auth logoutandauth statusif you want the full yt-cli auth surface; this PR only shipsloginper the brief.config set url/tokento a deprecation warning, onceauth loginis the documented path.auth login --base-urlfor credential setup