face+security: Introduce environment variables to set/override transport, pib, and tpm configurations.
- NDN_CLIENT_TRANSPORT: equivalent of transport in client.conf
- NDN_CLIENT_PIB: equivalent of pib in client.conf
- NDN_CLIENT_TPM: equivalent of tpm in client.conf
Whenever an environment variable is set, it takes precedence over any
values specified in the configuration file.
Change-Id: I44c2347168616387a0489b6bf5c2c3a12db29863
Refs: #2925, #2514
diff --git a/src/security/key-chain.cpp b/src/security/key-chain.cpp
index c1c605a..e6b1ff0 100644
--- a/src/security/key-chain.cpp
+++ b/src/security/key-chain.cpp
@@ -123,11 +123,29 @@
, m_tpm(nullptr)
, m_lastTimestamp(time::toUnixTimestamp(time::system_clock::now()))
{
- ConfigFile config;
- const ConfigFile::Parsed& parsed = config.getParsedConfiguration();
+ std::string pibLocator;
+ std::string tpmLocator;
- std::string pibLocator = parsed.get<std::string>("pib", "");
- std::string tpmLocator = parsed.get<std::string>("tpm", "");
+ if (getenv("NDN_CLIENT_PIB") != nullptr) {
+ pibLocator = getenv("NDN_CLIENT_PIB");
+ }
+
+ if (getenv("NDN_CLIENT_TPM") != nullptr) {
+ tpmLocator = getenv("NDN_CLIENT_TPM");
+ }
+
+ if (pibLocator.empty() || tpmLocator.empty()) {
+ ConfigFile config;
+ const ConfigFile::Parsed& parsed = config.getParsedConfiguration();
+
+ if (pibLocator.empty()) {
+ pibLocator = parsed.get<std::string>("pib", "");
+ }
+
+ if (tpmLocator.empty()) {
+ tpmLocator = parsed.get<std::string>("tpm", "");
+ }
+ }
initialize(pibLocator, tpmLocator, false);
}