コード例 #1
0
        /// <inheritdoc/>
        public override DockerShimInfo Shim(DockerShim shim)
        {
            var commandLine = shim.CommandLine;

            if (commandLine.Arguments.Length >= 3)
            {
                // We need to have the container command write the target file
                // to the [/shim] folder and then add a post action that copies
                // the target file to the specified location on the operator's
                // workstation.

                var externalTarget = commandLine.Arguments[2];
                var internalTarget = "__target";

                shim.ReplaceItem(externalTarget, internalTarget);

                shim.SetPostAction(
                    exitCode =>
                {
                    if (exitCode == 0)
                    {
                        File.Copy(Path.Combine(shim.ShimExternalFolder, internalTarget), externalTarget);
                    }
                });
            }

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

            // Shim command: neon vpn ca HIVE-DEF CA-FOLDER
            //
            // We need to copy the [HIVE-DEF] and the contents of the
            // [CA-FOLDER] into a shim subfolder, update the command line
            // and execute it, and then copy the file contents back out
            // to the original folder when the command completes.

            if (commandLine.Arguments.Length == 4 &&
                commandLine.Arguments[0] == "vpn" &&
                commandLine.Arguments[1] == "ca")
            {
                var hiveDefPath     = commandLine.Arguments[2];
                var caFolderPath    = commandLine.Arguments[3];
                var shimmedCaFolder = Path.Combine(shim.ShimExternalFolder, "ca");

                shim.AddFile(hiveDefPath);

                foreach (var file in Directory.GetFiles(caFolderPath, "*.*", SearchOption.TopDirectoryOnly))
                {
                    File.Copy(file, Path.Combine(shimmedCaFolder, Path.GetFileName(file)));
                }

                shim.ReplaceItem(caFolderPath, $"{DockerShim.ShimInternalFolder}/ca");

                shim.SetPostAction(
                    exitCode =>
                {
                    if (exitCode == 0)
                    {
                        foreach (var file in Directory.GetFiles(shimmedCaFolder, "*.*", SearchOption.TopDirectoryOnly))
                        {
                            File.Copy(file, Path.Combine(caFolderPath, Path.GetFileName(file)));
                        }
                    }
                });

                return(new DockerShimInfo(shimability: DockerShimability.Required));
            }

            // Shim command: neon vpn cert user create USER
            //
            // We need to copy the new hive login file to the current directory
            // after the command runs in Docker.  Note that the shimmed command
            // writes the file name for the new login to [new-login.txt].

            if (commandLine.Arguments.Length == 4 &&
                commandLine.Arguments[0] == "vpn" &&
                commandLine.Arguments[1] == "user" &&
                commandLine.Arguments[2] == "create")
            {
                var username = commandLine.Arguments[3];

                shim.SetPostAction(
                    exitCode =>
                {
                    if (exitCode == 0)
                    {
                        var loginName          = File.ReadAllText(Path.Combine(shim.ShimExternalFolder, "new-login.txt"));
                        var generatedLoginPath = Path.Combine(shim.ShimExternalFolder, loginName);
                        var outputLoginPath    = Path.GetFullPath(loginName);
                        var generatedLoginText = File.ReadAllText(generatedLoginPath);

                        File.WriteAllText(outputLoginPath, generatedLoginText);
                        Console.WriteLine($"*** Created login: {outputLoginPath}");
                    }
                });

                return(new DockerShimInfo(shimability: DockerShimability.Required));
            }

            // Shim command: neon vpn user revoke [--restart-vpn] THUMBPRINT
            //
            // No special actions required.

            return(new DockerShimInfo(shimability: DockerShimability.Required));
        }