Пример #1
1
        private ProcessToRun ProcessBuilder(DTOScript scriptToRun)
        {
            ProcessToRun processToRun = new ProcessToRun();

            switch (scriptToRun.script.Split(".", StringSplitOptions.RemoveEmptyEntries).Last())
            {
            case "ps1":
                string path       = _config.GetValue <string>("ScriptLocations:Powershell");
                var    scriptPath = Path.Combine(path, scriptToRun.script);
                processToRun.processName    = "powershell";
                processToRun.scriptWithArgs = $"{scriptPath} {scriptToRun.param}";
                break;

            case "py":
                string pathPY       = _config.GetValue <string>("ScriptLocations:Python");
                var    scriptPathPY = Path.Combine(pathPY, scriptToRun.script);
                processToRun.processName    = "python";
                processToRun.scriptWithArgs = $"{scriptPathPY} {scriptToRun.param}";
                break;

            default:
                throw new InvalidDataException($"Unsupported file type: {scriptToRun.script}");
            }
            return(processToRun);
        }
Пример #2
1
        public IActionResult StartPsScript([FromQuery] DTOScript scriptFromQuery)
        {
            string key = _config.GetValue <string>("key");

            if (!string.Equals(key, scriptFromQuery.key))
            {
                return(Unauthorized(new DTOResult {
                    isCompletedSuccessfully = false,
                    message = "Invalid key. Please provide a valid key to make a webhook."
                }));
            }

            string stdout = _scriptRunner.Run(scriptFromQuery);

            return(Ok(new DTOResult {
                isCompletedSuccessfully = true,
                scriptName = scriptFromQuery.script,
                param = scriptFromQuery.param,
                output = stdout
            }));
        }
Пример #3
0
        public string Run(DTOScript scriptToRun)
        {
            ProcessToRun processToRun = ProcessBuilder(scriptToRun);
            string       stdout       = ExecuteScript(processToRun);

            return(stdout);
        }