mirror of
https://github.com/nestriness/cdc-file-transfer.git
synced 2026-01-30 14:35:37 +02:00
Remove GGP dependencies from CDC RSync (#1)
* Remove dependencies of cdc_sync from GGP Allows overriding the SSH and SCP commands via command line flags. Hence, strict host checking, SSH config etc. can be removed since it is passed in by command line flags for GGP. Also deploys cdc_rsync_server to ~/.cache/cdc_file_transfer/ and creates that dir if it does not exist. * Tweak RemoteUtil Replaces localhost: by //./ in the workaround for scp since localhost: had two disadvantages: 1) It required 2 gnubby touches for gLinux and 2) it didn't work for ggp. //./ works for both. Also tweaks quoting, which didn't quite work for ggp. * Don't check remote ports in cdc_rsync Turns off checking remote ports in PortManager. In the future, the server should return available ports after failing to connect to the provided port. Since now the first remote connection is running cdc_rsync_server, the timeout check has to be done when running that process. * Remove now-unused kInstancePickerNotAvailableInQuietMode enum * Add more details to the readme * [cdc_rsync] Accept [user@]host:destination Removes the --ip command line argument and assumes user/host are passed in along with the destination, so it works in the same way as other popular tools. * [ggp_rsync] Combine server deploy commands Combines two chmod and one mv command into one ssh command. This makes deploy a bit quicker, especially if each ssh command involves touching your gnubby. * Remove GGP specific stuff from VS build commands * [cdc_rsync] Get rid of cdc_rsync.dll Compile the CDC RSync client as a static library instead. This removes quite a bit of boiler plate and makes string handling easier since we can now pass std::strings instead of const chars. Also fixes an issue where we were sometimes trying to assign nullptr to std::strings, which is forbidden. * Allow specifying ssh/scp commands with env vars * Rename GgpRsync* to CdcRsync* * Merge ggp_rsync_cli into ggp_rsync * [cdc_rsync] Refactor cdc_rsync.cc/h Merges cdc_rsync.cc/h with main.cc and CdcRsyncClient since code is closer to where it's being used and should be more readable.
This commit is contained in:
@@ -51,10 +51,14 @@ class PortManager {
|
||||
// Reserves a port in the range passed to the constructor. The port is
|
||||
// released automatically upon destruction if ReleasePort() is not called
|
||||
// explicitly.
|
||||
// |timeout_sec| is the timeout for finding available ports on the gamelet
|
||||
// instance. Returns a DeadlineExceeded error if the timeout is exceeded.
|
||||
// |check_remote| determines whether the remote port should be checked as
|
||||
// well. If false, the check is skipped and a port might be returned that is
|
||||
// still in use remotely.
|
||||
// |remote_timeout_sec| is the timeout for finding available ports on the
|
||||
// remote instance. Not used if |check_remote| is false.
|
||||
// Returns a DeadlineExceeded error if the timeout is exceeded.
|
||||
// Returns a ResourceExhausted error if no ports are available.
|
||||
absl::StatusOr<int> ReservePort(int timeout_sec);
|
||||
absl::StatusOr<int> ReservePort(bool check_remote, int remote_timeout_sec);
|
||||
|
||||
// Releases a reserved port.
|
||||
absl::Status ReleasePort(int port);
|
||||
|
||||
@@ -25,8 +25,8 @@
|
||||
namespace cdc_ft {
|
||||
namespace {
|
||||
|
||||
constexpr int kGameletPort = 12345;
|
||||
constexpr char kGameletIp[] = "1.2.3.4";
|
||||
constexpr int kSshPort = 12345;
|
||||
constexpr char kUserHost[] = "user@1.2.3.4";
|
||||
|
||||
constexpr char kGuid[] = "f77bcdfe-368c-4c45-9f01-230c5e7e2132";
|
||||
constexpr int kFirstPort = 44450;
|
||||
@@ -38,6 +38,9 @@ constexpr int kTimeoutSec = 1;
|
||||
constexpr char kLocalNetstat[] = "netstat -a -n -p tcp";
|
||||
constexpr char kRemoteNetstat[] = "netstat --numeric --listening --tcp";
|
||||
|
||||
constexpr bool kCheckRemote = true;
|
||||
constexpr bool kNoCheckRemote = false;
|
||||
|
||||
constexpr char kLocalNetstatOutFmt[] =
|
||||
"TCP 127.0.0.1:50000 127.0.0.1:%i ESTABLISHED";
|
||||
constexpr char kRemoteNetstatOutFmt[] =
|
||||
@@ -53,7 +56,7 @@ class PortManagerTest : public ::testing::Test {
|
||||
|
||||
void SetUp() override {
|
||||
Log::Initialize(std::make_unique<ConsoleLog>(LogLevel::kInfo));
|
||||
remote_util_.SetIpAndPort(kGameletIp, kGameletPort);
|
||||
remote_util_.SetUserHostAndPort(kUserHost, kSshPort);
|
||||
}
|
||||
|
||||
void TearDown() override { Log::Shutdown(); }
|
||||
@@ -70,7 +73,16 @@ TEST_F(PortManagerTest, ReservePortSuccess) {
|
||||
process_factory_.SetProcessOutput(kLocalNetstat, "", "", 0);
|
||||
process_factory_.SetProcessOutput(kRemoteNetstat, "", "", 0);
|
||||
|
||||
absl::StatusOr<int> port = port_manager_.ReservePort(kTimeoutSec);
|
||||
absl::StatusOr<int> port =
|
||||
port_manager_.ReservePort(kCheckRemote, kTimeoutSec);
|
||||
ASSERT_OK(port);
|
||||
EXPECT_EQ(*port, kFirstPort);
|
||||
}
|
||||
|
||||
TEST_F(PortManagerTest, ReservePortNoRemoteSuccess) {
|
||||
process_factory_.SetProcessOutput(kLocalNetstat, "", "", 0);
|
||||
|
||||
absl::StatusOr<int> port = port_manager_.ReservePort(kNoCheckRemote, 0);
|
||||
ASSERT_OK(port);
|
||||
EXPECT_EQ(*port, kFirstPort);
|
||||
}
|
||||
@@ -83,7 +95,8 @@ TEST_F(PortManagerTest, ReservePortAllLocalPortsTaken) {
|
||||
process_factory_.SetProcessOutput(kLocalNetstat, local_netstat_out, "", 0);
|
||||
process_factory_.SetProcessOutput(kRemoteNetstat, "", "", 0);
|
||||
|
||||
absl::StatusOr<int> port = port_manager_.ReservePort(kTimeoutSec);
|
||||
absl::StatusOr<int> port =
|
||||
port_manager_.ReservePort(kCheckRemote, kTimeoutSec);
|
||||
EXPECT_TRUE(absl::IsResourceExhausted(port.status()));
|
||||
EXPECT_TRUE(
|
||||
absl::StrContains(port.status().message(), "No port available in range"));
|
||||
@@ -97,7 +110,8 @@ TEST_F(PortManagerTest, ReservePortAllRemotePortsTaken) {
|
||||
process_factory_.SetProcessOutput(kLocalNetstat, "", "", 0);
|
||||
process_factory_.SetProcessOutput(kRemoteNetstat, remote_netstat_out, "", 0);
|
||||
|
||||
absl::StatusOr<int> port = port_manager_.ReservePort(kTimeoutSec);
|
||||
absl::StatusOr<int> port =
|
||||
port_manager_.ReservePort(kCheckRemote, kTimeoutSec);
|
||||
EXPECT_TRUE(absl::IsResourceExhausted(port.status()));
|
||||
EXPECT_TRUE(
|
||||
absl::StrContains(port.status().message(), "No port available in range"));
|
||||
@@ -107,7 +121,8 @@ TEST_F(PortManagerTest, ReservePortLocalNetstatFails) {
|
||||
process_factory_.SetProcessOutput(kLocalNetstat, "", "", 1);
|
||||
process_factory_.SetProcessOutput(kRemoteNetstat, "", "", 0);
|
||||
|
||||
absl::StatusOr<int> port = port_manager_.ReservePort(kTimeoutSec);
|
||||
absl::StatusOr<int> port =
|
||||
port_manager_.ReservePort(kCheckRemote, kTimeoutSec);
|
||||
EXPECT_NOT_OK(port);
|
||||
EXPECT_TRUE(
|
||||
absl::StrContains(port.status().message(),
|
||||
@@ -118,7 +133,8 @@ TEST_F(PortManagerTest, ReservePortRemoteNetstatFails) {
|
||||
process_factory_.SetProcessOutput(kLocalNetstat, "", "", 0);
|
||||
process_factory_.SetProcessOutput(kRemoteNetstat, "", "", 1);
|
||||
|
||||
absl::StatusOr<int> port = port_manager_.ReservePort(kTimeoutSec);
|
||||
absl::StatusOr<int> port =
|
||||
port_manager_.ReservePort(kCheckRemote, kTimeoutSec);
|
||||
EXPECT_NOT_OK(port);
|
||||
EXPECT_TRUE(absl::StrContains(port.status().message(),
|
||||
"Failed to find available ports on instance"));
|
||||
@@ -129,7 +145,8 @@ TEST_F(PortManagerTest, ReservePortRemoteNetstatTimesOut) {
|
||||
process_factory_.SetProcessNeverExits(kRemoteNetstat);
|
||||
steady_clock_.AutoAdvance(kTimeoutSec * 2 * 1000);
|
||||
|
||||
absl::StatusOr<int> port = port_manager_.ReservePort(kTimeoutSec);
|
||||
absl::StatusOr<int> port =
|
||||
port_manager_.ReservePort(kCheckRemote, kTimeoutSec);
|
||||
EXPECT_NOT_OK(port);
|
||||
EXPECT_TRUE(absl::IsDeadlineExceeded(port.status()));
|
||||
EXPECT_TRUE(absl::StrContains(port.status().message(),
|
||||
@@ -146,10 +163,14 @@ TEST_F(PortManagerTest, ReservePortMultipleInstances) {
|
||||
// Port managers use shared memory, so different instances know about each
|
||||
// other. This would even work if |port_manager_| and |port_manager2| belonged
|
||||
// to different processes, but we don't test that here.
|
||||
EXPECT_EQ(*port_manager_.ReservePort(kTimeoutSec), kFirstPort + 0);
|
||||
EXPECT_EQ(*port_manager2.ReservePort(kTimeoutSec), kFirstPort + 1);
|
||||
EXPECT_EQ(*port_manager_.ReservePort(kTimeoutSec), kFirstPort + 2);
|
||||
EXPECT_EQ(*port_manager2.ReservePort(kTimeoutSec), kFirstPort + 3);
|
||||
EXPECT_EQ(*port_manager_.ReservePort(kCheckRemote, kTimeoutSec),
|
||||
kFirstPort + 0);
|
||||
EXPECT_EQ(*port_manager2.ReservePort(kCheckRemote, kTimeoutSec),
|
||||
kFirstPort + 1);
|
||||
EXPECT_EQ(*port_manager_.ReservePort(kCheckRemote, kTimeoutSec),
|
||||
kFirstPort + 2);
|
||||
EXPECT_EQ(*port_manager2.ReservePort(kCheckRemote, kTimeoutSec),
|
||||
kFirstPort + 3);
|
||||
}
|
||||
|
||||
TEST_F(PortManagerTest, ReservePortReusesPortsInLRUOrder) {
|
||||
@@ -157,7 +178,7 @@ TEST_F(PortManagerTest, ReservePortReusesPortsInLRUOrder) {
|
||||
process_factory_.SetProcessOutput(kRemoteNetstat, "", "", 0);
|
||||
|
||||
for (int n = 0; n < kNumPorts * 2; ++n) {
|
||||
EXPECT_EQ(*port_manager_.ReservePort(kTimeoutSec),
|
||||
EXPECT_EQ(*port_manager_.ReservePort(kCheckRemote, kTimeoutSec),
|
||||
kFirstPort + n % kNumPorts);
|
||||
system_clock_.Advance(1000);
|
||||
}
|
||||
@@ -167,10 +188,11 @@ TEST_F(PortManagerTest, ReleasePort) {
|
||||
process_factory_.SetProcessOutput(kLocalNetstat, "", "", 0);
|
||||
process_factory_.SetProcessOutput(kRemoteNetstat, "", "", 0);
|
||||
|
||||
absl::StatusOr<int> port = port_manager_.ReservePort(kTimeoutSec);
|
||||
absl::StatusOr<int> port =
|
||||
port_manager_.ReservePort(kCheckRemote, kTimeoutSec);
|
||||
EXPECT_EQ(*port, kFirstPort);
|
||||
EXPECT_OK(port_manager_.ReleasePort(*port));
|
||||
port = port_manager_.ReservePort(kTimeoutSec);
|
||||
port = port_manager_.ReservePort(kCheckRemote, kTimeoutSec);
|
||||
EXPECT_EQ(*port, kFirstPort);
|
||||
}
|
||||
|
||||
@@ -180,10 +202,13 @@ TEST_F(PortManagerTest, ReleasePortOnDestruction) {
|
||||
|
||||
auto port_manager2 = std::make_unique<PortManager>(
|
||||
kGuid, kFirstPort, kLastPort, &process_factory_, &remote_util_);
|
||||
EXPECT_EQ(*port_manager2->ReservePort(kTimeoutSec), kFirstPort + 0);
|
||||
EXPECT_EQ(*port_manager_.ReservePort(kTimeoutSec), kFirstPort + 1);
|
||||
EXPECT_EQ(*port_manager2->ReservePort(kCheckRemote, kTimeoutSec),
|
||||
kFirstPort + 0);
|
||||
EXPECT_EQ(*port_manager_.ReservePort(kCheckRemote, kTimeoutSec),
|
||||
kFirstPort + 1);
|
||||
port_manager2.reset();
|
||||
EXPECT_EQ(*port_manager_.ReservePort(kTimeoutSec), kFirstPort + 0);
|
||||
EXPECT_EQ(*port_manager_.ReservePort(kCheckRemote, kTimeoutSec),
|
||||
kFirstPort + 0);
|
||||
}
|
||||
|
||||
TEST_F(PortManagerTest, FindAvailableLocalPortsSuccess) {
|
||||
|
||||
@@ -121,7 +121,8 @@ PortManager::~PortManager() {
|
||||
}
|
||||
}
|
||||
|
||||
absl::StatusOr<int> PortManager::ReservePort(int timeout_sec) {
|
||||
absl::StatusOr<int> PortManager::ReservePort(bool check_remote,
|
||||
int remote_timeout_sec) {
|
||||
// Find available port on workstation.
|
||||
std::unordered_set<int> local_ports;
|
||||
ASSIGN_OR_RETURN(local_ports,
|
||||
@@ -129,13 +130,16 @@ absl::StatusOr<int> PortManager::ReservePort(int timeout_sec) {
|
||||
process_factory_, false),
|
||||
"Failed to find available ports on workstation");
|
||||
|
||||
// Find available port on remote gamelet.
|
||||
std::unordered_set<int> remote_ports;
|
||||
ASSIGN_OR_RETURN(remote_ports,
|
||||
FindAvailableRemotePorts(first_port_, last_port_, "0.0.0.0",
|
||||
process_factory_, remote_util_,
|
||||
timeout_sec, false, steady_clock_),
|
||||
"Failed to find available ports on instance");
|
||||
// Find available port on remote instance.
|
||||
std::unordered_set<int> remote_ports = local_ports;
|
||||
if (check_remote) {
|
||||
ASSIGN_OR_RETURN(
|
||||
remote_ports,
|
||||
FindAvailableRemotePorts(first_port_, last_port_, "0.0.0.0",
|
||||
process_factory_, remote_util_,
|
||||
remote_timeout_sec, false, steady_clock_),
|
||||
"Failed to find available ports on instance");
|
||||
}
|
||||
|
||||
// Fetch shared memory.
|
||||
void* mem;
|
||||
|
||||
@@ -58,8 +58,8 @@ absl::Status CreatePipeForOverlappedIo(ScopedHandle* pipe_read_end,
|
||||
ScopedHandle* pipe_write_end) {
|
||||
// We need named pipes for overlapped IO, so create a unique name.
|
||||
int id = g_pipe_serial_number++;
|
||||
std::string pipe_name = absl::StrFormat(
|
||||
R"(\\.\Pipe\GgpRsyncIoPipe.%08x.%08x)", GetCurrentProcessId(), id);
|
||||
std::string pipe_name = absl::StrFormat(R"(\\.\Pipe\CdcIoPipe.%08x.%08x)",
|
||||
GetCurrentProcessId(), id);
|
||||
|
||||
// Set the bInheritHandle flag so pipe handles are inherited.
|
||||
SECURITY_ATTRIBUTES security_attributes;
|
||||
|
||||
@@ -14,10 +14,9 @@
|
||||
|
||||
#include "common/remote_util.h"
|
||||
|
||||
#include <atomic>
|
||||
#include <regex>
|
||||
#include <sstream>
|
||||
|
||||
#include "absl/strings/str_cat.h"
|
||||
#include "absl/strings/str_format.h"
|
||||
#include "common/path.h"
|
||||
#include "common/status.h"
|
||||
@@ -25,32 +24,6 @@
|
||||
namespace cdc_ft {
|
||||
namespace {
|
||||
|
||||
// Escapes command line argument for the Microsoft command line parser in
|
||||
// preparation for quoting. Double quotes are backslash-escaped. Literal
|
||||
// backslashes are backslash-escaped if they are followed by a double quote, or
|
||||
// if they are part of a sequence of backslashes that are followed by a double
|
||||
// quote.
|
||||
std::string EscapeForWindows(const std::string& argument) {
|
||||
std::string str =
|
||||
std::regex_replace(argument, std::regex(R"(\\*(?=""|$))"), "$1$1");
|
||||
return std::regex_replace(str, std::regex("\""), "\\\"");
|
||||
}
|
||||
|
||||
// Quotes and escapes a command line argument following the convention
|
||||
// understood by the Microsoft command line parser.
|
||||
std::string QuoteArgument(const std::string& argument) {
|
||||
return absl::StrFormat("\"%s\"", EscapeForWindows(argument));
|
||||
}
|
||||
|
||||
// Quotes and escapes a command line arguments for use in ssh command. The
|
||||
// argument is first escaped and quoted for Linux using single quotes and then
|
||||
// it is escaped to be used by the Microsoft command line parser.
|
||||
std::string QuoteAndEscapeArgumentForSsh(const std::string& argument) {
|
||||
std::string quoted_argument = absl::StrFormat(
|
||||
"'%s'", std::regex_replace(argument, std::regex("'"), "'\\''"));
|
||||
return EscapeForWindows(quoted_argument);
|
||||
}
|
||||
|
||||
// Gets the argument for SSH (reverse) port forwarding, e.g. -L23:localhost:45.
|
||||
std::string GetPortForwardingArg(int local_port, int remote_port,
|
||||
bool reverse) {
|
||||
@@ -69,21 +42,29 @@ RemoteUtil::RemoteUtil(int verbosity, bool quiet,
|
||||
process_factory_(process_factory),
|
||||
forward_output_to_log_(forward_output_to_log) {}
|
||||
|
||||
void RemoteUtil::SetIpAndPort(const std::string& gamelet_ip, int ssh_port) {
|
||||
gamelet_ip_ = gamelet_ip;
|
||||
ssh_port_ = ssh_port;
|
||||
void RemoteUtil::SetUserHostAndPort(std::string user_host, int port) {
|
||||
user_host_ = std::move(user_host);
|
||||
ssh_port_ = port;
|
||||
}
|
||||
void RemoteUtil::SetScpCommand(std::string scp_command) {
|
||||
scp_command_ = std::move(scp_command);
|
||||
}
|
||||
|
||||
void RemoteUtil::SetSshCommand(std::string ssh_command) {
|
||||
ssh_command_ = std::move(ssh_command);
|
||||
}
|
||||
|
||||
absl::Status RemoteUtil::Scp(std::vector<std::string> source_filepaths,
|
||||
const std::string& dest, bool compress) {
|
||||
absl::Status status = CheckIpPort();
|
||||
absl::Status status = CheckHostPort();
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
|
||||
std::string source_args;
|
||||
for (const std::string& sourceFilePath : source_filepaths) {
|
||||
source_args += QuoteArgument(sourceFilePath) + " ";
|
||||
// Workaround for scp thinking that C is a host in C:\path\to\foo.
|
||||
source_args += QuoteArgument("//./" + sourceFilePath) + " ";
|
||||
}
|
||||
|
||||
// -p preserves timestamps. This enables timestamp-based up-to-date checks.
|
||||
@@ -91,18 +72,10 @@ absl::Status RemoteUtil::Scp(std::vector<std::string> source_filepaths,
|
||||
start_info.command = absl::StrFormat(
|
||||
"%s "
|
||||
"%s %s -p -T "
|
||||
"-F %s "
|
||||
"-i %s -P %i "
|
||||
"-oStrictHostKeyChecking=yes "
|
||||
"-oUserKnownHostsFile=\"\"\"%s\"\"\" %s "
|
||||
"cloudcast@%s:"
|
||||
"-P %i %s "
|
||||
"%s",
|
||||
QuoteArgument(sdk_util_.GetScpExePath()),
|
||||
quiet_ || verbosity_ < 2 ? "-q" : "", compress ? "-C" : "",
|
||||
QuoteArgument(sdk_util_.GetSshConfigPath()),
|
||||
QuoteArgument(sdk_util_.GetSshKeyFilePath()), ssh_port_,
|
||||
sdk_util_.GetSshKnownHostsFilePath(), source_args,
|
||||
QuoteArgument(gamelet_ip_), QuoteAndEscapeArgumentForSsh(dest));
|
||||
scp_command_, quiet_ || verbosity_ < 2 ? "-q" : "", compress ? "-C" : "",
|
||||
ssh_port_, source_args, QuoteArgument(user_host_ + ":" + dest));
|
||||
start_info.name = "scp";
|
||||
start_info.forward_output_to_log = forward_output_to_log_;
|
||||
|
||||
@@ -111,7 +84,7 @@ absl::Status RemoteUtil::Scp(std::vector<std::string> source_filepaths,
|
||||
|
||||
absl::Status RemoteUtil::Sync(std::vector<std::string> source_filepaths,
|
||||
const std::string& dest) {
|
||||
absl::Status status = CheckIpPort();
|
||||
absl::Status status = CheckHostPort();
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
@@ -123,9 +96,9 @@ absl::Status RemoteUtil::Sync(std::vector<std::string> source_filepaths,
|
||||
|
||||
ProcessStartInfo start_info;
|
||||
start_info.command = absl::StrFormat(
|
||||
"%s --ip=%s --port=%i -z %s %s%s",
|
||||
path::Join(sdk_util_.GetDevBinPath(), "cdc_rsync"),
|
||||
QuoteArgument(gamelet_ip_), ssh_port_,
|
||||
"cdc_rsync --ip=%s --port=%i -z "
|
||||
"%s %s%s",
|
||||
QuoteArgument(user_host_), ssh_port_,
|
||||
quiet_ || verbosity_ < 2 ? "-q " : " ", source_args, QuoteArgument(dest));
|
||||
start_info.name = "cdc_rsync";
|
||||
start_info.forward_output_to_log = forward_output_to_log_;
|
||||
@@ -135,16 +108,16 @@ absl::Status RemoteUtil::Sync(std::vector<std::string> source_filepaths,
|
||||
|
||||
absl::Status RemoteUtil::Chmod(const std::string& mode,
|
||||
const std::string& remote_path, bool quiet) {
|
||||
std::string remote_command = absl::StrFormat(
|
||||
"chmod %s %s %s", QuoteArgument(mode),
|
||||
QuoteAndEscapeArgumentForSsh(remote_path), quiet ? "-f" : "");
|
||||
std::string remote_command =
|
||||
absl::StrFormat("chmod %s %s %s", QuoteArgument(mode),
|
||||
EscapeForWindows(remote_path), quiet ? "-f" : "");
|
||||
|
||||
return Run(remote_command, "chmod");
|
||||
}
|
||||
|
||||
absl::Status RemoteUtil::Rm(const std::string& remote_path, bool force) {
|
||||
std::string remote_command = absl::StrFormat(
|
||||
"rm %s %s", force ? "-f" : "", QuoteAndEscapeArgumentForSsh(remote_path));
|
||||
std::string remote_command = absl::StrFormat("rm %s %s", force ? "-f" : "",
|
||||
EscapeForWindows(remote_path));
|
||||
|
||||
return Run(remote_command, "rm");
|
||||
}
|
||||
@@ -152,14 +125,14 @@ absl::Status RemoteUtil::Rm(const std::string& remote_path, bool force) {
|
||||
absl::Status RemoteUtil::Mv(const std::string& old_remote_path,
|
||||
const std::string& new_remote_path) {
|
||||
std::string remote_command =
|
||||
absl::StrFormat("mv %s %s", QuoteAndEscapeArgumentForSsh(old_remote_path),
|
||||
QuoteAndEscapeArgumentForSsh(new_remote_path));
|
||||
absl::StrFormat("mv %s %s", EscapeForWindows(old_remote_path),
|
||||
EscapeForWindows(new_remote_path));
|
||||
|
||||
return Run(remote_command, "mv");
|
||||
}
|
||||
|
||||
absl::Status RemoteUtil::Run(std::string remote_command, std::string name) {
|
||||
absl::Status status = CheckIpPort();
|
||||
absl::Status status = CheckHostPort();
|
||||
if (!status.ok()) {
|
||||
return status;
|
||||
}
|
||||
@@ -201,25 +174,37 @@ ProcessStartInfo RemoteUtil::BuildProcessStartInfoForSshInternal(
|
||||
start_info.command = absl::StrFormat(
|
||||
"%s "
|
||||
"%s -tt "
|
||||
"-F %s "
|
||||
"-i %s "
|
||||
"-oServerAliveCountMax=6 " // Number of lost msgs before ssh terminates
|
||||
"-oServerAliveInterval=5 " // Time interval between alive msgs
|
||||
"-oStrictHostKeyChecking=yes "
|
||||
"-oUserKnownHostsFile=\"\"\"%s\"\"\" %s"
|
||||
"cloudcast@%s -p %i %s",
|
||||
QuoteArgument(sdk_util_.GetSshExePath()),
|
||||
quiet_ || verbosity_ < 2 ? "-q" : "",
|
||||
QuoteArgument(sdk_util_.GetSshConfigPath()),
|
||||
QuoteArgument(sdk_util_.GetSshKeyFilePath()),
|
||||
sdk_util_.GetSshKnownHostsFilePath(), forward_arg,
|
||||
QuoteArgument(gamelet_ip_), ssh_port_, remote_command_arg);
|
||||
"%s %s -p %i %s",
|
||||
ssh_command_, quiet_ || verbosity_ < 2 ? "-q" : "", forward_arg,
|
||||
QuoteArgument(user_host_), ssh_port_, remote_command_arg);
|
||||
start_info.forward_output_to_log = forward_output_to_log_;
|
||||
return start_info;
|
||||
}
|
||||
|
||||
absl::Status RemoteUtil::CheckIpPort() {
|
||||
if (gamelet_ip_.empty() || ssh_port_ == 0) {
|
||||
std::string RemoteUtil::EscapeForWindows(const std::string& argument) {
|
||||
std::string str =
|
||||
std::regex_replace(argument, std::regex(R"(\\*(?="|$))"), "$&$&");
|
||||
return std::regex_replace(str, std::regex(R"(")"), R"(\")");
|
||||
}
|
||||
|
||||
std::string RemoteUtil::QuoteArgument(const std::string& argument) {
|
||||
return absl::StrCat("\"", EscapeForWindows(argument), "\"");
|
||||
}
|
||||
|
||||
std::string RemoteUtil::QuoteArgumentForSsh(const std::string& argument) {
|
||||
return absl::StrFormat(
|
||||
"'%s'", std::regex_replace(argument, std::regex("'"), "'\\''"));
|
||||
}
|
||||
|
||||
std::string RemoteUtil::QuoteAndEscapeArgumentForSsh(
|
||||
const std::string& argument) {
|
||||
return EscapeForWindows(QuoteArgumentForSsh(argument));
|
||||
}
|
||||
|
||||
absl::Status RemoteUtil::CheckHostPort() {
|
||||
if (user_host_.empty() || ssh_port_ == 0) {
|
||||
return MakeStatus("IP or port not set");
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
|
||||
#include "absl/status/status.h"
|
||||
#include "common/process.h"
|
||||
#include "common/sdk_util.h"
|
||||
|
||||
namespace cdc_ft {
|
||||
|
||||
@@ -30,6 +29,8 @@ namespace cdc_ft {
|
||||
// Windows-only.
|
||||
class RemoteUtil {
|
||||
public:
|
||||
static constexpr int kDefaultSshPort = 22;
|
||||
|
||||
// If |verbosity| is > 0 and |quiet| is false, output from scp, ssh etc.
|
||||
// commands is shown.
|
||||
// If |quiet| is true, scp, ssh etc. commands use quiet mode.
|
||||
@@ -38,61 +39,67 @@ class RemoteUtil {
|
||||
RemoteUtil(int verbosity, bool quiet, ProcessFactory* process_factory,
|
||||
bool forward_output_to_log);
|
||||
|
||||
// Returns the initialization status. Should be OK unless in case of some rare
|
||||
// internal error. Should be checked before accessing any members.
|
||||
const absl::Status& GetInitStatus() const {
|
||||
return sdk_util_.GetInitStatus();
|
||||
}
|
||||
// Sets the SSH username and hostname of the remote instance, as well as the
|
||||
// SSH tunnel port. |user_host| must be of the form [user@]host.
|
||||
void SetUserHostAndPort(std::string user_host, int port);
|
||||
|
||||
// Set IP of the remote instance and the ssh tunnel port.
|
||||
void SetIpAndPort(const std::string& gamelet_ip, int ssh_port);
|
||||
// Sets the SCP command binary path and additional arguments, e.g.
|
||||
// C:\path\to\scp.exe -F <ssh_config> -i <key_file>
|
||||
// -oStrictHostKeyChecking=yes -oUserKnownHostsFile="""file"""
|
||||
// By default, searches scp.exe on the path environment variables.
|
||||
void SetScpCommand(std::string scp_command);
|
||||
|
||||
// Sets the SSH command binary path and additional arguments, e.g.
|
||||
// C:\path\to\ssh.exe -F <ssh_config> -i <key_file>
|
||||
// -oStrictHostKeyChecking=yes -oUserKnownHostsFile="""file"""
|
||||
// By default, searches ssh.exe on the path environment variables.
|
||||
void SetSshCommand(std::string ssh_command);
|
||||
|
||||
// Copies |source_filepaths| to the remote folder |dest| on the gamelet using
|
||||
// scp. Must call either InitSsh or SetGameletIp before calling this method.
|
||||
// If |compress| is true, compressed upload is used.
|
||||
// scp. If |compress| is true, compressed upload is used.
|
||||
// Must call SetUserHostAndPort before calling this method.
|
||||
absl::Status Scp(std::vector<std::string> source_filepaths,
|
||||
const std::string& dest, bool compress);
|
||||
|
||||
// Syncs |source_filepaths| to the remote folder |dest| on the gamelet using
|
||||
// cdc_rsync. Must call either InitSsh or SetGameletIp before calling this
|
||||
// method.
|
||||
// cdc_rsync. Must call SetUserHostAndPort before calling this method.
|
||||
absl::Status Sync(std::vector<std::string> source_filepaths,
|
||||
const std::string& dest);
|
||||
|
||||
// Calls 'chmod |mode| |remote_path|' on the gamelet.
|
||||
// Must call either InitSsh or SetGameletIp before calling this method.
|
||||
// Must call SetUserHostAndPort before calling this method.
|
||||
absl::Status Chmod(const std::string& mode, const std::string& remote_path,
|
||||
bool quiet = false);
|
||||
|
||||
// Calls 'rm [-f] |remote_path|' on the gamelet.
|
||||
// Must call either InitSsh or SetGameletIp before calling this method.
|
||||
// Must call SetUserHostAndPort before calling this method.
|
||||
absl::Status Rm(const std::string& remote_path, bool force);
|
||||
|
||||
// Calls `mv |old_remote_path| |new_remote_path| on the gamelet.
|
||||
// Must call either InitSsh or SetGameletIp before calling this method.
|
||||
// Must call SetUserHostAndPort before calling this method.
|
||||
absl::Status Mv(const std::string& old_remote_path,
|
||||
const std::string& new_remote_path);
|
||||
|
||||
// Runs |remote_command| on the gamelet. The command must be properly escaped.
|
||||
// |name| is the name of the command displayed in the logs.
|
||||
// Must call either InitSsh or SetGameletIp before calling this method.
|
||||
// Must call SetUserHostAndPort before calling this method.
|
||||
absl::Status Run(std::string remote_command, std::string name);
|
||||
|
||||
// Builds an ssh command that executes |remote_command| on the gamelet.
|
||||
// Builds an SSH command that executes |remote_command| on the gamelet.
|
||||
ProcessStartInfo BuildProcessStartInfoForSsh(std::string remote_command);
|
||||
|
||||
// Builds an ssh command that runs SSH port forwarding to the gamelet, using
|
||||
// Builds an SSH command that runs SSH port forwarding to the gamelet, using
|
||||
// the given |local_port| and |remote_port|.
|
||||
// If |reverse| is true, sets up reverse port forwarding.
|
||||
// Must call either InitSsh or SetGameletIp before calling this method.
|
||||
// Must call SetUserHostAndPort before calling this method.
|
||||
ProcessStartInfo BuildProcessStartInfoForSshPortForward(int local_port,
|
||||
int remote_port,
|
||||
bool reverse);
|
||||
|
||||
// Builds an ssh command that executes |remote_command| on the gamelet, using
|
||||
// Builds an SSH command that executes |remote_command| on the gamelet, using
|
||||
// port forwarding with given |local_port| and |remote_port|.
|
||||
// If |reverse| is true, sets up reverse port forwarding.
|
||||
// Must call either InitSsh or SetGameletIp before calling this method.
|
||||
// Must call SetUserHostAndPort before calling this method.
|
||||
ProcessStartInfo BuildProcessStartInfoForSshPortForwardAndCommand(
|
||||
int local_port, int remote_port, bool reverse,
|
||||
std::string remote_command);
|
||||
@@ -100,9 +107,28 @@ class RemoteUtil {
|
||||
// Returns whether output is suppressed.
|
||||
bool Quiet() const { return quiet_; }
|
||||
|
||||
// Escapes command line argument for the Microsoft command line parser in
|
||||
// preparation for quoting. Double quotes are backslash-escaped. One or more
|
||||
// backslashes are backslash-escaped if they are followed by a double quote,
|
||||
// or if they occur at the end of the string, e.g.
|
||||
// foo\bar -> foo\bar, foo\ -> foo\\, foo\\"bar -> foo\\\\\"bar.
|
||||
static std::string EscapeForWindows(const std::string& argument);
|
||||
|
||||
// Quotes and escapes a command line argument following the convention
|
||||
// understood by the Microsoft command line parser.
|
||||
static std::string QuoteArgument(const std::string& argument);
|
||||
|
||||
// Quotes and escapes a command line argument for usage in SSH.
|
||||
static std::string QuoteArgumentForSsh(const std::string& argument);
|
||||
|
||||
// Quotes and escapes a command line arguments for use in SSH command. The
|
||||
// argument is first escaped and quoted for Linux using single quotes and then
|
||||
// it is escaped to be used by the Microsoft command line parser.
|
||||
static std::string QuoteAndEscapeArgumentForSsh(const std::string& argument);
|
||||
|
||||
private:
|
||||
// Verifies that both |gamelet_ip_| and |ssh_port_| are set.
|
||||
absl::Status CheckIpPort();
|
||||
// Verifies that both || and |ssh_port_| are set.
|
||||
absl::Status CheckHostPort();
|
||||
|
||||
// Common code for BuildProcessStartInfoForSsh*.
|
||||
ProcessStartInfo BuildProcessStartInfoForSshInternal(
|
||||
@@ -113,9 +139,10 @@ class RemoteUtil {
|
||||
ProcessFactory* const process_factory_;
|
||||
const bool forward_output_to_log_;
|
||||
|
||||
SdkUtil sdk_util_;
|
||||
std::string gamelet_ip_;
|
||||
int ssh_port_ = 0;
|
||||
std::string scp_command_ = "scp";
|
||||
std::string ssh_command_ = "ssh";
|
||||
std::string user_host_;
|
||||
int ssh_port_ = kDefaultSshPort;
|
||||
};
|
||||
|
||||
} // namespace cdc_ft
|
||||
|
||||
@@ -21,11 +21,11 @@
|
||||
namespace cdc_ft {
|
||||
namespace {
|
||||
|
||||
constexpr int kGameletPort = 12345;
|
||||
constexpr char kGameletPortArg[] = "-p 12345";
|
||||
constexpr int kSshPort = 12345;
|
||||
constexpr char kSshPortArg[] = "-p 12345";
|
||||
|
||||
constexpr char kGameletIp[] = "1.2.3.4";
|
||||
constexpr char kGameletIpArg[] = "cloudcast@\"1.2.3.4\"";
|
||||
constexpr char kUserHost[] = "user@example.com";
|
||||
constexpr char kUserHostArg[] = "\"user@example.com\"";
|
||||
|
||||
constexpr int kLocalPort = 23456;
|
||||
constexpr int kRemotePort = 34567;
|
||||
@@ -44,7 +44,7 @@ class RemoteUtilTest : public ::testing::Test {
|
||||
|
||||
void SetUp() override {
|
||||
Log::Initialize(std::make_unique<ConsoleLog>(LogLevel::kInfo));
|
||||
util_.SetIpAndPort(kGameletIp, kGameletPort);
|
||||
util_.SetUserHostAndPort(kUserHost, kSshPort);
|
||||
}
|
||||
|
||||
void TearDown() override { Log::Shutdown(); }
|
||||
@@ -64,42 +64,68 @@ class RemoteUtilTest : public ::testing::Test {
|
||||
|
||||
TEST_F(RemoteUtilTest, BuildProcessStartInfoForSsh) {
|
||||
ProcessStartInfo si = util_.BuildProcessStartInfoForSsh(kCommand);
|
||||
ExpectContains(si.command,
|
||||
{"ssh.exe", "GGP\\ssh\\id", "oStrictHostKeyChecking=yes",
|
||||
"oUserKnownHostsFile", "known_hosts", kGameletPortArg,
|
||||
kGameletIpArg, kCommand});
|
||||
ExpectContains(si.command, {"ssh", kSshPortArg, kUserHostArg, kCommand});
|
||||
}
|
||||
|
||||
TEST_F(RemoteUtilTest, BuildProcessStartInfoForSshPortForward) {
|
||||
ProcessStartInfo si = util_.BuildProcessStartInfoForSshPortForward(
|
||||
kLocalPort, kRemotePort, kRegular);
|
||||
ExpectContains(si.command,
|
||||
{"ssh.exe", "GGP\\ssh\\id", "oStrictHostKeyChecking=yes",
|
||||
"oUserKnownHostsFile", "known_hosts", kGameletPortArg,
|
||||
kGameletIpArg, kPortForwardingArg});
|
||||
{"ssh", kSshPortArg, kUserHostArg, kPortForwardingArg});
|
||||
|
||||
si = util_.BuildProcessStartInfoForSshPortForward(kLocalPort, kRemotePort,
|
||||
kReverse);
|
||||
ExpectContains(si.command,
|
||||
{"ssh.exe", "GGP\\ssh\\id", "oStrictHostKeyChecking=yes",
|
||||
"oUserKnownHostsFile", "known_hosts", kGameletPortArg,
|
||||
kGameletIpArg, kReversePortForwardingArg});
|
||||
{"ssh", kSshPortArg, kUserHostArg, kReversePortForwardingArg});
|
||||
}
|
||||
|
||||
TEST_F(RemoteUtilTest, BuildProcessStartInfoForSshPortForwardAndCommand) {
|
||||
ProcessStartInfo si = util_.BuildProcessStartInfoForSshPortForwardAndCommand(
|
||||
kLocalPort, kRemotePort, kRegular, kCommand);
|
||||
ExpectContains(si.command,
|
||||
{"ssh.exe", "GGP\\ssh\\id", "oStrictHostKeyChecking=yes",
|
||||
"oUserKnownHostsFile", "known_hosts", kGameletPortArg,
|
||||
kGameletIpArg, kPortForwardingArg, kCommand});
|
||||
ExpectContains(si.command, {"ssh", kSshPortArg, kUserHostArg,
|
||||
kPortForwardingArg, kCommand});
|
||||
|
||||
si = util_.BuildProcessStartInfoForSshPortForwardAndCommand(
|
||||
kLocalPort, kRemotePort, kReverse, kCommand);
|
||||
ExpectContains(si.command,
|
||||
{"ssh.exe", "GGP\\ssh\\id", "oStrictHostKeyChecking=yes",
|
||||
"oUserKnownHostsFile", "known_hosts", kGameletPortArg,
|
||||
kGameletIpArg, kReversePortForwardingArg, kCommand});
|
||||
ExpectContains(si.command, {"ssh", kSshPortArg, kUserHostArg,
|
||||
kReversePortForwardingArg, kCommand});
|
||||
}
|
||||
TEST_F(RemoteUtilTest, BuildProcessStartInfoForSshWithCustomCommand) {
|
||||
constexpr char kCustomSshCmd[] = "C:\\path\\to\\ssh.exe --fooarg --bararg=42";
|
||||
util_.SetSshCommand(kCustomSshCmd);
|
||||
ProcessStartInfo si = util_.BuildProcessStartInfoForSsh(kCommand);
|
||||
ExpectContains(si.command, {kCustomSshCmd});
|
||||
}
|
||||
|
||||
TEST_F(RemoteUtilTest, EscapeForWindows) {
|
||||
EXPECT_EQ("foo", RemoteUtil::EscapeForWindows("foo"));
|
||||
EXPECT_EQ("foo bar", RemoteUtil::EscapeForWindows("foo bar"));
|
||||
EXPECT_EQ("foo\\bar", RemoteUtil::EscapeForWindows("foo\\bar"));
|
||||
EXPECT_EQ("\\\\foo", RemoteUtil::EscapeForWindows("\\\\foo"));
|
||||
EXPECT_EQ("foo\\\\", RemoteUtil::EscapeForWindows("foo\\"));
|
||||
EXPECT_EQ("foo\\\\\\\\", RemoteUtil::EscapeForWindows("foo\\\\"));
|
||||
EXPECT_EQ("foo\\\"", RemoteUtil::EscapeForWindows("foo\""));
|
||||
EXPECT_EQ("foo\\\"bar", RemoteUtil::EscapeForWindows("foo\"bar"));
|
||||
EXPECT_EQ("foo\\\\\\\"bar", RemoteUtil::EscapeForWindows("foo\\\"bar"));
|
||||
EXPECT_EQ("foo\\\\\\\\\\\"bar", RemoteUtil::EscapeForWindows("foo\\\\\"bar"));
|
||||
EXPECT_EQ("\\\"foo\\\"", RemoteUtil::EscapeForWindows("\"foo\""));
|
||||
EXPECT_EQ("\\\" \\file.txt", RemoteUtil::EscapeForWindows("\" \\file.txt"));
|
||||
}
|
||||
|
||||
TEST_F(RemoteUtilTest, QuoteArgument) {
|
||||
EXPECT_EQ("\"foo\"", RemoteUtil::QuoteArgument("foo"));
|
||||
EXPECT_EQ("\"foo bar\"", RemoteUtil::QuoteArgument("foo bar"));
|
||||
EXPECT_EQ("\"foo\\bar\"", RemoteUtil::QuoteArgument("foo\\bar"));
|
||||
EXPECT_EQ("\"\\\\foo\"", RemoteUtil::QuoteArgument("\\\\foo"));
|
||||
EXPECT_EQ("\"foo\\\\\"", RemoteUtil::QuoteArgument("foo\\"));
|
||||
EXPECT_EQ("\"foo\\\\\\\\\"", RemoteUtil::QuoteArgument("foo\\\\"));
|
||||
EXPECT_EQ("\"foo\\\"\"", RemoteUtil::QuoteArgument("foo\""));
|
||||
EXPECT_EQ("\"foo\\\"bar\"", RemoteUtil::QuoteArgument("foo\"bar"));
|
||||
EXPECT_EQ("\"foo\\\\\\\"bar\"", RemoteUtil::QuoteArgument("foo\\\"bar"));
|
||||
EXPECT_EQ("\"foo\\\\\\\\\\\"bar\"",
|
||||
RemoteUtil::QuoteArgument("foo\\\\\"bar"));
|
||||
EXPECT_EQ("\"\\\"foo\\\"\"", RemoteUtil::QuoteArgument("\"foo\""));
|
||||
EXPECT_EQ("\"\\\" \\file.txt\"", RemoteUtil::QuoteArgument("\" \\file.txt"));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -31,13 +31,6 @@ SdkUtil::SdkUtil() {
|
||||
absl::Status status = path::GetEnv("GGP_SDK_PATH", &ggp_sdk_path_env_);
|
||||
if (absl::IsNotFound(status) || ggp_sdk_path_env_.empty())
|
||||
ggp_sdk_path_env_ = path::Join(program_files_path_, "GGP SDK");
|
||||
|
||||
// Create an empty config file if it does not exist yet.
|
||||
const std::string ssh_config_path = GetSshConfigPath();
|
||||
if (!path::Exists(ssh_config_path)) {
|
||||
init_status_.Update(path::CreateDirRec(path::DirName(ssh_config_path)));
|
||||
init_status_.Update(path::WriteFile(ssh_config_path, nullptr, 0));
|
||||
}
|
||||
}
|
||||
|
||||
SdkUtil::~SdkUtil() = default;
|
||||
@@ -57,37 +50,8 @@ std::string SdkUtil::GetLogPath(const char* log_base_name) const {
|
||||
return path::Join(GetUserConfigPath(), "logs", log_base_name + timestamp_ext);
|
||||
}
|
||||
|
||||
std::string SdkUtil::GetSshConfigPath() const {
|
||||
return path::Join(GetUserConfigPath(), "ssh", "config");
|
||||
}
|
||||
|
||||
std::string SdkUtil::GetSshKeyFilePath() const {
|
||||
return path::Join(GetUserConfigPath(), "ssh", "id_rsa");
|
||||
}
|
||||
|
||||
std::string SdkUtil::GetSshKnownHostsFilePath() const {
|
||||
return path::Join(GetUserConfigPath(), "ssh", "known_hosts");
|
||||
}
|
||||
|
||||
std::string SdkUtil::GetSDKPath() const {
|
||||
assert(init_status_.ok());
|
||||
return ggp_sdk_path_env_;
|
||||
}
|
||||
|
||||
std::string SdkUtil::GetDevBinPath() const {
|
||||
return path::Join(GetSDKPath(), "dev", "bin");
|
||||
}
|
||||
|
||||
std::string SdkUtil::GetSshPath() const {
|
||||
return path::Join(GetSDKPath(), "tools", "OpenSSH-Win64");
|
||||
}
|
||||
|
||||
std::string SdkUtil::GetSshExePath() const {
|
||||
return path::Join(GetSshPath(), "ssh.exe");
|
||||
}
|
||||
|
||||
std::string SdkUtil::GetScpExePath() const {
|
||||
return path::Join(GetSshPath(), "scp.exe");
|
||||
return path::Join(ggp_sdk_path_env_, "dev", "bin");
|
||||
}
|
||||
|
||||
} // namespace cdc_ft
|
||||
|
||||
@@ -51,38 +51,10 @@ class SdkUtil {
|
||||
// %APPDATA%\GGP\logs\log_base_name.20210729-125930.log.
|
||||
std::string GetLogPath(const char* log_base_name) const;
|
||||
|
||||
// Returns the path of the ssh configuration file, e.g.
|
||||
// %APPDATA%\GGP\ssh\config.
|
||||
std::string GetSshConfigPath() const;
|
||||
|
||||
// Returns the path of the ssh private key file in the SDK configuration, e.g.
|
||||
// %APPDATA%\GGP\ssh\id_rsa.
|
||||
std::string GetSshKeyFilePath() const;
|
||||
|
||||
// Returns the path of the ssh known_hosts file in the SDK configuration, e.g.
|
||||
// %APPDATA%\GGP\ssh\known_hosts.
|
||||
std::string GetSshKnownHostsFilePath() const;
|
||||
|
||||
// Returns the path of the installed SDK, e.g.
|
||||
// C:\Program Files\GGP SDK.
|
||||
std::string GetSDKPath() const;
|
||||
|
||||
// Returns the path of the dev tools that ship with the SDK, e.g.
|
||||
// C:\Program Files\GGP SDK\dev\bin.
|
||||
std::string GetDevBinPath() const;
|
||||
|
||||
// Returns the path of the OpenSSH tools that ship with the SDK, e.g.
|
||||
// C:\Program Files\GGP SDK\tools\OpenSSH-Win64.
|
||||
std::string GetSshPath() const;
|
||||
|
||||
// Returns the path of ssh.exe that ships with the SDK, e.g.
|
||||
// C:\Program Files\GGP SDK\tools\OpenSSH-Win64\ssh.exe.
|
||||
std::string GetSshExePath() const;
|
||||
|
||||
// Returns the path of scp.exe that ships with the SDK, e.g.
|
||||
// C:\Program Files\GGP SDK\tools\OpenSSH-Win64\scp.exe.
|
||||
std::string GetScpExePath() const;
|
||||
|
||||
private:
|
||||
std::string roaming_appdata_path_;
|
||||
std::string program_files_path_;
|
||||
|
||||
@@ -42,13 +42,6 @@ class SdkUtilTest : public ::testing::Test {
|
||||
|
||||
protected:
|
||||
void CheckSdkPaths(const SdkUtil& sdk_util, const std::string& sdk_dir) {
|
||||
EXPECT_EQ(sdk_util.GetSDKPath(), sdk_dir);
|
||||
EXPECT_EQ(sdk_util.GetSshPath(),
|
||||
path::Join(sdk_dir, "tools\\OpenSSH-Win64"));
|
||||
EXPECT_EQ(sdk_util.GetSshExePath(),
|
||||
path::Join(sdk_dir, "tools\\OpenSSH-Win64\\ssh.exe"));
|
||||
EXPECT_EQ(sdk_util.GetScpExePath(),
|
||||
path::Join(sdk_dir, "tools\\OpenSSH-Win64\\scp.exe"));
|
||||
EXPECT_EQ(sdk_util.GetDevBinPath(), path::Join(sdk_dir, "dev", "bin"));
|
||||
}
|
||||
|
||||
@@ -81,11 +74,6 @@ TEST_F(SdkUtilTest, CheckRoamingAppDataPaths) {
|
||||
const std::string ggp_path = path::Join(appdata_dir, "GGP");
|
||||
EXPECT_EQ(sdk_util.GetUserConfigPath(), ggp_path);
|
||||
EXPECT_EQ(sdk_util.GetServicesConfigPath(), path::Join(ggp_path, "services"));
|
||||
EXPECT_EQ(sdk_util.GetSshConfigPath(), path::Join(ggp_path, "ssh", "config"));
|
||||
EXPECT_EQ(sdk_util.GetSshKeyFilePath(),
|
||||
path::Join(ggp_path, "ssh", "id_rsa"));
|
||||
EXPECT_EQ(sdk_util.GetSshKnownHostsFilePath(),
|
||||
path::Join(ggp_path, "ssh", "known_hosts"));
|
||||
}
|
||||
|
||||
TEST_F(SdkUtilTest, CheckSdkPathsWithoutGgpSdkPathEnv) {
|
||||
|
||||
@@ -77,14 +77,11 @@ enum class Tag : uint8_t {
|
||||
// The gamelet components need to be re-deployed.
|
||||
kDeployServer = 2,
|
||||
|
||||
// Something asks for user input, but we're in quiet mode.
|
||||
kInstancePickerNotAvailableInQuietMode = 3,
|
||||
|
||||
// Timeout while trying to connect to the gamelet component.
|
||||
kConnectionTimeout = 4,
|
||||
kConnectionTimeout = 3,
|
||||
|
||||
// MUST BE LAST.
|
||||
kCount = 5,
|
||||
kCount = 4,
|
||||
};
|
||||
|
||||
// Tags a status. No-op if |status| is OK. Overwrites existing tags.
|
||||
|
||||
Reference in New Issue
Block a user