Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: Refactor CLI config-ssh to improve UX#1900

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mafredri merged 38 commits intomainfrommafredri/ssh-config-refactor-2
Jun 8, 2022

Conversation

mafredri
Copy link
Member

@mafredrimafredri commentedMay 30, 2022
edited
Loading

This PR improves the UX ofcoder config-ssh with multiple QoL improvements. Replaces#1848.

  • Magic block is replaced by Include statement
  • Writes are only done on changes
  • Inform user of changes via prompt
  • Allow displaying changes via--diff
  • Remove magic block if present
  • Safer config writing via tmp-file + rename
  • Parse previousconfig-ssh options, compare to new options and ask to use new (otherwise old ones are used)
  • Tests for the new functionality

Fixes#1326

TODO:

  • Auto-update~/.ssh/coder oncoder create andcoder delete
    • This will be be left to a follow-up PR, or scrapped in unwanted

Examples:

New config:

❯ coder config-ssh> The following changes will be made to your SSH configuration:    * Remove old config block (START-CODER/END-CODER) from /home/maf/.ssh/config    * Add "Include coder" to /home/maf/.ssh/config    * Write auto-generated coder config file to /home/maf/.ssh/coder  To see changes, run diff:    $ coder config-ssh --diff  Continue? (yes/no) yesYou should now be able to ssh into your workspace.For example, try running:$ ssh coder.work

Options changed:

❯ coder config-ssh -o ForwardAgent=yes> New options differ from previous options:  New options:    * ssh-option: ForwardAgent=yes  Previous options: none  Use new options? (yes/no) yes> The following changes will be made to your SSH configuration:    * Update auto-generated coder config file in /home/maf/.ssh/coder  To see changes, run diff:    $ coder config-ssh --ssh-option "ForwardAgent=yes" --diff  Continue? (yes/no) yesYou should now be able to ssh into your workspace.For example, try running:$ ssh coder.work

Options would change => select no (no changes):

❯ coder config-ssh -o ForwardAgent=yes -o IdentityAgent=none> New options differ from previous options:  New options:    * ssh-option: ForwardAgent=yes    * ssh-option: IdentityAgent=none  Previous options:    * ssh-option: ForwardAgent=yes  Use new options? (yes/no) noYou should now be able to ssh into your workspace.For example, try running:$ ssh coder.work

Diff:

❯ coder config-ssh --diffChanges:  * Remove old config block (START-CODER/END-CODER) from /home/maf/.ssh/config  * Add "Include coder" to /home/maf/.ssh/config  * Write auto-generated coder config file to /home/maf/.ssh/coder--- /home/maf/.ssh/config+++ /home/maf/.ssh/config.new@@ -1,23 +1,6 @@+Include coder+ Host github.com HostName github.com User git-# ------------START-CODER------------# This was generated by "coder config-ssh".-#-# To remove this blob, run:-#-#    coder config-ssh --remove-#-# You should not hand-edit this section, unless you are deleting it.--Host coder.work-ForwardAgent=yes-HostName coder.work-ConnectTimeout=0-StrictHostKeyChecking=no-UserKnownHostsFile=/dev/null-LogLevel ERROR-ProxyCommand "coder" --global-config "/Users/maf/Library/Application Support/coderv2" ssh --stdio work--# ------------END-CODER--------------- /home/maf/.ssh/coder+++ /home/maf/.ssh/coder.new@@ -0,0 +1,14 @@+# This file is managed by coder. DO NOT EDIT.+#+# You should not hand-edit this file, all changes will be lost upon workspace+# creation, deletion or when running "coder config-ssh".+#+# Last config-ssh options:+#+Host coder.work+HostName coder.work+ConnectTimeout=0+StrictHostKeyChecking=no+UserKnownHostsFile=/dev/null+LogLevel ERROR+ProxyCommand "coder" --global-config "/home/maf/.config/coderv2" ssh --stdio workexit status 1

@mafredri
Copy link
MemberAuthor

Just noticed we need to place theInclude directive before the firstHost entry, otherwise it will be interpreted as part of one and included conditionally.

Copy link
Member

@johnstcnjohnstcn left a comment

Choose a reason for hiding this comment

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

I like the approach so far! The--diff option is really cool!

Some observations:

  • We should keep the configs under~/.ssh because that's where they always go.
  • We should check that we "own"~/.ssh/coder (maybe by checking for a magic string) before writing it

mafredri reacted with thumbs up emoji
@mafredri
Copy link
MemberAuthor

mafredri commentedMay 31, 2022
edited
Loading

@johnstcn great observations, I've made the necessary changes.

I've now also implemented options parsing, socoder config-ssh can suggest to re-use previous options, whereascoder config-ssh -o MyOption=yes assumes the user knows what they're doing. As a result, the full diff command is output in the prompt. The two different scenarios look like this:

#
# To remove this blob, run:
# You should not hand-edit this file, all changes will be lost upon workspace
# creation, deletion or when running "coder config-ssh".`
Copy link
MemberAuthor

@mafredrimafredriMay 31, 2022
edited
Loading

Choose a reason for hiding this comment

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

I really would love to see this feature. (i.e. runningcoder create will automatically update the config). But I suggest we rewrite this comment to not include it, open up a ticket for this functionality, and leave it for a follow-up PR. (PS. This is one reason we write the used options to the config file.)

Copy link
Member

Choose a reason for hiding this comment

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

TODO: rewrite comment

@mafredrimafredri marked this pull request as ready for reviewJune 1, 2022 16:59
Copy link
Member

@johnstcnjohnstcn left a comment

Choose a reason for hiding this comment

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

I haven't tested this locally, but looks good to me. I appreciate the thorough tests!

I do think there's still scope for refactoring; a lot of the code related to reading and writing SSH configs seems like it could be ripped out to its own module. This should probably done in a separate PR however!

#
# To remove this blob, run:
# You should not hand-edit this file, all changes will be lost upon workspace
# creation, deletion or when running "coder config-ssh".`
Copy link
Member

Choose a reason for hiding this comment

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

TODO: rewrite comment

@mafredrimafredri self-assigned thisJun 2, 2022
@mafredrimafredriforce-pushed themafredri/ssh-config-refactor-2 branch fromaf23128 to142683bCompareJune 6, 2022 16:14
- Magic block is replaced by Include statement- Writes are only done on changes- Inform user of changes via prompt- Allow displaying changes via `--diff`- Remove magic block if presentTODO:- [ ] Parse previous `config-ssh` options and suggest re-using them- [ ] Auto-update `~/.ssh/coder` on `coder create` and `coder delete`- [ ] Tests for the new functionalityFixes#1326
@mafredrimafredriforce-pushed themafredri/ssh-config-refactor-2 branch from142683b toe084a73CompareJune 8, 2022 08:06
@mafredrimafredriforce-pushed themafredri/ssh-config-refactor-2 branch frome084a73 tof1be4c6CompareJune 8, 2022 08:07
@mafredrimafredri merged commitb65259f intomainJun 8, 2022
@mafredrimafredri deleted the mafredri/ssh-config-refactor-2 branchJune 8, 2022 08:45
kylecarbs pushed a commit that referenced this pull requestJun 10, 2022
- Magic block is replaced by Include statement- Writes are only done on changes- Inform user of changes via prompt- Allow displaying changes via `--diff`- Remove magic block if present- Safer config writing via tmp-file + rename- Parse previous `config-ssh` options, compare to new options and ask to use new (otherwise old ones are used)- Tests the new functionalityFixes#1326
mafredri added a commit that referenced this pull requestJun 15, 2022
This commit partially reverts#1900 and removes the separate`~/.ssh/coder` config file whilst keeping most other features.This will allow us to remain more compatible with different IDEs.Fixes#2317
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@johnstcnjohnstcnjohnstcn approved these changes

@kylecarbskylecarbsAwaiting requested review from kylecarbs

Assignees

@mafredrimafredri

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Modify user SSH config with singleInclude statement instead of managed block
2 participants
@mafredri@johnstcn

[8]ページ先頭

©2009-2025 Movatter.jp