mirror of
https://github.com/Eugeny/tabby.git
synced 2025-10-04 14:04:56 +00:00
strict null checks
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "terminus-ssh",
|
||||
"version": "1.0.83-nightly.0",
|
||||
"version": "1.0.92-nightly.0",
|
||||
"description": "SSH connection manager for Terminus",
|
||||
"keywords": [
|
||||
"terminus-builtin-plugin"
|
||||
|
@@ -1,7 +1,7 @@
|
||||
import { BaseSession } from 'terminus-terminal'
|
||||
|
||||
export interface LoginScript {
|
||||
expect?: string
|
||||
expect: string
|
||||
send: string
|
||||
isRegex?: boolean
|
||||
optional?: boolean
|
||||
@@ -15,7 +15,7 @@ export enum SSHAlgorithmType {
|
||||
}
|
||||
|
||||
export interface SSHConnection {
|
||||
name?: string
|
||||
name: string
|
||||
host: string
|
||||
port: number
|
||||
user: string
|
||||
@@ -122,7 +122,7 @@ export class SSHSession extends BaseSession {
|
||||
this.kill('TERM')
|
||||
}
|
||||
|
||||
async getWorkingDirectory (): Promise<string> {
|
||||
async getWorkingDirectory (): Promise<string|null> {
|
||||
return null
|
||||
}
|
||||
|
||||
|
@@ -85,7 +85,7 @@ export class EditConnectionModalComponent {
|
||||
title: 'Select private key',
|
||||
}
|
||||
).then(result => {
|
||||
if (!result.filePaths) {
|
||||
if (result.filePaths) {
|
||||
this.connection.privateKey = result.filePaths[0]
|
||||
}
|
||||
})
|
||||
@@ -93,7 +93,7 @@ export class EditConnectionModalComponent {
|
||||
|
||||
save () {
|
||||
for (const k of Object.values(SSHAlgorithmType)) {
|
||||
this.connection.algorithms[k] = Object.entries(this.algorithms[k])
|
||||
this.connection.algorithms![k] = Object.entries(this.algorithms[k])
|
||||
.filter(([_k, v]) => !!v)
|
||||
.map(([k, _v]) => k)
|
||||
}
|
||||
@@ -105,6 +105,9 @@ export class EditConnectionModalComponent {
|
||||
}
|
||||
|
||||
moveScriptUp (script: LoginScript) {
|
||||
if (!this.connection.scripts) {
|
||||
this.connection.scripts = []
|
||||
}
|
||||
const index = this.connection.scripts.indexOf(script)
|
||||
if (index > 0) {
|
||||
this.connection.scripts.splice(index, 1)
|
||||
@@ -113,6 +116,9 @@ export class EditConnectionModalComponent {
|
||||
}
|
||||
|
||||
moveScriptDown (script: LoginScript) {
|
||||
if (!this.connection.scripts) {
|
||||
this.connection.scripts = []
|
||||
}
|
||||
const index = this.connection.scripts.indexOf(script)
|
||||
if (index >= 0 && index < this.connection.scripts.length - 1) {
|
||||
this.connection.scripts.splice(index, 1)
|
||||
@@ -121,7 +127,7 @@ export class EditConnectionModalComponent {
|
||||
}
|
||||
|
||||
async deleteScript (script: LoginScript) {
|
||||
if ((await this.electron.showMessageBox(
|
||||
if (this.connection.scripts && (await this.electron.showMessageBox(
|
||||
this.hostApp.getWindow(),
|
||||
{
|
||||
type: 'warning',
|
||||
@@ -136,6 +142,9 @@ export class EditConnectionModalComponent {
|
||||
}
|
||||
|
||||
addScript () {
|
||||
if (!this.connection.scripts) {
|
||||
this.connection.scripts = []
|
||||
}
|
||||
this.connection.scripts.push({ expect: '', send: '' })
|
||||
}
|
||||
}
|
||||
|
@@ -15,7 +15,7 @@ export class SSHModalComponent {
|
||||
connections: SSHConnection[]
|
||||
childFolders: SSHConnectionGroup[]
|
||||
quickTarget: string
|
||||
lastConnection: SSHConnection
|
||||
lastConnection: SSHConnection|null = null
|
||||
childGroups: SSHConnectionGroup[]
|
||||
groupCollapsed: {[id: string]: boolean} = {}
|
||||
|
||||
@@ -91,14 +91,14 @@ export class SSHModalComponent {
|
||||
}
|
||||
|
||||
for (const connection of connections) {
|
||||
connection.group = connection.group || null
|
||||
connection.group = connection.group || undefined
|
||||
let group = this.childGroups.find(x => x.name === connection.group)
|
||||
if (!group) {
|
||||
group = {
|
||||
name: connection.group,
|
||||
name: connection.group!,
|
||||
connections: [],
|
||||
}
|
||||
this.childGroups.push(group)
|
||||
this.childGroups.push(group!)
|
||||
}
|
||||
group.connections.push(connection)
|
||||
}
|
||||
|
@@ -97,7 +97,7 @@ export class SSHSettingsTabComponent {
|
||||
}
|
||||
)).response === 1) {
|
||||
for (const connection of this.connections.filter(x => x.group === group.name)) {
|
||||
connection.group = null
|
||||
connection.group = undefined
|
||||
}
|
||||
this.config.save()
|
||||
this.refresh()
|
||||
@@ -109,14 +109,14 @@ export class SSHSettingsTabComponent {
|
||||
this.childGroups = []
|
||||
|
||||
for (const connection of this.connections) {
|
||||
connection.group = connection.group || null
|
||||
connection.group = connection.group || undefined
|
||||
let group = this.childGroups.find(x => x.name === connection.group)
|
||||
if (!group) {
|
||||
group = {
|
||||
name: connection.group,
|
||||
name: connection.group!,
|
||||
connections: [],
|
||||
}
|
||||
this.childGroups.push(group)
|
||||
this.childGroups.push(group!)
|
||||
}
|
||||
group.connections.push(connection)
|
||||
}
|
||||
|
@@ -6,7 +6,7 @@ import { SSHTabComponent } from './components/sshTab.component'
|
||||
/** @hidden */
|
||||
@Injectable()
|
||||
export class RecoveryProvider extends TabRecoveryProvider {
|
||||
async recover (recoveryToken: any): Promise<RecoveredTab> {
|
||||
async recover (recoveryToken: any): Promise<RecoveredTab|null> {
|
||||
if (recoveryToken && recoveryToken.type === 'app:ssh-tab') {
|
||||
return {
|
||||
type: SSHTabComponent,
|
||||
|
@@ -12,7 +12,7 @@ export class PasswordStorageService {
|
||||
await keytar.deletePassword(`ssh@${connection.host}`, connection.user)
|
||||
}
|
||||
|
||||
async loadPassword (connection: SSHConnection): Promise<string> {
|
||||
async loadPassword (connection: SSHConnection): Promise<string|null> {
|
||||
return keytar.getPassword(`ssh@${connection.host}`, connection.user)
|
||||
}
|
||||
}
|
||||
|
@@ -38,9 +38,9 @@ export class SSHService {
|
||||
) as SSHTabComponent)
|
||||
}
|
||||
|
||||
async connectSession (session: SSHSession, logCallback?: (s: string) => void): Promise<void> {
|
||||
let privateKey: string = null
|
||||
let privateKeyPassphrase: string = null
|
||||
async connectSession (session: SSHSession, logCallback?: (s: any) => void): Promise<void> {
|
||||
let privateKey: string|null = null
|
||||
let privateKeyPassphrase: string|null = null
|
||||
let privateKeyPath = session.connection.privateKey
|
||||
|
||||
if (!logCallback) {
|
||||
@@ -48,12 +48,12 @@ export class SSHService {
|
||||
}
|
||||
|
||||
const log = (s: any) => {
|
||||
logCallback(s)
|
||||
logCallback!(s)
|
||||
this.logger.info(s)
|
||||
}
|
||||
|
||||
if (!privateKeyPath) {
|
||||
const userKeyPath = path.join(process.env.HOME, '.ssh', 'id_rsa')
|
||||
const userKeyPath = path.join(process.env.HOME as string, '.ssh', 'id_rsa')
|
||||
if (await fs.exists(userKeyPath)) {
|
||||
log(`Using user's default private key: ${userKeyPath}`)
|
||||
privateKeyPath = userKeyPath
|
||||
@@ -92,7 +92,7 @@ export class SSHService {
|
||||
|
||||
const ssh = new Client()
|
||||
let connected = false
|
||||
let savedPassword: string = null
|
||||
let savedPassword: string|null = null
|
||||
await new Promise(async (resolve, reject) => {
|
||||
ssh.on('ready', () => {
|
||||
connected = true
|
||||
@@ -116,7 +116,7 @@ export class SSHService {
|
||||
ssh.on('keyboard-interactive', (name, instructions, instructionsLang, prompts, finish) => this.zone.run(async () => {
|
||||
log(`Keyboard-interactive auth requested: ${name}`)
|
||||
this.logger.info('Keyboard-interactive auth:', name, instructions, instructionsLang)
|
||||
const results = []
|
||||
const results: string[] = []
|
||||
for (const prompt of prompts) {
|
||||
const modal = this.ngbModal.open(PromptModalComponent)
|
||||
modal.componentInstance.prompt = prompt.prompt
|
||||
@@ -135,7 +135,7 @@ export class SSHService {
|
||||
log('Banner: \n' + banner)
|
||||
})
|
||||
|
||||
let agent: string = null
|
||||
let agent: string|null = null
|
||||
if (this.hostApp.platform === Platform.Windows) {
|
||||
const pageantRunning = new Promise<boolean>(resolve => {
|
||||
windowsProcessTreeNative.getProcessList(list => { // eslint-disable-line block-scoped-var
|
||||
@@ -146,7 +146,7 @@ export class SSHService {
|
||||
agent = 'pageant'
|
||||
}
|
||||
} else {
|
||||
agent = process.env.SSH_AUTH_SOCK
|
||||
agent = process.env.SSH_AUTH_SOCK as string
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -155,10 +155,10 @@ export class SSHService {
|
||||
port: session.connection.port || 22,
|
||||
username: session.connection.user,
|
||||
password: session.connection.privateKey ? undefined : '',
|
||||
privateKey,
|
||||
passphrase: privateKeyPassphrase,
|
||||
privateKey: privateKey || undefined,
|
||||
passphrase: privateKeyPassphrase || undefined,
|
||||
tryKeyboard: true,
|
||||
agent,
|
||||
agent: agent || undefined,
|
||||
agentForward: !!agent,
|
||||
keepaliveInterval: session.connection.keepaliveInterval,
|
||||
keepaliveCountMax: session.connection.keepaliveCountMax,
|
||||
|
Reference in New Issue
Block a user