All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hidetake.groovy.ssh.session.execution.Sudo.groovy Maven / Gradle / Ivy

There is a newer version: 2.11.2
Show newest version
package org.hidetake.groovy.ssh.session.execution

import org.hidetake.groovy.ssh.session.SessionExtension

/**
 * An extension class of sudo command execution.
 * Each method performs a sudo operation, explicitly providing password for the sudo user.
 * It blocks until channel is closed.
 *
 * @author Hidetake Iwata
 */
trait Sudo implements SessionExtension {

    String executeSudo(HashMap settings = [:], String commandLine) {
        assert commandLine, 'commandLine must be given'
        assert settings != null, 'settings must not be null'
        def helper = new SudoHelper(operations, mergedSettings, new SudoHelper.SudoCommandSettings(settings))
        helper.execute(commandLine)
    }

    String executeSudo(HashMap settings = [:], List commandLineArgs) {
        executeSudo(settings, Escape.escape(commandLineArgs))
    }

    void executeSudo(HashMap settings = [:], String commandLine, Closure callback) {
        assert commandLine, 'commandLine must be given'
        assert callback, 'callback must be given'
        assert settings != null, 'settings must not be null'
        callback.call(executeSudo(settings, commandLine))
    }

    void executeSudo(HashMap settings = [:], List commandLineArgs, Closure callback) {
        executeSudo(settings, Escape.escape(commandLineArgs), callback)
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy