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(String commandLine) {
        assert commandLine, 'commandLine must be given'
        def helper = new SudoHelper(operations, mergedSettings, new SudoHelper.SudoCommandSettings())
        helper.execute(commandLine)
    }

    String executeSudo(List commandLineArgs) {
        executeSudo(Escape.escape(commandLineArgs))
    }

    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(String commandLine, Closure callback) {
        assert commandLine, 'commandLine must be given'
        assert callback, 'callback must be given'
        callback.call(executeSudo(commandLine))
    }

    void executeSudo(List commandLineArgs, Closure callback) {
        executeSudo(Escape.escape(commandLineArgs), callback)
    }

    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 - 2025 Weber Informatics LLC | Privacy Policy