Ejemplo n.º 1
0
        /// <summary>
        /// Returns ProcessStartInfo for forwarding a local port to a remote gamelet using SSH.
        /// </summary>
        public static ProcessStartInfo BuildForSshPortForward(
            IEnumerable <PortForwardEntry> ports, SshTarget target)
        {
            var portsArgument = string.Join(" ",
                                            ports.Select(e => $"-L{e.LocalPort}:localhost:{e.RemotePort}"));

            return(new ProcessStartInfo()
            {
                FileName = Path.Combine(SDKUtil.GetSshPath(), YetiConstants.SshWinExecutable),
                Arguments = string.Format(
                    "-nNT -i \"{0}\" -F NUL " +
                    "-oStrictHostKeyChecking=yes -oUserKnownHostsFile=\"\"\"{1}\"\"\" " +
                    "{2} cloudcast@{3} -p {4}",
                    SDKUtil.GetSshKeyFilePath(), SDKUtil.GetSshKnownHostsFilePath(), portsArgument,
                    target.IpAddress, target.Port),
            });
        }
Ejemplo n.º 2
0
        // Attempts to read the SDK version file from the SDK path and extracts the version.
        // If the read or parsing failed, logs an error and returns the empty string.
        public static string GetFullSdkVersionString()
        {
            var sdkVersionFilePath = Path.Combine(SDKUtil.GetSDKPath(), "VERSION");

            try
            {
                return(File.ReadLines(sdkVersionFilePath).First());
            }
            catch (Exception e) when(
                e is IOException ||
                e is UnauthorizedAccessException)
            {
                Trace.WriteLine($"Failed to read or parse VERSION file '{sdkVersionFilePath}'." +
                                $"{Environment.NewLine}{e}");
            }
            return("");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Returns ProcessStartInfo for running a command on a remote gamelet using SSH.
        /// </summary>
        public static ProcessStartInfo BuildForSsh(
            string command, IEnumerable <string> environment, SshTarget target)
        {
            string envArgs = environment.Aggregate("", (acc, entry) => acc + entry + " ");

            return(new ProcessStartInfo()
            {
                FileName = Path.Combine(
                    SDKUtil.GetSshPath(), YetiConstants.SshWinExecutable),
                // (internal): Without -tt, GGP processes leak if ssh.exe is killed.
                Arguments = string.Format(
                    "-tt -i \"{0}\" -F NUL " +
                    "-oStrictHostKeyChecking=yes -oUserKnownHostsFile=\"\"\"{1}\"\"\" " +
                    "cloudcast@{2} -p {3} -- \"{4}{5}\"",
                    SDKUtil.GetSshKeyFilePath(), SDKUtil.GetSshKnownHostsFilePath(),
                    target.IpAddress, target.Port, envArgs, command),
            });
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Returns ProcessStartInfo for transferring a file from a remote gamelet using scp.
 /// </summary>
 public static ProcessStartInfo BuildForScpGet(
     string file, SshTarget target, string destination)
 {
     return(new ProcessStartInfo
     {
         FileName = Path.Combine(SDKUtil.GetSshPath(), YetiConstants.ScpWinExecutable),
         // Note that remote file names must be escaped twice, once for local command
         // parsing and once for remote shell parsing. Linux file systems also allow double
         // quotes in file names, so those params must be escaped, where as the Windows
         // paths can simply be quoted.
         Arguments = string.Format(
             "-T -i \"{0}\" -F NUL -P {1} " +
             "-oStrictHostKeyChecking=yes -oUserKnownHostsFile=\"\"\"{2}\"\"\" " +
             "cloudcast@{3}:{4} {5}",
             SDKUtil.GetSshKeyFilePath(), target.Port, SDKUtil.GetSshKnownHostsFilePath(),
             target.IpAddress, ProcessUtil.QuoteArgument($"'{file}'"),
             ProcessUtil.QuoteArgument(destination)),
     });
 }
Ejemplo n.º 5
0
 public virtual CredentialConfig LoadOrDefault()
 {
     return(new CredentialConfig(
                jsonUtil, Path.Combine(SDKUtil.GetCredentialsPath(), "config.json")));
 }
Ejemplo n.º 6
0
 public virtual SdkConfig LoadOrDefault() =>
 _jsonUtil.LoadOrDefault <SdkConfig>(
     Path.Combine(SDKUtil.GetUserConfigPath(), SdkConfigFilename));