Exemple #1
0
        /// <inheritdoc/>
        public override DockerShimInfo Shim(DockerShim shim)
        {
            Program.LogPath = null;

            var commandLine = shim.CommandLine;

            // Handle the case where we need to pipe the standard input to
            // to the container.

            if (commandLine.Items.LastOrDefault() == "-")
            {
                shim.AddStdin();
            }
            else if (commandLine.StartsWithArgs("consul", "kv", "put") && commandLine.Arguments.Length == 5 && commandLine.Arguments[4].StartsWith("@"))
            {
                // We're going to special case PUT when saving a file
                // whose name is prefixed with "@".

                var fileArg  = commandLine.Arguments[4];
                var filePath = fileArg.Substring(1);
                var shimFile = shim.AddFile(filePath, dontReplace: true);

                shim.ReplaceItem(fileArg, "@" + shimFile);
            }

            return(new DockerShimInfo(shimability: DockerShimability.Optional, ensureConnection: true));
        }
Exemple #2
0
        /// <inheritdoc/>
        public override DockerShimInfo Shim(DockerShim shim)
        {
            Program.LogPath = null;

            var commandLine = shim.CommandLine;

            if (commandLine.Arguments.Length > 2)
            {
                switch (commandLine[1])
                {
                case "write":

                    // We need handle any [key=@file] arguments specially by adding
                    // them to the shim.

                    foreach (var arg in commandLine.Arguments.Skip(2))
                    {
                        var pos = arg.IndexOf("=@");

                        if (pos != -1)
                        {
                            var shimFile = shim.AddFile(arg.Substring(pos + 2), dontReplace: true);

                            shim.ReplaceItem(arg, arg.Substring(0, pos + 2) + shimFile);
                        }
                    }
                    break;

                case "policy-write":

                    // The last command line item is either:
                    //
                    //      * A "-", indicating that the content should come from standard input.
                    //      * A file name prefixed by "@"
                    //      * A string holding JSON or HCL

                    if (commandLine.Arguments.LastOrDefault() == "-")
                    {
                        shim.AddStdin();
                    }
                    else
                    {
                        var lastArg = commandLine.Arguments.LastOrDefault();

                        if (lastArg.StartsWith("@"))
                        {
                            var shimFile = shim.AddFile(lastArg.Substring(1), dontReplace: true);

                            shim.ReplaceItem(lastArg, "@" + shimFile);
                        }
                    }
                    break;
                }
            }

            return(new DockerShimInfo(shimability: DockerShimability.Optional, ensureConnection: true));
        }
Exemple #3
0
        /// <inheritdoc/>
        public override DockerShimInfo Shim(DockerShim shim)
        {
            var commandLine = shim.CommandLine;

            if (commandLine.Arguments.LastOrDefault() == "-")
            {
                shim.AddStdin(text: true);
            }
            else if (commandLine.Arguments.Length == 4)
            {
                switch (commandLine.Arguments[2])
                {
                case "add":
                case "settings":

                    shim.AddFile(commandLine.Arguments[3]);
                    break;
                }
            }

            return(new DockerShimInfo(shimability: DockerShimability.Optional, ensureConnection: true));
        }
Exemple #4
0
        /// <inheritdoc/>
        public override DockerShimInfo Shim(DockerShim shim)
        {
            Program.LogPath = null;

            // We're going to upload files for a handful of Docker commands unless this is disabled.

            var split            = shim.CommandLine.Split(SplitItem);
            var leftCommandLine  = split.Left;
            var rightCommandLine = split.Right;

            if (rightCommandLine == null)
            {
                rightCommandLine = new CommandLine();
            }

            if (leftCommandLine.HasOption("--no-upload"))
            {
                return(new DockerShimInfo(shimability: DockerShimability.Optional));
            }

            var arg1 = rightCommandLine.Arguments.ElementAtOrDefault(0);
            var arg2 = rightCommandLine.Arguments.ElementAtOrDefault(1);

            switch (arg1)
            {
            case "deploy":

                ShimDeploy(shim, rightCommandLine);
                break;

            case "stack":

                if (arg2 == "deploy")
                {
                    ShimDeploy(shim, rightCommandLine);
                }
                break;

            case "config":

                if (arg2 == "create")
                {
                    var path = rightCommandLine.Arguments.Skip(3).FirstOrDefault();

                    if (path == null)
                    {
                        return(new DockerShimInfo(shimability: DockerShimability.Optional, ensureConnection: true));      // This is an error but we'll let Docker report it.
                    }

                    if (path == "-")
                    {
                        shim.AddStdin();
                    }
                    else
                    {
                        shim.AddFile(path);
                    }
                }
                break;

            case "secret":

                if (arg2 == "create")
                {
                    var path = rightCommandLine.Arguments.Skip(3).FirstOrDefault();

                    if (path == null)
                    {
                        return(new DockerShimInfo(shimability: DockerShimability.Optional, ensureConnection: true));      // This is an error but we'll let Docker report it.
                    }

                    if (path == "-")
                    {
                        shim.AddStdin();
                    }
                    else
                    {
                        shim.AddFile(path);
                    }
                }
                break;
            }

            return(new DockerShimInfo(shimability: DockerShimability.Optional, ensureConnection: true));
        }