/// <inheritdoc/> public override DockerShimInfo Shim(DockerShim shim) { // We need to copy any of the files referenced by [--script] // [--text] and/or [--data] options to the shim directory. var commandLine = shim.CommandLine; var optionPatterns = new string[] { "--script=", "--text=", "--data=" }; for (int i = 0; i < commandLine.Items.Length; i++) { var item = commandLine.Items[i]; foreach (var pattern in optionPatterns) { if (item.StartsWith(pattern)) { var shimPath = shim.AddFile(item.Substring(pattern.Length), dontReplace: true, noGuid: true); commandLine.Items[i] = $"{pattern}{shimPath}"; break; } } } return(new DockerShimInfo(shimability: DockerShimability.Optional, ensureConnection: true)); }
/// <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)); }
/// <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)); }
/// <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)); }
/// <summary> /// Handles the shim for the <b>docker deploy</b> and <b>docker stack deploy</b> commands. /// </summary> /// <param name="shim">The shim.</param> /// <param name="rightCommandLine">The right split of the command line.</param> private void ShimDeploy(DockerShim shim, CommandLine rightCommandLine) { string path; // We're going to shim the file specified by the first // [--bundle-file], [--compose-file], or [-c] option. for (int i = 0; i < rightCommandLine.Items.Length; i++) { switch (rightCommandLine.Items[i]) { case "--bundle-file": case "--compose-file": case "-c": path = rightCommandLine.Items.Skip(i + 1).FirstOrDefault(); if (path != null) { shim.AddFile(path); return; } break; } } // If that didn't work, try looking for arguments like: // // --bundle-file=PATH var patterns = new string[] { "--bundle-file=", "--compose-file=", "-c=" }; foreach (var item in rightCommandLine.Items) { foreach (var pattern in patterns) { if (item.StartsWith(pattern)) { path = item.Substring(pattern.Length); var shimFile = shim.AddFile(path, dontReplace: true); shim.ReplaceItem(pattern + path, pattern + shimFile); return; } } } }
/// <inheritdoc/> public override DockerShimInfo Shim(DockerShim shim) { var commandLine = shim.CommandLine; var command = commandLine.Arguments.ElementAtOrDefault(1); switch (command) { // These commands should be run on the operator workstation. case "join": case "split": return(new DockerShimInfo(shimability: DockerShimability.None)); // These commands can be run in Docker without modification. case "set": if (commandLine.Arguments.Length >= 4) { shim.AddFile(commandLine.Arguments[3]); } return(new DockerShimInfo(shimability: DockerShimability.Optional, ensureConnection: true)); case "verify": foreach (var path in commandLine.Arguments.Skip(2)) { shim.AddFile(path); } return(new DockerShimInfo(shimability: DockerShimability.Optional, ensureConnection: true)); case "remove": case "rm": case "get": case "ls": case "list": default: return(new DockerShimInfo(shimability: DockerShimability.Optional, ensureConnection: true)); } }
/// <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)); }
/// <inheritdoc/> public override DockerShimInfo Shim(DockerShim shim) { var ensureConnection = shim.CommandLine.Arguments.ElementAtOrDefault(1) != "help"; return(new DockerShimInfo(shimability: DockerShimability.None, ensureConnection: ensureConnection)); }
/// <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)); }
/// <inheritdoc/> public override DockerShimInfo Shim(DockerShim shim) { return(new DockerShimInfo(shimability: DockerShimability.None, ensureConnection: false)); }
/// <inheritdoc/> public override DockerShimInfo Shim(DockerShim shim) { return(new DockerShimInfo(shimability: DockerShimability.Optional, ensureConnection: true)); }
/// <inheritdoc/> public override DockerShimInfo Shim(DockerShim shim) { // This command cannot be executed within the [neon-cli] container. return(new DockerShimInfo(shimability: DockerShimability.None, ensureConnection: true)); }
public DockerShimInfo Shim(DockerShim shim) { Covenant.Requires <ArgumentNullException>(shim != null); return(null); }
/// <inheritdoc/> public override DockerShimInfo Shim(DockerShim shim) { shim.AddFile(shim.CommandLine.Arguments.LastOrDefault()); return(new DockerShimInfo(shimability: DockerShimability.Optional)); }
/// <inheritdoc/> public abstract DockerShimInfo Shim(DockerShim shim);
/// <inheritdoc/> public override DockerShimInfo Shim(DockerShim shim) { return(new DockerShimInfo(shimability: DockerShimability.None)); }
/// <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)); }