mirror of
https://github.com/Eugeny/tabby.git
synced 2025-03-31 15:50:28 +08:00
fixed #5712 - SSH import from a separate config file
This commit is contained in:
parent
c408154137
commit
b3a07e5f99
@ -17,7 +17,7 @@ import { ElectronService } from './services/electron.service'
|
||||
import { ElectronHotkeyProvider } from './hotkeys'
|
||||
import { ElectronConfigProvider } from './config'
|
||||
import { EditSFTPContextMenu } from './sftpContextMenu'
|
||||
import { OpenSSHImporter } from './openSSHImport'
|
||||
import { OpenSSHImporter, StaticFileImporter } from './sshImporters'
|
||||
|
||||
@NgModule({
|
||||
providers: [
|
||||
@ -32,7 +32,8 @@ import { OpenSSHImporter } from './openSSHImport'
|
||||
{ provide: ConfigProvider, useClass: ElectronConfigProvider, multi: true },
|
||||
{ provide: FileProvider, useClass: ElectronFileProvider, multi: true },
|
||||
{ provide: SFTPContextMenuItemProvider, useClass: EditSFTPContextMenu, multi: true },
|
||||
{ provide: SSHProfileImporter, useClass: OpenSSHImporter, multi: true },
|
||||
{ provide: SSHProfileImporter, useExisting: OpenSSHImporter, multi: true },
|
||||
{ provide: SSHProfileImporter, useExisting: StaticFileImporter, multi: true },
|
||||
],
|
||||
})
|
||||
export default class ElectronModule {
|
||||
|
@ -1,15 +1,20 @@
|
||||
import * as fs from 'fs/promises'
|
||||
import * as fsSync from 'fs'
|
||||
import * as path from 'path'
|
||||
import slugify from 'slugify'
|
||||
import * as yaml from 'js-yaml'
|
||||
import { Injectable } from '@angular/core'
|
||||
import { PartialProfile } from 'tabby-core'
|
||||
import { SSHProfileImporter, PortForwardType, SSHProfile, SSHProfileOptions } from 'tabby-ssh'
|
||||
|
||||
function deriveID (name: string): string {
|
||||
return 'openssh-config:' + slugify(name)
|
||||
}
|
||||
import { ElectronService } from './services/electron.service'
|
||||
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class OpenSSHImporter extends SSHProfileImporter {
|
||||
async getProfiles (): Promise<PartialProfile<SSHProfile>[]> {
|
||||
const deriveID = name => 'openssh-config:' + slugify(name)
|
||||
|
||||
const results: PartialProfile<SSHProfile>[] = []
|
||||
const configPath = path.join(process.env.HOME ?? '~', '.ssh', 'config')
|
||||
try {
|
||||
@ -127,3 +132,34 @@ export class OpenSSHImporter extends SSHProfileImporter {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class StaticFileImporter extends SSHProfileImporter {
|
||||
private configPath: string
|
||||
|
||||
constructor (
|
||||
electron: ElectronService,
|
||||
) {
|
||||
super()
|
||||
this.configPath = path.join(electron.app.getPath('userData'), 'ssh-profiles.yaml')
|
||||
}
|
||||
|
||||
async getProfiles (): Promise<PartialProfile<SSHProfile>[]> {
|
||||
const deriveID = name => 'file-config:' + slugify(name)
|
||||
|
||||
if (!fsSync.existsSync(this.configPath)) {
|
||||
return []
|
||||
}
|
||||
|
||||
const content = await fs.readFile(this.configPath, 'utf8')
|
||||
if (!content) {
|
||||
return []
|
||||
}
|
||||
|
||||
return (yaml.load(content) as PartialProfile<SSHProfile>[]).map(item => ({
|
||||
...item,
|
||||
id: deriveID(item.name),
|
||||
type: 'ssh',
|
||||
}))
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user