mirror of
https://github.com/nestriness/cdc-file-transfer.git
synced 2026-01-30 14:35:37 +02:00
[cdc_rsync] [cdc_stream] Remove SSH port argument (#41)
This CL removes the port arguments for both tools. The port argument can also be specified via the ssh-command and scp-command flags. In fact, if a port is specified by both port flags and ssh/scp commands, they interfere with each other. For ssh, the one specified in ssh-command wins. For scp, the one specified in scp-command wins. To fix this, one would have to parse scp-command and remove the port arg there. Or we could just remove the ssh-port arg. This is what this CL does. Note that if you need a custom port, it's very likely that you also have to define custom ssh and scp commands.
This commit is contained in:
@@ -99,9 +99,9 @@ CdcRsyncClient::CdcRsyncClient(const Options& options,
|
||||
std::string user_host, std::string destination)
|
||||
: options_(options),
|
||||
sources_(std::move(sources)),
|
||||
user_host_(std::move(user_host)),
|
||||
destination_(std::move(destination)),
|
||||
remote_util_(options.verbosity, options.quiet, &process_factory_,
|
||||
remote_util_(std::move(user_host), options.verbosity, options.quiet,
|
||||
&process_factory_,
|
||||
/*forward_output_to_log=*/false),
|
||||
port_manager_("cdc_rsync_ports_f77bcdfe-368c-4c45-9f01-230c5e7e2132",
|
||||
kForwardPortFirst, kForwardPortLast, &process_factory_,
|
||||
@@ -122,9 +122,6 @@ CdcRsyncClient::~CdcRsyncClient() {
|
||||
}
|
||||
|
||||
absl::Status CdcRsyncClient::Run() {
|
||||
// Initialize |remote_util_|.
|
||||
remote_util_.SetUserHostAndPort(user_host_, options_.port);
|
||||
|
||||
// Start the server process.
|
||||
absl::Status status = StartServer();
|
||||
if (HasTag(status, Tag::kDeployServer)) {
|
||||
|
||||
@@ -36,7 +36,6 @@ class ZstdStream;
|
||||
class CdcRsyncClient {
|
||||
public:
|
||||
struct Options {
|
||||
int port = RemoteUtil::kDefaultSshPort;
|
||||
bool delete_ = false;
|
||||
bool recursive = false;
|
||||
int verbosity = 0;
|
||||
@@ -118,7 +117,6 @@ class CdcRsyncClient {
|
||||
|
||||
Options options_;
|
||||
std::vector<std::string> sources_;
|
||||
const std::string user_host_;
|
||||
const std::string destination_;
|
||||
WinProcessFactory process_factory_;
|
||||
RemoteUtil remote_util_;
|
||||
|
||||
@@ -75,9 +75,9 @@ ReturnCode TagToMessage(cdc_ft::Tag tag,
|
||||
case cdc_ft::Tag::kConnectionTimeout:
|
||||
// Server connection timed out. SSH probably stale.
|
||||
*msg = absl::StrFormat(
|
||||
"Server connection timed out. Verify that host '%s' and port '%i' "
|
||||
"are correct, or specify a larger timeout with --contimeout.",
|
||||
params.user_host, params.options.port);
|
||||
"Server connection timed out. Verify that the host '%s' "
|
||||
"is correct, or specify a larger timeout with --contimeout.",
|
||||
params.user_host);
|
||||
return ReturnCode::kConnectionTimeout;
|
||||
|
||||
case cdc_ft::Tag::kCount:
|
||||
|
||||
@@ -51,8 +51,6 @@ Parameters:
|
||||
destination Remote destination directory
|
||||
|
||||
Options:
|
||||
--ip string Gamelet IP. Required.
|
||||
--port number SSH port to use. Required.
|
||||
--contimeout sec Gamelet connection timeout in seconds (default: 10)
|
||||
-q, --quiet Quiet mode, only print errors
|
||||
-v, --verbose Increase output verbosity
|
||||
@@ -74,10 +72,10 @@ Options:
|
||||
--existing Skip creating new files on instance
|
||||
--copy-dest dir Use files from dir as sync base if files are missing
|
||||
--ssh-command Path and arguments of ssh command to use, e.g.
|
||||
C:\path\to\ssh.exe -F config -i id_rsa -oStrictHostKeyChecking=yes -oUserKnownHostsFile="""known_hosts"""
|
||||
"C:\path\to\ssh.exe -p 12345 -i id_rsa -oUserKnownHostsFile=known_hosts"
|
||||
Can also be specified by the CDC_SSH_COMMAND environment variable.
|
||||
--scp-command Path and arguments of scp command to use, e.g.
|
||||
C:\path\to\scp.exe -F config -i id_rsa -oStrictHostKeyChecking=yes -oUserKnownHostsFile="""known_hosts"""
|
||||
"C:\path\to\scp.exe -P 12345 -i id_rsa -oUserKnownHostsFile=known_hosts"
|
||||
Can also be specified by the CDC_SCP_COMMAND environment variable.
|
||||
-h --help Help for cdc_rsync
|
||||
)";
|
||||
@@ -164,13 +162,6 @@ bool LoadFilesFrom(const std::string& files_from,
|
||||
|
||||
OptionResult HandleParameter(const std::string& key, const char* value,
|
||||
Parameters* params, bool* help) {
|
||||
if (key == "port") {
|
||||
if (value) {
|
||||
params->options.port = atoi(value);
|
||||
}
|
||||
return OptionResult::kConsumedKeyValue;
|
||||
}
|
||||
|
||||
if (key == "delete") {
|
||||
params->options.delete_ = true;
|
||||
return OptionResult::kConsumedKey;
|
||||
@@ -302,11 +293,6 @@ bool ValidateParameters(const Parameters& params, bool help) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (params.options.port <= 0 || params.options.port > UINT16_MAX) {
|
||||
PrintError("--port must specify a valid port");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Note: ZSTD_minCLevel() is ridiculously small (-131072), so use a
|
||||
// reasonable value.
|
||||
assert(ZSTD_minCLevel() <= Options::kMinCompressLevel);
|
||||
|
||||
@@ -97,7 +97,6 @@ class ParamsTest : public ::testing::Test {
|
||||
TEST_F(ParamsTest, ParseSucceedsDefaults) {
|
||||
const char* argv[] = {"cdc_rsync.exe", kSrc, kUserHostDst, NULL};
|
||||
EXPECT_TRUE(Parse(static_cast<int>(std::size(argv)) - 1, argv, ¶meters_));
|
||||
EXPECT_EQ(RemoteUtil::kDefaultSshPort, parameters_.options.port);
|
||||
EXPECT_FALSE(parameters_.options.delete_);
|
||||
EXPECT_FALSE(parameters_.options.recursive);
|
||||
EXPECT_EQ(0, parameters_.options.verbosity);
|
||||
@@ -145,13 +144,6 @@ TEST_F(ParamsTest, ParseFailsOnCompressLevelEqualsNoValue) {
|
||||
ExpectError(NeedsValueError("compress-level"));
|
||||
}
|
||||
|
||||
TEST_F(ParamsTest, ParseFailsOnPortEqualsNoValue) {
|
||||
const char* argv[] = {"cdc_rsync.exe", "--port=", kSrc, kUserHostDst, NULL};
|
||||
EXPECT_FALSE(
|
||||
Parse(static_cast<int>(std::size(argv)) - 1, argv, ¶meters_));
|
||||
ExpectError(NeedsValueError("port"));
|
||||
}
|
||||
|
||||
TEST_F(ParamsTest, ParseFailsOnContimeoutEqualsNoValue) {
|
||||
const char* argv[] = {"cdc_rsync.exe", "--contimeout=", kSrc, kUserHostDst,
|
||||
NULL};
|
||||
@@ -285,13 +277,18 @@ TEST_F(ParamsTest, ParseFailsOnUnknownKey) {
|
||||
}
|
||||
|
||||
TEST_F(ParamsTest, ParseSucceedsWithSupportedKeyValue) {
|
||||
const char* argv[] = {
|
||||
"cdc_rsync.exe", "--compress-level", "11", "--contimeout", "99", "--port",
|
||||
"4086", "--copy-dest=dest", kSrc, kUserHostDst, NULL};
|
||||
const char* argv[] = {"cdc_rsync.exe",
|
||||
"--compress-level",
|
||||
"11",
|
||||
"--contimeout",
|
||||
"99",
|
||||
"--copy-dest=dest",
|
||||
kSrc,
|
||||
kUserHostDst,
|
||||
NULL};
|
||||
EXPECT_TRUE(Parse(static_cast<int>(std::size(argv)) - 1, argv, ¶meters_));
|
||||
EXPECT_EQ(parameters_.options.compress_level, 11);
|
||||
EXPECT_EQ(parameters_.options.connection_timeout_sec, 99);
|
||||
EXPECT_EQ(parameters_.options.port, 4086);
|
||||
EXPECT_EQ(parameters_.options.copy_dest, "dest");
|
||||
ExpectNoError();
|
||||
}
|
||||
@@ -304,13 +301,6 @@ TEST_F(ParamsTest, ParseSucceedsWithSupportedKeyValueWithoutEqualityForChars) {
|
||||
ExpectNoError();
|
||||
}
|
||||
|
||||
TEST_F(ParamsTest, ParseFailsOnInvalidPort) {
|
||||
const char* argv[] = {"cdc_rsync.exe", "--port=0", kSrc, kUserHostDst, NULL};
|
||||
EXPECT_FALSE(
|
||||
Parse(static_cast<int>(std::size(argv)) - 1, argv, ¶meters_));
|
||||
ExpectError("--port must specify a valid port");
|
||||
}
|
||||
|
||||
TEST_F(ParamsTest, ParseFailsOnDeleteNeedsRecursive) {
|
||||
const char* argv[] = {"cdc_rsync.exe", "--delete", kSrc, kUserHostDst, NULL};
|
||||
EXPECT_FALSE(
|
||||
|
||||
Reference in New Issue
Block a user