-
Notifications
You must be signed in to change notification settings - Fork 8
feat: Implement User Authentication and Session Ownership #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 7 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
947a8b4
Add authentication support and custom base URL handling
yuxiang-wu efb63b6
Revise README.md to enhance clarity and structure of ML engineering t…
yuxiang-wu cb207ac
Enhance login process in `cli.py` to support automatic browser openin…
yuxiang-wu 30b76ac
fix format with ruff
yuxiang-wu 1f3c24b
Add logout command parser to CLI
yuxiang-wu d966b2b
Refactor login error handling in `cli.py` to improve response managem…
yuxiang-wu 5650342
Merge branch 'main' into feat-user-auth.
yuxiang-wu 8e60af1
update branch based on review
DhruvSrikanth ff7402c
upgrade package version
DhruvSrikanth 754af26
add dashboard url
DhruvSrikanth 1b9ea6d
Update .gitignore and add .repomixignore
yuxiang-wu f62e7cb
minor bug fixes
DhruvSrikanth e790a0b
minor bug fixes
DhruvSrikanth ace2f4e
minor bug fixes
DhruvSrikanth 44e522d
Merge branch 'remote-feat-user-auth' into feat-user-auth
DhruvSrikanth 7f0962b
update final tree panel header
DhruvSrikanth 51a4cec
lint and format code
DhruvSrikanth d1c5bc0
Refactor imports and clean up comments in `weco/cli.py`.
yuxiang-wu d3a3956
Merge branch 'feat-user-auth' of github.com:WecoAI/weco-cli into feat…
yuxiang-wu a86be78
Delete examples/hello-kernel-world/response.json
DhruvSrikanth 0634922
Fix video link in README.md
DhruvSrikanth 31d4433
Merge branch 'main' into feat-user-auth
DhruvSrikanth 0a19f08
update release workflow to read version from pyproject
DhruvSrikanth c6d67f9
update api base url
DhruvSrikanth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,10 @@ | ||
| import os | ||
|
|
||
| # DO NOT EDIT | ||
| __pkg_version__ = "0.2.8" | ||
| __api_version__ = "v1" | ||
|
|
||
| __base_url__ = f"https://api.aide.weco.ai/{__api_version__}" | ||
| # If user specifies a custom base URL, use that instead | ||
| if os.environ.get("WECO_BASE_URL"): | ||
| __base_url__ = os.environ.get("WECO_BASE_URL") |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # weco/auth.py | ||
| import os | ||
| import pathlib | ||
| import json | ||
| import stat | ||
|
|
||
| CONFIG_DIR = pathlib.Path.home() / ".config" / "weco" | ||
| CREDENTIALS_FILE = CONFIG_DIR / "credentials.json" | ||
|
|
||
|
|
||
| def ensure_config_dir(): | ||
| """Ensures the configuration directory exists.""" | ||
| CONFIG_DIR.mkdir(parents=True, exist_ok=True) | ||
| # Ensure directory permissions are secure (optional but good practice) | ||
| try: | ||
| os.chmod(CONFIG_DIR, stat.S_IRWXU) # Read/Write/Execute for owner only | ||
| except OSError as e: | ||
| print(f"Warning: Could not set permissions on {CONFIG_DIR}: {e}") | ||
|
|
||
|
|
||
| def save_api_key(api_key: str): | ||
| """Saves the Weco API key securely.""" | ||
| ensure_config_dir() | ||
| credentials = {"api_key": api_key} | ||
| try: | ||
| with open(CREDENTIALS_FILE, "w") as f: | ||
| json.dump(credentials, f) | ||
| # Set file permissions to read/write for owner only (600) | ||
| os.chmod(CREDENTIALS_FILE, stat.S_IRUSR | stat.S_IWUSR) | ||
| except IOError as e: | ||
| print(f"Error: Could not write credentials file at {CREDENTIALS_FILE}: {e}") | ||
| except OSError as e: | ||
| print(f"Warning: Could not set permissions on {CREDENTIALS_FILE}: {e}") | ||
|
|
||
|
|
||
| def load_api_key() -> str | None: | ||
| """Loads the Weco API key.""" | ||
| if not CREDENTIALS_FILE.exists(): | ||
| return None | ||
| try: | ||
| # Check permissions before reading (optional but safer) | ||
| file_stat = os.stat(CREDENTIALS_FILE) | ||
| if file_stat.st_mode & (stat.S_IRWXG | stat.S_IRWXO): # Check if group/other have permissions | ||
| print(f"Warning: Credentials file {CREDENTIALS_FILE} has insecure permissions. Please set to 600.") | ||
| # Optionally, refuse to load or try to fix permissions | ||
|
|
||
| with open(CREDENTIALS_FILE, "r") as f: | ||
| credentials = json.load(f) | ||
| return credentials.get("api_key") | ||
| except (IOError, json.JSONDecodeError, OSError) as e: | ||
| print(f"Warning: Could not read or parse credentials file at {CREDENTIALS_FILE}: {e}") | ||
| return None | ||
|
|
||
|
|
||
| def clear_api_key(): | ||
| """Removes the stored API key.""" | ||
| if CREDENTIALS_FILE.exists(): | ||
| try: | ||
| os.remove(CREDENTIALS_FILE) | ||
| print("Logged out successfully.") | ||
| except OSError as e: | ||
| print(f"Error: Could not remove credentials file at {CREDENTIALS_FILE}: {e}") | ||
| else: | ||
| print("Already logged out.") |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.