Search in sources :

Example 1 with GroovySandboxComponent

use of net.robinfriedli.aiode.boot.configurations.GroovySandboxComponent in project aiode by robinfriedli.

the class ScriptCommand method executeScript.

private void executeScript(Aiode aiode, CommandContext context, Session session) {
    GroovySandboxComponent groovySandboxComponent = aiode.getGroovySandboxComponent();
    GroovyVariableManager groovyVariableManager = aiode.getGroovyVariableManager();
    SafeGroovyScriptRunner groovyScriptRunner = new SafeGroovyScriptRunner(context, groovySandboxComponent, groovyVariableManager, aiode.getSecurityManager(), argumentSet("privileged"));
    StoredScript script;
    if (this.script != null) {
        script = this.script;
    } else {
        String identifier = getArgumentValue("invoke");
        Optional<StoredScript> storedScript = SearchEngine.searchScript(identifier, "script", session);
        if (storedScript.isPresent()) {
            script = storedScript.get();
        } else {
            throw new InvalidCommandException(String.format("No such script '%s'", identifier));
        }
    }
    if (!script.isActive()) {
        throw new InvalidCommandException(String.format("Script '%s' has been deactivated. Use the active argument to reactivate the script.", script.getIdentifier()));
    }
    groovyScriptRunner.runAndSendResult(script.getScript(), 10, TimeUnit.SECONDS);
}
Also used : SafeGroovyScriptRunner(net.robinfriedli.aiode.scripting.SafeGroovyScriptRunner) InvalidCommandException(net.robinfriedli.aiode.exceptions.InvalidCommandException) StoredScript(net.robinfriedli.aiode.entities.StoredScript) GroovyVariableManager(net.robinfriedli.aiode.scripting.GroovyVariableManager) GroovySandboxComponent(net.robinfriedli.aiode.boot.configurations.GroovySandboxComponent)

Example 2 with GroovySandboxComponent

use of net.robinfriedli.aiode.boot.configurations.GroovySandboxComponent in project aiode by robinfriedli.

the class EvalCommand method doRun.

@Override
public void doRun() {
    CommandContext context = getContext();
    Aiode aiode = Aiode.get();
    SecurityManager securityManager = aiode.getSecurityManager();
    GroovySandboxComponent groovySandboxComponent = aiode.getGroovySandboxComponent();
    GroovyVariableManager groovyVariableManager = aiode.getGroovyVariableManager();
    SafeGroovyScriptRunner groovyScriptRunner = new SafeGroovyScriptRunner(context, groovySandboxComponent, groovyVariableManager, securityManager, argumentSet("privileged"));
    groovyScriptRunner.runAndSendResult(getCommandInput(), 10, TimeUnit.SECONDS);
}
Also used : CommandContext(net.robinfriedli.aiode.command.CommandContext) SecurityManager(net.robinfriedli.aiode.command.SecurityManager) SafeGroovyScriptRunner(net.robinfriedli.aiode.scripting.SafeGroovyScriptRunner) Aiode(net.robinfriedli.aiode.Aiode) GroovyVariableManager(net.robinfriedli.aiode.scripting.GroovyVariableManager) GroovySandboxComponent(net.robinfriedli.aiode.boot.configurations.GroovySandboxComponent)

Aggregations

GroovySandboxComponent (net.robinfriedli.aiode.boot.configurations.GroovySandboxComponent)2 GroovyVariableManager (net.robinfriedli.aiode.scripting.GroovyVariableManager)2 SafeGroovyScriptRunner (net.robinfriedli.aiode.scripting.SafeGroovyScriptRunner)2 Aiode (net.robinfriedli.aiode.Aiode)1 CommandContext (net.robinfriedli.aiode.command.CommandContext)1 SecurityManager (net.robinfriedli.aiode.command.SecurityManager)1 StoredScript (net.robinfriedli.aiode.entities.StoredScript)1 InvalidCommandException (net.robinfriedli.aiode.exceptions.InvalidCommandException)1