To use this function add it to the class library file named PluginSSHService.ts
GitHub Repository: https://github.com/SimonSparksUK/Orchestrator
Filename: PluginSSHService.ts
Description: Orchestrator Function to register a Public Key on an SSH Host
Public Function: registerPublicKey
publicregisterPublicKey(strSSHHostFQDN:string,strUsername:string,strPassword:string):void{
try{
letobjSSHSession:SSHSession=newSSHSession(strSSHHostFQDN,strUsername);
objSSHSession.connectWithPassword(strPassword);
letintErrorCode:number=objSSHSession.putFile("/usr/lib/vco/app-server/conf/vco_key.pub","/tmp");
if (intErrorCode!=0){
objSSHSession.disconnect();
this.objLogger.info(`Registration of Automation Orchestrator server public key on '${strSSHHostFQDN}' for user '${strUsername}' failed (file transfer):${objSSHSession.error}`);
}
letstrCommandLine:string=`cd ; mkdir -p .ssh ; cat /tmp/vco_key.pub >> ~/.ssh/authorized_keys ; rm -f /tmp/vco_key.pub`;
objSSHSession.executeCommand(strCommandLine,true);
objSSHSession.disconnect();
if (objSSHSession.error){
this.objLogger.info(`Registration of Automation Orchestrator server public key on '${strSSHHostFQDN}' for user '${strUsername}' failed (command):${objSSHSession.error}`);
}else{
this.objLogger.info(`Registration of Automation Orchestrator server public key completed on '${strSSHHostFQDN}' for user '${strUsername}'`);
}
}catch (objException){
this.objLogger.info(`Registration of Automation Orchestrator server public key on '${strSSHHostFQDN}' for user '${strUsername}' failed.${objException}`);
}
}Discover more from Cloud Build Tools
Subscribe to get the latest posts sent to your email.
