feat(core): add SSH data access proxy CLI and core managers
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
import { SshClient } from './classes.sshclient.js';
|
||||
import type { IProxyRequest } from './types.js';
|
||||
|
||||
export class PortProxy {
|
||||
constructor(private sshClient = new SshClient()) {}
|
||||
|
||||
public buildArgs(request: IProxyRequest): string[] {
|
||||
this.validateLocalForward(request.localForward);
|
||||
return this.sshClient.buildSshArgs(request.host, {
|
||||
localForwards: [request.localForward],
|
||||
extraArgs: ['-N'],
|
||||
exitOnForwardFailure: true,
|
||||
});
|
||||
}
|
||||
|
||||
public async start(request: IProxyRequest): Promise<number> {
|
||||
return this.sshClient.spawnInteractive('ssh', this.buildArgs(request));
|
||||
}
|
||||
|
||||
private validateLocalForward(localForward: string): void {
|
||||
const parts = localForward.split(':');
|
||||
if (parts.length < 3) {
|
||||
throw new Error('Local forward must look like <localPort>:<remoteHost>:<remotePort>');
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user