in src/config/ConfigFile.cpp [156:212]
void update_port_mapping(const string & input, unordered_map<string, string> & serviceId_to_endpoint_mapping)
{
vector<string> splitting_1st_res;
// Different mappings are delimited by ,
boost::split(splitting_1st_res, input, boost::is_any_of(","), boost::algorithm::token_compress_on);
if (splitting_1st_res.empty()) {
throw std::runtime_error("Must provide at least one port or port mapping for destination-app!");
}
// Process each port mapping tags
for (auto res: splitting_1st_res) {
// Ignore empty string
if (res.empty()) continue;
vector<string> splitting_2rd_res;
// Inside the mapping, the service_id and port are delimited by =
boost::split(splitting_2rd_res,
res,
boost::algorithm::is_any_of("="), boost::algorithm::token_compress_on);
if (splitting_2rd_res.size() != 2) {
/** For v1 format, v2 local proxy will continue to support
* Example 1: Local proxy starts in v1 source mode:
* ./localproxy -r us-east-1 -s 3389 -t <source_client_access_token>
* cli_input will be 3389
* Example 2: Local proxy starts in v1 destination mode:
* ./localproxy -r us-east-1 -d localhost:22 -t <destination_client_access_token>
* cli_input will be localhost:22
*/
if (splitting_1st_res.size() == 1 && splitting_2rd_res.size() == 1) {
boost::trim(splitting_2rd_res[0]);
serviceId_to_endpoint_mapping[""] = splitting_2rd_res[0];
return;
}
else
{
throw std::runtime_error("Wrong format for the port mappings! Example: SSH1=5555,SSH2=6666.");
}
}
// Trim whitespace and insert
string service_id = boost::trim_copy(splitting_2rd_res[0]);
string endpoint = boost::trim_copy(splitting_2rd_res[1]);
if (service_id.empty() || endpoint.empty()) {
string error_message =
string("Wrong format for the port mappings: ") + res + string(" .Example: SSH1=5555");
throw std::runtime_error(error_message);
}
// Check if it's a duplicate mapping, ignore if it has been provided
if (serviceId_to_endpoint_mapping.find(service_id) != serviceId_to_endpoint_mapping.end()) {
BOOST_LOG_SEV(log, warning) << "Duplicate mappings, ignore. This mapping already exists: " << service_id << " : "
<< serviceId_to_endpoint_mapping[service_id];
continue;
}
serviceId_to_endpoint_mapping[service_id] = endpoint;
}
}