Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 0021226

Browse files
authored
Add --next flag to config-ssh (#347)
1 parent 99b3008 commit 0021226

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

docs/coder_config-ssh.md

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ coder config-ssh [flags]
1515
```
1616
--filepath string override the default path of your ssh config file (default "~/.ssh/config")
1717
-h, --help help for config-ssh
18+
--next (alpha) uses coder tunnel to proxy ssh connection
1819
--remove remove the auto-generated Coder ssh config
1920
```
2021

internal/cmd/configssh.go

+17-3
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,23 @@ func configSSHCmd() *cobra.Command {
3535
var (
3636
configpath string
3737
remove = false
38+
next = false
3839
)
3940

4041
cmd := &cobra.Command{
4142
Use: "config-ssh",
4243
Short: "Configure SSH to access Coder environments",
4344
Long: "Inject the proper OpenSSH configuration into your local SSH config file.",
44-
RunE: configSSH(&configpath, &remove),
45+
RunE: configSSH(&configpath, &remove, &next),
4546
}
4647
cmd.Flags().StringVar(&configpath, "filepath", filepath.Join("~", ".ssh", "config"), "override the default path of your ssh config file")
4748
cmd.Flags().BoolVar(&remove, "remove", false, "remove the auto-generated Coder ssh config")
49+
cmd.Flags().BoolVar(&next, "next", false, "(alpha) uses coder tunnel to proxy ssh connection")
4850

4951
return cmd
5052
}
5153

52-
func configSSH(configpath *string, remove *bool) func(cmd *cobra.Command, _ []string) error {
54+
func configSSH(configpath *string, remove *bool, next *bool) func(cmd *cobra.Command, _ []string) error {
5355
return func(cmd *cobra.Command, _ []string) error {
5456
ctx := cmd.Context()
5557
usr, err := user.Current()
@@ -117,8 +119,20 @@ func configSSH(configpath *string, remove *bool) func(cmd *cobra.Command, _ []st
117119
if err != nil {
118120
return xerrors.Errorf("getting site workspace config: %w", err)
119121
}
122+
p2p := false
123+
if wconf.EnableP2P {
124+
if *next {
125+
p2p = true
126+
} else {
127+
fmt.Println("Note: NetworkingV2 is enabled on the coder deployment, use --next to enable it for ssh")
128+
}
129+
} else {
130+
if *next {
131+
return xerrors.New("NetworkingV2 feature is not enabled, cannot use --next flag")
132+
}
133+
}
120134

121-
newConfig := makeNewConfigs(user.Username, envsWithProviders, privateKeyFilepath, wconf.EnableP2P)
135+
newConfig := makeNewConfigs(user.Username, envsWithProviders, privateKeyFilepath, p2p)
122136

123137
err = os.MkdirAll(filepath.Dir(*configpath), os.ModePerm)
124138
if err != nil {

0 commit comments

Comments
 (0)