Skip to content

Commit 51ee7be

Browse files
authored
Shellpref for sshconfig import (#270)
1 parent 5ce7b92 commit 51ee7be

5 files changed

Lines changed: 48 additions & 29 deletions

File tree

src/app/common/modals/editremoteconn.less

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
width: 100%;
2121
}
2222

23+
.import-edit-warning {
24+
display: flex;
25+
flex-direction: row;
26+
align-items: flex-start;
27+
}
28+
2329
.name-actions-section {
2430
margin-bottom: 10px;
2531
display: flex;

src/app/common/modals/editremoteconn.tsx

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ class EditRemoteConnModal extends React.Component<{}, {}> {
5858
return this.selectedRemote?.local;
5959
}
6060

61+
isImportedRemote(): boolean {
62+
return this.selectedRemote?.sshconfigsrc == "sshconfig-import";
63+
}
64+
6165
componentDidMount(): void {
6266
mobx.action(() => {
6367
this.tempAlias.set(this.selectedRemote?.remotealias);
@@ -259,6 +263,27 @@ class EditRemoteConnModal extends React.Component<{}, {}> {
259263
);
260264
}
261265

266+
renderImportedRemoteEditWarning() {
267+
return (
268+
<div className="import-edit-warning">
269+
<Tooltip
270+
message={
271+
<span>
272+
Most options for connections imported from an ssh config file cannot be edited. For these
273+
changes, you must edit the config file and import it again. The shell preference can be
274+
edited, but will return to the default if you import again. It will stay changed if you
275+
follow <a href="https://docs.waveterm.dev/features/sshconfig-imports">this procedure</a>.
276+
</span>
277+
}
278+
icon={<i className="fa-sharp fa-regular fa-fw fa-triangle-exclamation" />}
279+
>
280+
<i className="fa-sharp fa-regular fa-fw fa-triangle-exclamation" />
281+
</Tooltip>
282+
&nbsp;SSH Config Import Behavior
283+
</div>
284+
);
285+
}
286+
262287
renderAuthMode() {
263288
let authMode = this.tempAuthMode.get();
264289
return (
@@ -344,16 +369,18 @@ class EditRemoteConnModal extends React.Component<{}, {}> {
344369
return null;
345370
}
346371
let isLocal = this.isLocalRemote();
372+
let isImported = this.isImportedRemote();
347373
return (
348374
<Modal className="erconn-modal">
349375
<Modal.Header title="Edit Connection" onClose={this.model.closeModal} />
350376
<div className="wave-modal-body">
351377
<div className="name-actions-section">
352378
<div className="name text-primary">{util.getRemoteName(this.selectedRemote)}</div>
353379
</div>
354-
<If condition={!isLocal}>{this.renderAlias()}</If>
355-
<If condition={!isLocal}>{this.renderAuthMode()}</If>
356-
<If condition={!isLocal}>{this.renderConnectMode()}</If>
380+
<If condition={!isLocal && !isImported}>{this.renderAlias()}</If>
381+
<If condition={!isLocal && !isImported}>{this.renderAuthMode()}</If>
382+
<If condition={!isLocal && !isImported}>{this.renderConnectMode()}</If>
383+
<If condition={isImported}>{this.renderImportedRemoteEditWarning()}</If>
357384
{this.renderShellPref()}
358385
<If condition={!util.isBlank(this.remoteEdit?.errorstr)}>
359386
<div className="settings-field settings-error">Error: {this.remoteEdit?.errorstr}</div>

src/app/common/modals/modals.tsx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,17 +1026,6 @@ class ViewRemoteConnDetailModal extends React.Component<{}, {}> {
10261026
cancelInstallButton = <></>;
10271027
}
10281028
if (remote.sshconfigsrc == "sshconfig-import") {
1029-
updateAuthButton = (
1030-
<Button theme="secondary" disabled={true}>
1031-
Edit
1032-
<Tooltip
1033-
message={`Connections imported from an ssh config file cannot be edited inside waveterm. To edit these, you must edit the config file and import it again.`}
1034-
icon={<i className="fa-sharp fa-regular fa-fw fa-ban" />}
1035-
>
1036-
<i className="fa-sharp fa-regular fa-fw fa-ban" />
1037-
</Tooltip>
1038-
</Button>
1039-
);
10401029
archiveButton = (
10411030
<Button theme="secondary" onClick={() => this.clickArchive()}>
10421031
Delete

src/app/common/modals/viewremoteconndetail.tsx

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -209,17 +209,6 @@ class ViewRemoteConnDetailModal extends React.Component<{}, {}> {
209209
cancelInstallButton = <></>;
210210
}
211211
if (remote.sshconfigsrc == "sshconfig-import") {
212-
updateAuthButton = (
213-
<Button theme="secondary" disabled={true}>
214-
Edit
215-
<Tooltip
216-
message={`Connections imported from an ssh config file cannot be edited inside waveterm. To edit these, you must edit the config file and import it again.`}
217-
icon={<i className="fa-sharp fa-regular fa-fw fa-ban" />}
218-
>
219-
<i className="fa-sharp fa-regular fa-fw fa-ban" />
220-
</Tooltip>
221-
</Button>
222-
);
223212
archiveButton = (
224213
<Button theme="secondary" onClick={() => this.clickArchive()}>
225214
Delete

wavesrv/pkg/cmdrunner/cmdrunner.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,9 +1420,6 @@ func RemoteSetCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (ss
14201420
if err != nil {
14211421
return nil, err
14221422
}
1423-
if ids.Remote.RState.SSHConfigSrc == sstore.SSHConfigSrcTypeImport {
1424-
return nil, fmt.Errorf("/remote:new cannot update imported remote")
1425-
}
14261423
visualEdit := resolveBool(pk.Kwargs["visual"], false)
14271424
isSubmitted := resolveBool(pk.Kwargs["submit"], false)
14281425
editArgs, err := parseRemoteEditArgs(false, pk, ids.Remote.MShell.IsLocal())
@@ -1542,6 +1539,7 @@ type HostInfoType struct {
15421539
SshKeyFile string
15431540
ConnectMode string
15441541
Ignore bool
1542+
ShellPref string
15451543
}
15461544

15471545
func createSshImportSummary(changeList map[string][]string) string {
@@ -1637,6 +1635,13 @@ func NewHostInfo(hostName string) (*HostInfoType, error) {
16371635
connectMode = sstore.ConnectModeManual
16381636
}
16391637

1638+
shellPref := sstore.ShellTypePref_Detect
1639+
if cfgWaveOptions["shellpref"] == "bash" {
1640+
shellPref = "bash"
1641+
} else if cfgWaveOptions["shellpref"] == "zsh" {
1642+
shellPref = "zsh"
1643+
}
1644+
16401645
outHostInfo := new(HostInfoType)
16411646
outHostInfo.Host = hostName
16421647
outHostInfo.User = userName
@@ -1645,6 +1650,7 @@ func NewHostInfo(hostName string) (*HostInfoType, error) {
16451650
outHostInfo.SshKeyFile = sshKeyFile
16461651
outHostInfo.ConnectMode = connectMode
16471652
outHostInfo.Ignore = shouldIgnore
1653+
outHostInfo.ShellPref = shellPref
16481654
return outHostInfo, nil
16491655
}
16501656

@@ -1709,14 +1715,15 @@ func RemoteConfigParseCommand(ctx context.Context, pk *scpacket.FeCommandPacketT
17091715
if hostInfo.SshKeyFile != "" {
17101716
editMap[sstore.RemoteField_SSHKey] = hostInfo.SshKeyFile
17111717
}
1718+
editMap[sstore.RemoteField_ShellPref] = hostInfo.ShellPref
17121719
msh := remote.GetRemoteById(previouslyImportedRemote.RemoteId)
17131720
if msh == nil {
17141721
remoteChangeList["updateErr"] = append(remoteChangeList["updateErr"], hostInfo.CanonicalName)
17151722
log.Printf("strange, msh for remote %s [%s] not found\n", hostInfo.CanonicalName, previouslyImportedRemote.RemoteId)
17161723
continue
17171724
}
17181725

1719-
if msh.Remote.ConnectMode == hostInfo.ConnectMode && msh.Remote.SSHOpts.SSHIdentity == hostInfo.SshKeyFile && msh.Remote.RemoteAlias == hostInfo.Host {
1726+
if msh.Remote.ConnectMode == hostInfo.ConnectMode && msh.Remote.SSHOpts.SSHIdentity == hostInfo.SshKeyFile && msh.Remote.RemoteAlias == hostInfo.Host && msh.Remote.ShellPref == hostInfo.ShellPref {
17201727
// silently skip this one. it didn't fail, but no changes were needed
17211728
continue
17221729
}
@@ -1753,6 +1760,7 @@ func RemoteConfigParseCommand(ctx context.Context, pk *scpacket.FeCommandPacketT
17531760
AutoInstall: true,
17541761
SSHOpts: sshOpts,
17551762
SSHConfigSrc: sstore.SSHConfigSrcTypeImport,
1763+
ShellPref: sstore.ShellTypePref_Detect,
17561764
}
17571765
err := remote.AddRemote(ctx, r, false)
17581766
if err != nil {

0 commit comments

Comments
 (0)