-
Notifications
You must be signed in to change notification settings - Fork 14
feat: automatically find existing IdentityFile
#39
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -68,6 +68,22 @@ def posix_shell(chan): | |||||||||||||||||||||
| finally: | ||||||||||||||||||||||
| termios.tcsetattr(sys.stdin, termios.TCSADRAIN, oldtty) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| def get_identity_files(path: str = "~/.ssh"): | ||||||||||||||||||||||
| fullpath = os.path.expanduser(path) | ||||||||||||||||||||||
| keys = [] | ||||||||||||||||||||||
| for file in os.listdir(fullpath): | ||||||||||||||||||||||
| # if not ends with .pub and starts with id_ | ||||||||||||||||||||||
| if file.startswith("id_") and not file.endswith(".pub") and os.path.isfile(os.path.join(fullpath, file)): | ||||||||||||||||||||||
| keys.append(os.path.join(path, file)) | ||||||||||||||||||||||
|
Comment on lines
+74
to
+77
|
||||||||||||||||||||||
| if len(keys) == 0: | ||||||||||||||||||||||
| # keys not found, return default key | ||||||||||||||||||||||
| click.echo(f"[Warning] identity file not found, using default") | ||||||||||||||||||||||
| return os.path.join(path, "id_rsa") | ||||||||||||||||||||||
|
Comment on lines
+77
to
+81
|
||||||||||||||||||||||
| keys.append(os.path.join(path, file)) | |
| if len(keys) == 0: | |
| # keys not found, return default key | |
| click.echo(f"[Warning] identity file not found, using default") | |
| return os.path.join(path, "id_rsa") | |
| keys.append(os.path.join(fullpath, file)) | |
| if len(keys) == 0: | |
| # keys not found, return default key | |
| click.echo(f"[Warning] identity file not found, using default") | |
| return os.path.join(fullpath, "id_rsa") |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function uses click.echo for the warning on line 80 but uses print for the warning on line 85. This is inconsistent. Since this is a Click-based CLI application, click.echo should be used consistently for all output.
| print(f"[Warning] multiple identity files found: {keys}") | |
| click.echo(f"[Warning] multiple identity files found: {keys}") |
Copilot
AI
Dec 23, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new get_identity_files() function is called during the add command flow, but there are no tests covering this new behavior. Since the repository has comprehensive test coverage for CLI commands (as seen in test_cli.py), tests should be added to verify the identity file discovery functionality, including edge cases like missing .ssh directory, multiple identity files, and no identity files found.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function does not handle potential permission errors when accessing the .ssh directory. If the user lacks read permissions for the directory,
os.listdir()will raise a PermissionError. Consider adding error handling to gracefully fall back to the default identity file in such cases.