44 lines
1.3 KiB
TypeScript
44 lines
1.3 KiB
TypeScript
|
|
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);
|
||
|
|
}
|
||
|
|
}
|