mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-11 07:10:36 +00:00
Allow override of some config via env variables
This commit is contained in:
parent
08d306f6e9
commit
fbb83704a0
@ -5,6 +5,8 @@
|
||||
#include <router_contact.hpp>
|
||||
#include <util/fs.hpp>
|
||||
|
||||
#include <absl/strings/str_cat.h>
|
||||
#include <cstdlib>
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <utility>
|
||||
@ -14,6 +16,22 @@ namespace llarp
|
||||
{
|
||||
struct ConfigParser;
|
||||
|
||||
template < typename Type >
|
||||
Type
|
||||
fromEnv(const Type& val, string_view envNameSuffix)
|
||||
{
|
||||
std::string envName = absl::StrCat("LOKINET_", envNameSuffix);
|
||||
auto ptr = std::getenv(envName.c_str());
|
||||
if(ptr)
|
||||
{
|
||||
return ptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
return val;
|
||||
}
|
||||
}
|
||||
|
||||
class RouterConfig
|
||||
{
|
||||
private:
|
||||
@ -67,16 +85,21 @@ namespace llarp
|
||||
|
||||
class NetworkConfig
|
||||
{
|
||||
public:
|
||||
using NetConfig = std::unordered_multimap< std::string, std::string >;
|
||||
|
||||
private:
|
||||
absl::optional< bool > m_enableProfiling;
|
||||
std::string m_routerProfilesFile = "profiles.dat";
|
||||
std::string m_strictConnect;
|
||||
NetConfig m_netConfig;
|
||||
|
||||
public:
|
||||
// clang-format off
|
||||
const absl::optional< bool >& enableProfiling() const { return m_enableProfiling; }
|
||||
const std::string& routerProfilesFile() const { return m_routerProfilesFile; }
|
||||
const std::string& strictConnect() const { return m_strictConnect; }
|
||||
const NetConfig& netConfig() const { return m_netConfig; }
|
||||
// clang-format on
|
||||
|
||||
void
|
||||
|
@ -808,7 +808,7 @@ namespace llarp
|
||||
}
|
||||
|
||||
// set network config
|
||||
netConfig = conf->network.netConfig;
|
||||
netConfig = conf->network.netConfig();
|
||||
|
||||
// Network config
|
||||
if(conf->network.enableProfiling().has_value())
|
||||
|
@ -92,9 +92,9 @@ metric-tank-host=52.80.56.123:2003
|
||||
ASSERT_TRUE(config.LoadFromString(text));
|
||||
|
||||
{
|
||||
using kv = decltype(config.network.netConfig)::value_type;
|
||||
using kv = NetworkConfig::NetConfig::value_type;
|
||||
|
||||
ASSERT_THAT(config.network.netConfig,
|
||||
ASSERT_THAT(config.network.netConfig(),
|
||||
UnorderedElementsAre(kv("ifname", "cluster-1"),
|
||||
kv("ifaddr", "10.101.0.1/16")));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user