mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-15 18:56:16 +02:00
808082ea03
Progress towards #10766 I thought that #10768 achieved, but when I went to use this stuff (in Hydra), turns out it did not. (Those `using FooConfig;` lines were not working --- they are so finicky!) This PR gets the job done, and adds some trivial unit tests to make sure I did what I intended. I had to add add a header to expose `SSHStoreConfig`, after which the preexisting `ssh-store-config.*` were very confusingly named files, so I renamed them to `common-ssh-store-config.hh` to match the type defined therein.
43 lines
1 KiB
C++
43 lines
1 KiB
C++
#include <regex>
|
|
|
|
#include "common-ssh-store-config.hh"
|
|
#include "ssh.hh"
|
|
|
|
namespace nix {
|
|
|
|
static std::string extractConnStr(std::string_view scheme, std::string_view _connStr)
|
|
{
|
|
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;
|
|
}
|
|
|
|
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,
|
|
};
|
|
}
|
|
|
|
}
|