DO-47/Tavro_pipeline (#1)

Add first classes
Co-authored-by: aleksandr.vodyanov <aleksandr.vodyanov@avroid.tech>
Co-committed-by: aleksandr.vodyanov <aleksandr.vodyanov@avroid.tech>
This commit is contained in:
aleksandr.vodyanov
2023-09-05 12:54:07 +00:00
committed by Aleksandr Vodyanov
parent af5323092c
commit ecc7728355
3 changed files with 149 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
package tech.avroid.ssh
/**
* Class for work with SSH client
*/
class Ssh implements Serializable {
private Script script
private String sshKey
private String fileSshKey
Ssh(Script script, String sshKey, String fileSshKey) {
this.script = script
this.fileSshKey = fileSshKey
this.sshKey = sshKey
}
/**
* Add file with private Ssh key and create ssh config with disable "StrictHostKeyChecking" for all hosts
* @param sshKey String - Variable with private SSH key
* @param fileSshKey String - name of file private SSH key's in catalog ~/.ssh
*/
public void configureSshClient() {
script.println 'Configure SSH-client with private key for current user'
script.sh """
[ -d ~/.ssh ] || mkdir ~/.ssh && chmod 0700 ~/.ssh
cat $sshKey > ~/.ssh/$fileSshKey
chmod 600 ~/.ssh/$fileSshKey
echo 'Host *' > ~/.ssh/config
echo ' StrictHostKeyChecking no' >> ~/.ssh/config
echo ' UserKnownHostsFile=/dev/null' >> ~/.ssh/config
"""
}
/**
* Remove file with private Ssh Key and ssh config
* @param fileSshKey String - name of file private SSH key's in catalog ~/.ssh
*/
public void cleanupSshConfiguration() {
script.println 'Unconfigure SSH-client with private key for current user'
script.sh """
rm -f ~/.ssh/$fileSshKey
rm -f ~/.ssh/config
"""
}
}