public TestableProcessCommand(IContainer container, IProcessIO io, IRemoteCommandArgs args, string workingDirectory, string exePath, params string[] exeArgs)
            {
                this.Container   = container;
                this.IO          = io;
                this.CommandArgs = args;

                this.workingDirectory = workingDirectory;
                this.exePath          = exePath;
                this.exeArguments     = exeArgs;
            }
Beispiel #2
0
        public static RemoteCommand Create(IContainer container, IProcessIO io, string commandType, IRemoteCommandArgs args)
        {
            RemoteCommand command = null;

            switch (commandType.ToLowerInvariant())
            {
            case "mkdir":
                command = new MkDirCommand();
                break;

            case "touch":
                command = new TouchCommand();
                break;

            case "exe":
                command = new ExeCommand();
                break;

            case "ps1":
                command = new PowerShellCommand();
                break;

            case "unzip":
                command = new UnzipCommand();
                break;

            case "tar":
                command = new TarCommand();
                break;

            case "replace-tokens":
                command = new ReplaceTokensCommand();
                break;

            default:
                throw new NotImplementedException(string.Format("Command type {0} is unknown.", commandType));
            }

            command.Container   = container;
            command.IO          = io;
            command.CommandArgs = args;

            return(command);
        }
Beispiel #3
0
        public IContainerProcess Run(ProcessSpec spec, IProcessIO io)
        {
            lock (_ioLock)
            {
                ThrowIfNotActive();

                var runner = spec.Privileged
                    ? processRunner
                    : constrainedProcessRunner;

                var executablePath = !spec.DisablePathMapping
                    ? directory.MapUserPath(spec.ExecutablePath)
                    : spec.ExecutablePath;

                var specEnvironment    = spec.Environment ?? new Dictionary <string, string>();
                var processEnvironment = this.defaultEnvironment.Merge(specEnvironment);

                Action <string> stdOut = io == null || io.StandardOutput == null
                    ? (Action <string>)null
                    : data => io.StandardOutput.Write(data);

                Action <string> stdErr = io == null || io.StandardError == null
                    ? (Action <string>)null
                    : data => io.StandardError.Write(data);

                var runSpec = new ProcessRunSpec
                {
                    ExecutablePath   = executablePath,
                    Arguments        = spec.Arguments,
                    Environment      = processEnvironment,
                    WorkingDirectory = directory.MapUserPath(spec.WorkingDirectory ?? DefaultWorkingDirectory),
                    OutputCallback   = stdOut,
                    ErrorCallback    = stdErr,
                };

                var process = runner.Run(runSpec);

                return(new ContainerProcess(process));
            }
        }
Beispiel #4
0
        public IContainerProcess Run(ProcessSpec spec, IProcessIO io)
        {
            lock (_ioLock)
            {
                ThrowIfNotActive();

                var runner = spec.Privileged
                    ? processRunner
                    : constrainedProcessRunner;

                var executablePath = !spec.DisablePathMapping
                    ? directory.MapUserPath(spec.ExecutablePath)
                    : spec.ExecutablePath;

                var specEnvironment = spec.Environment ?? new Dictionary<string, string>();
                var processEnvironment = this.defaultEnvironment.Merge(specEnvironment);

                Action<string> stdOut = io == null || io.StandardOutput == null
                    ? (Action<string>) null
                    : data => io.StandardOutput.Write(data);

                Action<string> stdErr = io == null || io.StandardError == null
                    ? (Action<string>) null
                    : data => io.StandardError.Write(data);

                var runSpec = new ProcessRunSpec
                {
                    ExecutablePath = executablePath,
                    Arguments = spec.Arguments,
                    Environment = processEnvironment,
                    WorkingDirectory = directory.MapUserPath(spec.WorkingDirectory ?? DefaultWorkingDirectory),
                    OutputCallback = stdOut,
                    ErrorCallback = stdErr,
                };

                var process = runner.Run(runSpec);

                return new ContainerProcess(process);
            }
        }