mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-15 18:56:16 +02:00
3e9c3738d3
By moving `host` to the config, we can do a lot further cleanups and dedups. This anticipates a world where we always go `StoreReference` -> `*StoreConfig` -> `Store*` rather than skipping the middle step too. Progress on #10766 Progress on https://github.com/NixOS/hydra/issues/1164
43 lines
1,017 B
C++
43 lines
1,017 B
C++
#include <regex>
|
|
|
|
#include "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,
|
|
};
|
|
}
|
|
|
|
}
|