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

Commit343d118

Browse files
authored
fix: Clean upcoder config-ssh dry-run behavior (#3660)
This commit also drops old deprecated code.Fixes#2982
1 parent7a71180 commit343d118

File tree

3 files changed

+40
-263
lines changed

3 files changed

+40
-263
lines changed

‎cli/configssh.go

Lines changed: 32 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ func configSSH() *cobra.Command {
137137
sshConfigFilestring
138138
sshConfigOptssshConfigOptions
139139
usePreviousOptsbool
140-
coderConfigFilestring
141140
dryRunbool
142141
skipProxyCommandbool
143142
wireguardbool
@@ -198,15 +197,7 @@ func configSSH() *cobra.Command {
198197
// Parse the previous configuration only if config-ssh
199198
// has been run previously.
200199
varlastConfig*sshConfigOptions
201-
varokbool
202-
varcoderConfigRaw []byte
203-
ifcoderConfigFile,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-
}elseifsection,ok:=sshConfigGetCoderSection(configRaw);ok {
200+
ifsection,ok:=sshConfigGetCoderSection(configRaw);ok {
210201
c:=sshConfigParseLastOptions(bytes.NewReader(section))
211202
lastConfig=&c
212203
}
@@ -237,6 +228,8 @@ func configSSH() *cobra.Command {
237228
}
238229
// Selecting "no" will use the last config.
239230
sshConfigOpts=*lastConfig
231+
}else {
232+
changes=append(changes,"Use new SSH options")
240233
}
241234
// Only print when prompts are shown.
242235
ifyes,_:=cmd.Flags().GetBool("yes");!yes {
@@ -245,14 +238,6 @@ func configSSH() *cobra.Command {
245238
}
246239

247240
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-
ifconfigModified,ok=removeDeprecatedSSHIncludeStatement(configModified);ok {
253-
changes=append(changes,fmt.Sprintf("Remove %q from %s","Include coder",sshConfigFile))
254-
}
255-
256241
root:=createConfig(cmd)
257242

258243
buf:=&bytes.Buffer{}
@@ -313,17 +298,34 @@ func configSSH() *cobra.Command {
313298
_,_=buf.Write(after)
314299

315300
if!bytes.Equal(configModified,buf.Bytes()) {
316-
changes=append(changes,fmt.Sprintf("Updatecoder config section in %s",sshConfigFile))
301+
changes=append(changes,fmt.Sprintf("Updatethe coder section in %s",sshConfigFile))
317302
configModified=buf.Bytes()
318303
}
319304

320-
iflen(changes)>0 {
321-
dryRunDisclaimer:=""
322-
ifdryRun {
323-
dryRunDisclaimer=" (dry-run, no changes will be made)"
305+
iflen(changes)==0 {
306+
_,_=fmt.Fprintf(out,"No changes to make.\n")
307+
returnnil
308+
}
309+
310+
ifdryRun {
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+
iferr!=nil {
316+
returnxerrors.Errorf("diff failed: %w",err)
317+
}
318+
iflen(diff)>0 {
319+
// Write diff to stdout.
320+
_,_=fmt.Fprintf(cmd.OutOrStdout(),"%s",diff)
324321
}
322+
323+
returnnil
324+
}
325+
326+
iflen(changes)>0 {
325327
_,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 * ")),
327329
IsConfirm:true,
328330
})
329331
iferr!=nil {
@@ -335,47 +337,18 @@ func configSSH() *cobra.Command {
335337
}
336338
}
337339

338-
ifdryRun {
339-
color:=isTTYOut(cmd)
340-
diffFns:= []func() ([]byte,error){
341-
func() ([]byte,error) {returndiffBytes(sshConfigFile,configRaw,configModified,color) },
342-
}
343-
iflen(coderConfigRaw)>0 {
344-
// Deprecated: Remove after migration period.
345-
diffFns=append(diffFns,func() ([]byte,error) {returndiffBytes(coderConfigFile,coderConfigRaw,nil,color) })
346-
}
347-
348-
for_,diffFn:=rangediffFns {
349-
diff,err:=diffFn()
350-
iferr!=nil {
351-
returnxerrors.Errorf("diff failed: %w",err)
352-
}
353-
iflen(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-
iferr!=nil {
362-
returnxerrors.Errorf("write ssh config failed: %w",err)
363-
}
364-
}
365-
// Deprecated: Remove after migration period.
366-
iflen(coderConfigRaw)>0 {
367-
err=os.Remove(coderConfigFile)
368-
iferr!=nil {
369-
returnxerrors.Errorf("remove coder config failed: %w",err)
370-
}
340+
if!bytes.Equal(configRaw,configModified) {
341+
err=writeWithTempFileAndMove(sshConfigFile,bytes.NewReader(configModified))
342+
iferr!=nil {
343+
returnxerrors.Errorf("write ssh config failed: %w",err)
371344
}
372345
}
373346

374347
iflen(workspaceConfigs)>0 {
375348
_,_=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)
377350
}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")
379352
}
380353
returnnil
381354
},
@@ -389,10 +362,6 @@ func configSSH() *cobra.Command {
389362
cliflag.BoolVarP(cmd.Flags(),&wireguard,"wireguard","","CODER_CONFIG_SSH_WIREGUARD",false,"Whether to use Wireguard for SSH tunneling.")
390363
_=cmd.Flags().MarkHidden("wireguard")
391364

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-
396365
cliui.AllowSkipPrompt(cmd)
397366

398367
returncmd

‎cli/configssh_old.go

Lines changed: 0 additions & 66 deletions
This file was deleted.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp