-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
File Explorer: Introduce sftp connection method (#139)
Currently behind the setting: `tailscale.nodeExplorer.connectionMethod` which defaults to `ssh` --------- Signed-off-by: Tyler Smalley <[email protected]> Co-authored-by: Marwan Sulaiman <[email protected]>
- Loading branch information
1 parent
535d928
commit 6eb7604
Showing
17 changed files
with
750 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import * as vscode from 'vscode'; | ||
import { Logger } from './logger'; | ||
import { ConfigManager } from './config-manager'; | ||
import { parseTsUri } from './utils/uri'; | ||
import { SshConnectionManager } from './ssh-connection-manager'; | ||
import { fileSorter } from './filesystem-provider'; | ||
|
||
export class FileSystemProviderSFTP implements vscode.FileSystemProvider { | ||
public manager: SshConnectionManager; | ||
|
||
constructor(configManager: ConfigManager) { | ||
this.manager = new SshConnectionManager(configManager); | ||
} | ||
|
||
// Implementation of the `onDidChangeFile` event | ||
onDidChangeFile: vscode.Event<vscode.FileChangeEvent[]> = new vscode.EventEmitter< | ||
vscode.FileChangeEvent[] | ||
>().event; | ||
|
||
watch(): vscode.Disposable { | ||
throw new Error('Watch not supported'); | ||
} | ||
|
||
async readDirectory(uri: vscode.Uri): Promise<[string, vscode.FileType][]> { | ||
Logger.info(`readDirectory: ${uri}`, `tsFs-sftp`); | ||
const { hostname, resourcePath } = parseTsUri(uri); | ||
|
||
const sftp = await this.manager.getSftp(hostname); | ||
if (!sftp) { | ||
throw new Error('Unable to establish SFTP connection'); | ||
} | ||
|
||
const files = await sftp.readDirectory(resourcePath); | ||
return files.sort(fileSorter); | ||
} | ||
|
||
async stat(uri: vscode.Uri): Promise<vscode.FileStat> { | ||
Logger.info(`stat: ${uri}`, 'tsFs-sftp'); | ||
const { hostname, resourcePath } = parseTsUri(uri); | ||
|
||
const sftp = await this.manager.getSftp(hostname); | ||
if (!sftp) { | ||
throw new Error('Unable to establish SFTP connection'); | ||
} | ||
|
||
return await sftp.stat(resourcePath); | ||
} | ||
|
||
async createDirectory(uri: vscode.Uri): Promise<void> { | ||
try { | ||
Logger.info(`createDirectory: ${uri}`, 'tsFs-sftp'); | ||
const { hostname, resourcePath } = parseTsUri(uri); | ||
|
||
const sftp = await this.manager.getSftp(hostname); | ||
if (!sftp) throw new Error('Failed to establish SFTP connection'); | ||
|
||
return await sftp.createDirectory(resourcePath); | ||
} catch (err) { | ||
Logger.error(`createDirectory: ${err}`, 'tsFs-sftp'); | ||
throw err; | ||
} | ||
} | ||
|
||
async getHomeDirectory(hostname: string): Promise<string> { | ||
const sftp = await this.manager.getSftp(hostname); | ||
if (!sftp) throw new Error('Failed to establish SFTP connection'); | ||
|
||
return await sftp.getHomeDirectory(); | ||
} | ||
|
||
async readFile(uri: vscode.Uri): Promise<Uint8Array> { | ||
Logger.info(`readFile: ${uri}`, 'tsFs-sftp'); | ||
const { hostname, resourcePath } = parseTsUri(uri); | ||
|
||
const sftp = await this.manager.getSftp(hostname); | ||
if (!sftp) { | ||
throw new Error('Unable to establish SFTP connection'); | ||
} | ||
|
||
return await sftp.readFile(resourcePath); | ||
} | ||
|
||
async writeFile(uri: vscode.Uri, content: Uint8Array): Promise<void> { | ||
Logger.info(`readFile: ${uri}`, 'tsFs-sftp'); | ||
const { hostname, resourcePath } = parseTsUri(uri); | ||
|
||
const sftp = await this.manager.getSftp(hostname); | ||
if (!sftp) { | ||
throw new Error('Unable to establish SFTP connection'); | ||
} | ||
|
||
return await sftp.writeFile(resourcePath, content); | ||
} | ||
|
||
async delete(uri: vscode.Uri): Promise<void> { | ||
Logger.info(`delete: ${uri}`, 'tsFs-sftp'); | ||
const { hostname, resourcePath } = parseTsUri(uri); | ||
|
||
const sftp = await this.manager.getSftp(hostname); | ||
if (!sftp) { | ||
throw new Error('Unable to establish SFTP connection'); | ||
} | ||
|
||
return await sftp.delete(resourcePath); | ||
} | ||
|
||
async rename(): Promise<void> {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.