package com.mirantis.mk

/**
 *
 * SSH functions
 *
 */

/**
 * Ensure entry in SSH known hosts
 *
 * @param url   url of remote host
 */
def ensureKnownHosts(url) {
    def hostArray = getKnownHost(url)
    sh "test -f ~/.ssh/known_hosts && grep ${hostArray[0]} ~/.ssh/known_hosts || ssh-keyscan -p ${hostArray[1]} ${hostArray[0]} >> ~/.ssh/known_hosts"
}

@NonCPS
def getKnownHost(url){
     // test for git@github.com:organization/repository like URLs
    def p = ~/.+@(.+\..+)\:{1}.*/
    def result = p.matcher(url)
    def host = ""
    if (result.matches()) {
        host = result.group(1)
        port = 22
    } else {
        // test for protocol
        if(url.indexOf("://") == -1){
            url="ssh://" + url
        }
        parsed = new URI(url)
        host = parsed.host
        port = parsed.port && parsed.port > 0 ? parsed.port: 22
    }
    return [host,port]
}

/**
 * Execute command with ssh-agent
 *
 * @param cmd   Command to execute
 */
def runSshAgentCommand(cmd) {
    // if file exists, then we started ssh-agent
    if (fileExists("$HOME/.ssh/ssh-agent.sh")) {
        sh(". ~/.ssh/ssh-agent.sh && ${cmd}")
    } else {
    // we didn't start ssh-agent in prepareSshAgentKey() because some ssh-agent
    // is running. Let's re-use already running agent and re-construct
    //   * SSH_AUTH_SOCK
    //   * SSH_AGENT_PID
        sh """
        export SSH_AUTH_SOCK=`find /tmp/ -type s -name agent.\\* 2> /dev/null |  grep '/tmp/ssh-.*/agent.*' | head -n 1`
        export SSH_AGENT_PID=`echo \${SSH_AUTH_SOCK} | cut -d. -f2`
        ${cmd}
        """
    }
}

/**
 * Execute command with ssh-agent (shortcut for runSshAgentCommand)
 *
 * @param cmd   Command to execute
 */
def agentSh(cmd) {
    runSshAgentCommand(cmd)
}

/**
 * Setup ssh agent and add private key
 *
 * @param credentialsId Jenkins credentials name to lookup private key
 */
def prepareSshAgentKey(credentialsId) {
    def common = new com.mirantis.mk.Common()
    c = common.getSshCredentials(credentialsId)
    // create ~/.ssh and delete file ssh-agent.sh which can be stale
    sh('mkdir -p -m 700 ~/.ssh && rm -f ~/.ssh/ssh-agent.sh')
    sh('pgrep -l -u $USER -f ssh-agent\$ >/dev/null || ssh-agent|grep -v "Agent pid" > ~/.ssh/ssh-agent.sh')
    sh("set +x; echo '${c.getPrivateKey()}' > ~/.ssh/id_rsa_${credentialsId} && chmod 600 ~/.ssh/id_rsa_${credentialsId}; set -x")
    runSshAgentCommand("ssh-add ~/.ssh/id_rsa_${credentialsId}")
}

return this;
