Skip to content

Update logout command to revoke token server-side#1733

Open
amritghimire wants to merge 1 commit intomainfrom
amrit/logout-token
Open

Update logout command to revoke token server-side#1733
amritghimire wants to merge 1 commit intomainfrom
amrit/logout-token

Conversation

@amritghimire
Copy link
Copy Markdown
Contributor

Context

The datachain auth logout command currently only deletes the token from local config. The Studio backend now exposes POST /api/token-logout for self-revocation. The logout command should call this endpoint before clearing the local token, so the token is invalidated both locally and server-side.

This changes calls studio endpoint on logout

Context
--------
The datachain auth logout command currently only deletes the token from local config. The Studio backend now exposes POST /api/token-logout for self-revocation. The logout command should call this endpoint before clearing the local token, so the token is invalidated both locally and server-side.

This changes calls studio endpoint on logout
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented Apr 27, 2026

Deploying datachain with  Cloudflare Pages  Cloudflare Pages

Latest commit: 9eb6186
Status: ✅  Deploy successful!
Preview URL: https://04ef45ec.datachain-2g6.pages.dev
Branch Preview URL: https://amrit-logout-token.datachain-2g6.pages.dev

View logs

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the DataChain Studio auth logout CLI behavior to revoke the active token server-side via the new Studio endpoint before removing it from local configuration, ensuring logout invalidates credentials both locally and remotely.

Changes:

  • Call POST /api/token-logout during Studio logout prior to deleting the local token.
  • Add stderr warnings for “already revoked/invalid” tokens and for unexpected/unreachable Studio responses.
  • Extend CLI test coverage for successful revocation, 401 “already revoked”, and custom Studio URLs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/datachain/studio.py Implements server-side token revocation during logout and adds warning handling for error scenarios.
tests/test_cli_studio.py Updates logout tests to assert the revoke endpoint is called and adds new logout test scenarios (401 + custom URL).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/datachain/studio.py
Comment on lines +214 to +218
studio_url = (
conf.get("studio", {}).get("url")
or get_studio_env_variable("URL")
or STUDIO_URL
)
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

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

logout() resolves studio_url from config before checking DATACHAIN_STUDIO_URL (get_studio_env_variable("URL")). Elsewhere, Studio URL resolution prioritizes the env var (e.g., StudioClient.url and login()), so when DATACHAIN_STUDIO_URL is set this can revoke the token against a different host than the rest of the CLI uses. Consider aligning the precedence (env var first) or reusing a shared URL-resolution helper to keep behavior consistent across commands.

Copilot uses AI. Check for mistakes.
Comment thread tests/test_cli_studio.py
Comment on lines 95 to +104
def test_studio_logout():
with Config(ConfigLevel.GLOBAL).edit() as conf:
conf["studio"] = {"token": "isat_access_token"}
conf["studio"] = {"token": "isat_access_token", "url": STUDIO_URL}

with requests_mock.mock() as m:
m.post(
f"{STUDIO_URL}/api/token-logout",
json={"detail": "Token revoked successfully"},
)
assert main(["auth", "logout"]) == 0
Copy link

Copilot AI Apr 27, 2026

Choose a reason for hiding this comment

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

test_studio_logout() now sets studio.url in config, so it no longer exercises the fallback path where only a token is present (legacy configs) and logout() should default to DATACHAIN_STUDIO_URL/STUDIO_URL. Adding a test case for token-only config (and optionally env-var URL override) would help prevent regressions in the new URL-selection logic.

Copilot uses AI. Check for mistakes.
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 27, 2026

Codecov Report

❌ Patch coverage is 60.00000% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/datachain/studio.py 60.00% 3 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

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.

2 participants