[PR-716]: Improve Handling for PAT and USER_ID#702
Merged
srikanthbachala20 merged 4 commits intomasterfrom Jul 15, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the Clarifai CLI’s authentication and logging to consolidate credential validation, standardize output via a logger, and improve user feedback and exit behavior.
- Consolidates PAT validation by replacing
validate_pat_tokenwithvalidate_context_authand shifting from return values to structured logging andsys.exit. - Replaces
printstatements withlogger.info/logger.erroracross commands for consistent logging. - Enhances error handling in
local_runnerand login/create commands to clearly log missing or invalid credentials before exiting.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| clarifai/utils/cli.py | Introduces validate_context_auth with structured logging and exit behavior; deprecates returns |
| clarifai/cli/model.py | Updates local_runner to log and exit on missing user_id or pat; adds display of masked PAT |
| clarifai/cli/base.py | Switches CLI commands to use validate_context_auth and replaces prints with logger calls |
Comments suppressed due to low confidence (2)
clarifai/utils/cli.py:179
- Update the function signature and docstring of
validate_context_authto reflect that it no longer returns a tuple but exits directly. Consider using-> NoReturnand removing or revising the Returns section.
def validate_context_auth(pat: str, user_id: str, api_base: str = None) -> Tuple[bool, str]:
clarifai/cli/model.py:475
- The
loggeris used here but not imported in this module; addfrom clarifai.utils.logging import loggerat the top of the file.
logger.info(f"Current user_id: {user_id}")
luv-bansal
reviewed
Jul 15, 2025
Contributor
luv-bansal
left a comment
There was a problem hiding this comment.
Just small comments related to better message display. Else looks good!
Minimum allowed line rate is |
Merged
srikanthbachala20
added a commit
that referenced
this pull request
Jul 29, 2025
* [PR-716]: Improve Handling for PAT and USER_ID * [PR-716]: Improve Handling for PAT and USER_ID * [PR-716]: Improve Handling for PAT and USER_ID * [PR-716]: Improve Handling for PAT and USER_ID
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request refactors the authentication and logging mechanisms in the Clarifai CLI to improve maintainability and user feedback. The key changes include replacing the
validate_pat_tokenfunction withvalidate_context_auth, introducing structured logging via theloggermodule, and enhancing error handling and user feedback.Authentication Refactor:
validate_pat_tokenwithvalidate_context_authfor validating context credentials, consolidating the logic and improving clarity. (clarifai/cli/base.py,clarifai/utils/cli.py) [1] [2]validate_context_authfunction to use structured logging for success and error messages, replacing return values withsys.exit(1)for invalid credentials. (clarifai/utils/cli.py)Logging Enhancements:
printstatements withlogger.infoandlogger.erroracross the CLI commands to standardize logging and improve debugging. (clarifai/cli/base.py,clarifai/cli/model.py) [1] [2] [3] [4]loggerimport to relevant files for consistent logging usage. (clarifai/utils/cli.py)Error Handling Improvements:
local_runnerfunction, ensuring clear user guidance and proper exits. (clarifai/cli/model.py)validate_context_authfor common issues like invalid tokens, SSL errors, and network problems. (clarifai/utils/cli.py)