@@ -137,7 +137,6 @@ func configSSH() *cobra.Command {
137
137
sshConfigFile string
138
138
sshConfigOpts sshConfigOptions
139
139
usePreviousOpts bool
140
- coderConfigFile string
141
140
dryRun bool
142
141
skipProxyCommand bool
143
142
wireguard bool
@@ -198,15 +197,7 @@ func configSSH() *cobra.Command {
198
197
// Parse the previous configuration only if config-ssh
199
198
// has been run previously.
200
199
var lastConfig * sshConfigOptions
201
- var ok bool
202
- var coderConfigRaw []byte
203
- if coderConfigFile , coderConfigRaw , ok = readDeprecatedCoderConfigFile (homedir , coderConfigFile ); ok {
204
- // Deprecated: Remove after migration period.
205
- changes = append (changes , fmt .Sprintf ("Remove old auto-generated coder config file at %s" , coderConfigFile ))
206
- // Backwards compate, restore old options.
207
- c := sshConfigParseLastOptions (bytes .NewReader (coderConfigRaw ))
208
- lastConfig = & c
209
- } else if section , ok := sshConfigGetCoderSection (configRaw ); ok {
200
+ if section , ok := sshConfigGetCoderSection (configRaw ); ok {
210
201
c := sshConfigParseLastOptions (bytes .NewReader (section ))
211
202
lastConfig = & c
212
203
}
@@ -237,6 +228,8 @@ func configSSH() *cobra.Command {
237
228
}
238
229
// Selecting "no" will use the last config.
239
230
sshConfigOpts = * lastConfig
231
+ } else {
232
+ changes = append (changes , "Use new SSH options" )
240
233
}
241
234
// Only print when prompts are shown.
242
235
if yes , _ := cmd .Flags ().GetBool ("yes" ); ! yes {
@@ -245,14 +238,6 @@ func configSSH() *cobra.Command {
245
238
}
246
239
247
240
configModified := configRaw
248
-
249
- // Check for the presence of the coder Include
250
- // statement is present and add if missing.
251
- // Deprecated: Remove after migration period.
252
- if configModified , ok = removeDeprecatedSSHIncludeStatement (configModified ); ok {
253
- changes = append (changes , fmt .Sprintf ("Remove %q from %s" , "Include coder" , sshConfigFile ))
254
- }
255
-
256
241
root := createConfig (cmd )
257
242
258
243
buf := & bytes.Buffer {}
@@ -313,17 +298,34 @@ func configSSH() *cobra.Command {
313
298
_ , _ = buf .Write (after )
314
299
315
300
if ! bytes .Equal (configModified , buf .Bytes ()) {
316
- changes = append (changes , fmt .Sprintf ("Update coder config section in %s" , sshConfigFile ))
301
+ changes = append (changes , fmt .Sprintf ("Update the coder section in %s" , sshConfigFile ))
317
302
configModified = buf .Bytes ()
318
303
}
319
304
320
- if len (changes ) > 0 {
321
- dryRunDisclaimer := ""
322
- if dryRun {
323
- dryRunDisclaimer = " (dry-run, no changes will be made)"
305
+ if len (changes ) == 0 {
306
+ _ , _ = fmt .Fprintf (out , "No changes to make.\n " )
307
+ return nil
308
+ }
309
+
310
+ if dryRun {
311
+ _ , _ = fmt .Fprintf (out , "Dry run, the following changes would be made to your SSH configuration:\n \n * %s\n \n " , strings .Join (changes , "\n * " ))
312
+
313
+ color := isTTYOut (cmd )
314
+ diff , err := diffBytes (sshConfigFile , configRaw , configModified , color )
315
+ if err != nil {
316
+ return xerrors .Errorf ("diff failed: %w" , err )
317
+ }
318
+ if len (diff ) > 0 {
319
+ // Write diff to stdout.
320
+ _ , _ = fmt .Fprintf (cmd .OutOrStdout (), "%s" , diff )
324
321
}
322
+
323
+ return nil
324
+ }
325
+
326
+ if len (changes ) > 0 {
325
327
_ , err = cliui .Prompt (cmd , cliui.PromptOptions {
326
- Text : fmt .Sprintf ("The following changes will be made to your SSH configuration:\n \n * %s\n \n Continue?%s " , strings .Join (changes , "\n * " ), dryRunDisclaimer ),
328
+ Text : fmt .Sprintf ("The following changes will be made to your SSH configuration:\n \n * %s\n \n Continue?" , strings .Join (changes , "\n * " )),
327
329
IsConfirm : true ,
328
330
})
329
331
if err != nil {
@@ -335,47 +337,18 @@ func configSSH() *cobra.Command {
335
337
}
336
338
}
337
339
338
- if dryRun {
339
- color := isTTYOut (cmd )
340
- diffFns := []func () ([]byte , error ){
341
- func () ([]byte , error ) { return diffBytes (sshConfigFile , configRaw , configModified , color ) },
342
- }
343
- if len (coderConfigRaw ) > 0 {
344
- // Deprecated: Remove after migration period.
345
- diffFns = append (diffFns , func () ([]byte , error ) { return diffBytes (coderConfigFile , coderConfigRaw , nil , color ) })
346
- }
347
-
348
- for _ , diffFn := range diffFns {
349
- diff , err := diffFn ()
350
- if err != nil {
351
- return xerrors .Errorf ("diff failed: %w" , err )
352
- }
353
- if len (diff ) > 0 {
354
- // Write diff to stdout.
355
- _ , _ = fmt .Fprintf (cmd .OutOrStdout (), "\n %s" , diff )
356
- }
357
- }
358
- } else {
359
- if ! bytes .Equal (configRaw , configModified ) {
360
- err = writeWithTempFileAndMove (sshConfigFile , bytes .NewReader (configModified ))
361
- if err != nil {
362
- return xerrors .Errorf ("write ssh config failed: %w" , err )
363
- }
364
- }
365
- // Deprecated: Remove after migration period.
366
- if len (coderConfigRaw ) > 0 {
367
- err = os .Remove (coderConfigFile )
368
- if err != nil {
369
- return xerrors .Errorf ("remove coder config failed: %w" , err )
370
- }
340
+ if ! bytes .Equal (configRaw , configModified ) {
341
+ err = writeWithTempFileAndMove (sshConfigFile , bytes .NewReader (configModified ))
342
+ if err != nil {
343
+ return xerrors .Errorf ("write ssh config failed: %w" , err )
371
344
}
372
345
}
373
346
374
347
if len (workspaceConfigs ) > 0 {
375
348
_ , _ = fmt .Fprintln (out , "You should now be able to ssh into your workspace." )
376
- _ , _ = fmt .Fprintf (out , "For example, try running:\n \n \t $ ssh coder.%s\n \n " , workspaceConfigs [0 ].Name )
349
+ _ , _ = fmt .Fprintf (out , "For example, try running:\n \n \t $ ssh coder.%s\n " , workspaceConfigs [0 ].Name )
377
350
} else {
378
- _ , _ = fmt .Fprint (out , "You don't have any workspaces yet, try creating one with:\n \n \t $ coder create <workspace>\n \n " )
351
+ _ , _ = fmt .Fprint (out , "You don't have any workspaces yet, try creating one with:\n \n \t $ coder create <workspace>\n " )
379
352
}
380
353
return nil
381
354
},
@@ -389,10 +362,6 @@ func configSSH() *cobra.Command {
389
362
cliflag .BoolVarP (cmd .Flags (), & wireguard , "wireguard" , "" , "CODER_CONFIG_SSH_WIREGUARD" , false , "Whether to use Wireguard for SSH tunneling." )
390
363
_ = cmd .Flags ().MarkHidden ("wireguard" )
391
364
392
- // Deprecated: Remove after migration period.
393
- cmd .Flags ().StringVar (& coderConfigFile , "test.ssh-coder-config-file" , sshDefaultCoderConfigFileName , "Specifies the path to an Coder SSH config file. Useful for testing." )
394
- _ = cmd .Flags ().MarkHidden ("test.ssh-coder-config-file" )
395
-
396
365
cliui .AllowSkipPrompt (cmd )
397
366
398
367
return cmd
0 commit comments