feat(core): add SSH data access proxy CLI and core managers
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import { SshConfig } from './classes.sshconfig.js';
|
||||
import { SshConfigWriter } from './classes.sshconfigwriter.js';
|
||||
import type {
|
||||
IHostDefinition,
|
||||
IHostUpdatePreview,
|
||||
IHostWriteResult,
|
||||
ISshConfigHost,
|
||||
ISshConfigOptions,
|
||||
} from './types.js';
|
||||
|
||||
export class HostManager {
|
||||
private sshConfig: SshConfig;
|
||||
private sshConfigWriter: SshConfigWriter;
|
||||
|
||||
constructor(options: ISshConfigOptions = {}) {
|
||||
this.sshConfig = new SshConfig(options);
|
||||
this.sshConfigWriter = new SshConfigWriter(options);
|
||||
}
|
||||
|
||||
public async listHosts(): Promise<ISshConfigHost[]> {
|
||||
const result = await this.sshConfig.read();
|
||||
return this.sshConfig.getDisplayHosts(result);
|
||||
}
|
||||
|
||||
public async getHost(alias: string): Promise<ISshConfigHost | undefined> {
|
||||
return this.sshConfig.getHost(alias);
|
||||
}
|
||||
|
||||
public async addHost(hostDefinition: IHostDefinition): Promise<IHostWriteResult> {
|
||||
return this.sshConfigWriter.addOrReplaceManagedHost(hostDefinition);
|
||||
}
|
||||
|
||||
public async previewEditHost(
|
||||
alias: string,
|
||||
changes: Partial<IHostDefinition>
|
||||
): Promise<IHostUpdatePreview> {
|
||||
return this.sshConfigWriter.previewUpdateHost(alias, changes);
|
||||
}
|
||||
|
||||
public async editHost(alias: string, changes: Partial<IHostDefinition>): Promise<IHostWriteResult> {
|
||||
return this.sshConfigWriter.updateHost(alias, changes);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user