2024-01-25 17:31:52 +02:00
|
|
|
#include <regex>
|
|
|
|
|
|
|
|
#include "ssh-store-config.hh"
|
2024-05-23 19:14:53 +03:00
|
|
|
#include "ssh.hh"
|
2024-01-25 17:31:52 +02:00
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
2024-05-23 19:14:53 +03:00
|
|
|
static std::string extractConnStr(std::string_view scheme, std::string_view _connStr)
|
2024-01-25 17:31:52 +02:00
|
|
|
{
|
|
|
|
if (_connStr.empty())
|
|
|
|
throw UsageError("`%s` store requires a valid SSH host as the authority part in Store URI", scheme);
|
|
|
|
|
|
|
|
std::string connStr{_connStr};
|
|
|
|
|
|
|
|
std::smatch result;
|
|
|
|
static std::regex v6AddrRegex("^((.*)@)?\\[(.*)\\]$");
|
|
|
|
|
|
|
|
if (std::regex_match(connStr, result, v6AddrRegex)) {
|
|
|
|
connStr = result[1].matched ? result.str(1) + result.str(3) : result.str(3);
|
|
|
|
}
|
|
|
|
|
|
|
|
return connStr;
|
|
|
|
}
|
|
|
|
|
2024-05-23 19:14:53 +03:00
|
|
|
CommonSSHStoreConfig::CommonSSHStoreConfig(std::string_view scheme, std::string_view host, const Params & params)
|
|
|
|
: StoreConfig(params)
|
|
|
|
, host(extractConnStr(scheme, host))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
SSHMaster CommonSSHStoreConfig::createSSHMaster(bool useMaster, Descriptor logFD)
|
|
|
|
{
|
|
|
|
return {
|
|
|
|
host,
|
|
|
|
sshKey.get(),
|
|
|
|
sshPublicHostKey.get(),
|
|
|
|
useMaster,
|
|
|
|
compress,
|
|
|
|
logFD,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-01-25 17:31:52 +02:00
|
|
|
}
|