Shellpref for sshconfig import (#270)

This commit is contained in:
Sylvie Crowe 2024-01-31 14:11:12 -08:00 committed by GitHub
parent 5ce7b92232
commit 51ee7bef61
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 48 additions and 29 deletions

View File

@ -20,6 +20,12 @@
width: 100%; width: 100%;
} }
.import-edit-warning {
display: flex;
flex-direction: row;
align-items: flex-start;
}
.name-actions-section { .name-actions-section {
margin-bottom: 10px; margin-bottom: 10px;
display: flex; display: flex;

View File

@ -58,6 +58,10 @@ class EditRemoteConnModal extends React.Component<{}, {}> {
return this.selectedRemote?.local; return this.selectedRemote?.local;
} }
isImportedRemote(): boolean {
return this.selectedRemote?.sshconfigsrc == "sshconfig-import";
}
componentDidMount(): void { componentDidMount(): void {
mobx.action(() => { mobx.action(() => {
this.tempAlias.set(this.selectedRemote?.remotealias); this.tempAlias.set(this.selectedRemote?.remotealias);
@ -259,6 +263,27 @@ class EditRemoteConnModal extends React.Component<{}, {}> {
); );
} }
renderImportedRemoteEditWarning() {
return (
<div className="import-edit-warning">
<Tooltip
message={
<span>
Most options for connections imported from an ssh config file cannot be edited. For these
changes, you must edit the config file and import it again. The shell preference can be
edited, but will return to the default if you import again. It will stay changed if you
follow <a href="https://docs.waveterm.dev/features/sshconfig-imports">this procedure</a>.
</span>
}
icon={<i className="fa-sharp fa-regular fa-fw fa-triangle-exclamation" />}
>
<i className="fa-sharp fa-regular fa-fw fa-triangle-exclamation" />
</Tooltip>
&nbsp;SSH Config Import Behavior
</div>
);
}
renderAuthMode() { renderAuthMode() {
let authMode = this.tempAuthMode.get(); let authMode = this.tempAuthMode.get();
return ( return (
@ -344,6 +369,7 @@ class EditRemoteConnModal extends React.Component<{}, {}> {
return null; return null;
} }
let isLocal = this.isLocalRemote(); let isLocal = this.isLocalRemote();
let isImported = this.isImportedRemote();
return ( return (
<Modal className="erconn-modal"> <Modal className="erconn-modal">
<Modal.Header title="Edit Connection" onClose={this.model.closeModal} /> <Modal.Header title="Edit Connection" onClose={this.model.closeModal} />
@ -351,9 +377,10 @@ class EditRemoteConnModal extends React.Component<{}, {}> {
<div className="name-actions-section"> <div className="name-actions-section">
<div className="name text-primary">{util.getRemoteName(this.selectedRemote)}</div> <div className="name text-primary">{util.getRemoteName(this.selectedRemote)}</div>
</div> </div>
<If condition={!isLocal}>{this.renderAlias()}</If> <If condition={!isLocal && !isImported}>{this.renderAlias()}</If>
<If condition={!isLocal}>{this.renderAuthMode()}</If> <If condition={!isLocal && !isImported}>{this.renderAuthMode()}</If>
<If condition={!isLocal}>{this.renderConnectMode()}</If> <If condition={!isLocal && !isImported}>{this.renderConnectMode()}</If>
<If condition={isImported}>{this.renderImportedRemoteEditWarning()}</If>
{this.renderShellPref()} {this.renderShellPref()}
<If condition={!util.isBlank(this.remoteEdit?.errorstr)}> <If condition={!util.isBlank(this.remoteEdit?.errorstr)}>
<div className="settings-field settings-error">Error: {this.remoteEdit?.errorstr}</div> <div className="settings-field settings-error">Error: {this.remoteEdit?.errorstr}</div>

View File

@ -1026,17 +1026,6 @@ class ViewRemoteConnDetailModal extends React.Component<{}, {}> {
cancelInstallButton = <></>; cancelInstallButton = <></>;
} }
if (remote.sshconfigsrc == "sshconfig-import") { if (remote.sshconfigsrc == "sshconfig-import") {
updateAuthButton = (
<Button theme="secondary" disabled={true}>
Edit
<Tooltip
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.`}
icon={<i className="fa-sharp fa-regular fa-fw fa-ban" />}
>
<i className="fa-sharp fa-regular fa-fw fa-ban" />
</Tooltip>
</Button>
);
archiveButton = ( archiveButton = (
<Button theme="secondary" onClick={() => this.clickArchive()}> <Button theme="secondary" onClick={() => this.clickArchive()}>
Delete Delete

View File

@ -209,17 +209,6 @@ class ViewRemoteConnDetailModal extends React.Component<{}, {}> {
cancelInstallButton = <></>; cancelInstallButton = <></>;
} }
if (remote.sshconfigsrc == "sshconfig-import") { if (remote.sshconfigsrc == "sshconfig-import") {
updateAuthButton = (
<Button theme="secondary" disabled={true}>
Edit
<Tooltip
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.`}
icon={<i className="fa-sharp fa-regular fa-fw fa-ban" />}
>
<i className="fa-sharp fa-regular fa-fw fa-ban" />
</Tooltip>
</Button>
);
archiveButton = ( archiveButton = (
<Button theme="secondary" onClick={() => this.clickArchive()}> <Button theme="secondary" onClick={() => this.clickArchive()}>
Delete Delete

View File

@ -1420,9 +1420,6 @@ func RemoteSetCommand(ctx context.Context, pk *scpacket.FeCommandPacketType) (ss
if err != nil { if err != nil {
return nil, err return nil, err
} }
if ids.Remote.RState.SSHConfigSrc == sstore.SSHConfigSrcTypeImport {
return nil, fmt.Errorf("/remote:new cannot update imported remote")
}
visualEdit := resolveBool(pk.Kwargs["visual"], false) visualEdit := resolveBool(pk.Kwargs["visual"], false)
isSubmitted := resolveBool(pk.Kwargs["submit"], false) isSubmitted := resolveBool(pk.Kwargs["submit"], false)
editArgs, err := parseRemoteEditArgs(false, pk, ids.Remote.MShell.IsLocal()) editArgs, err := parseRemoteEditArgs(false, pk, ids.Remote.MShell.IsLocal())
@ -1542,6 +1539,7 @@ type HostInfoType struct {
SshKeyFile string SshKeyFile string
ConnectMode string ConnectMode string
Ignore bool Ignore bool
ShellPref string
} }
func createSshImportSummary(changeList map[string][]string) string { func createSshImportSummary(changeList map[string][]string) string {
@ -1637,6 +1635,13 @@ func NewHostInfo(hostName string) (*HostInfoType, error) {
connectMode = sstore.ConnectModeManual connectMode = sstore.ConnectModeManual
} }
shellPref := sstore.ShellTypePref_Detect
if cfgWaveOptions["shellpref"] == "bash" {
shellPref = "bash"
} else if cfgWaveOptions["shellpref"] == "zsh" {
shellPref = "zsh"
}
outHostInfo := new(HostInfoType) outHostInfo := new(HostInfoType)
outHostInfo.Host = hostName outHostInfo.Host = hostName
outHostInfo.User = userName outHostInfo.User = userName
@ -1645,6 +1650,7 @@ func NewHostInfo(hostName string) (*HostInfoType, error) {
outHostInfo.SshKeyFile = sshKeyFile outHostInfo.SshKeyFile = sshKeyFile
outHostInfo.ConnectMode = connectMode outHostInfo.ConnectMode = connectMode
outHostInfo.Ignore = shouldIgnore outHostInfo.Ignore = shouldIgnore
outHostInfo.ShellPref = shellPref
return outHostInfo, nil return outHostInfo, nil
} }
@ -1709,6 +1715,7 @@ func RemoteConfigParseCommand(ctx context.Context, pk *scpacket.FeCommandPacketT
if hostInfo.SshKeyFile != "" { if hostInfo.SshKeyFile != "" {
editMap[sstore.RemoteField_SSHKey] = hostInfo.SshKeyFile editMap[sstore.RemoteField_SSHKey] = hostInfo.SshKeyFile
} }
editMap[sstore.RemoteField_ShellPref] = hostInfo.ShellPref
msh := remote.GetRemoteById(previouslyImportedRemote.RemoteId) msh := remote.GetRemoteById(previouslyImportedRemote.RemoteId)
if msh == nil { if msh == nil {
remoteChangeList["updateErr"] = append(remoteChangeList["updateErr"], hostInfo.CanonicalName) remoteChangeList["updateErr"] = append(remoteChangeList["updateErr"], hostInfo.CanonicalName)
@ -1716,7 +1723,7 @@ func RemoteConfigParseCommand(ctx context.Context, pk *scpacket.FeCommandPacketT
continue continue
} }
if msh.Remote.ConnectMode == hostInfo.ConnectMode && msh.Remote.SSHOpts.SSHIdentity == hostInfo.SshKeyFile && msh.Remote.RemoteAlias == hostInfo.Host { if msh.Remote.ConnectMode == hostInfo.ConnectMode && msh.Remote.SSHOpts.SSHIdentity == hostInfo.SshKeyFile && msh.Remote.RemoteAlias == hostInfo.Host && msh.Remote.ShellPref == hostInfo.ShellPref {
// silently skip this one. it didn't fail, but no changes were needed // silently skip this one. it didn't fail, but no changes were needed
continue continue
} }
@ -1753,6 +1760,7 @@ func RemoteConfigParseCommand(ctx context.Context, pk *scpacket.FeCommandPacketT
AutoInstall: true, AutoInstall: true,
SSHOpts: sshOpts, SSHOpts: sshOpts,
SSHConfigSrc: sstore.SSHConfigSrcTypeImport, SSHConfigSrc: sstore.SSHConfigSrcTypeImport,
ShellPref: sstore.ShellTypePref_Detect,
} }
err := remote.AddRemote(ctx, r, false) err := remote.AddRemote(ctx, r, false)
if err != nil { if err != nil {