Quellcode durchsuchen

added extended search for (default) config files:
master: /etc/kind/master.conf etc/kind.master
/ffp/etc/kind/master.conf /ffp/etc/kind.master
config: <vault>/vault.conf <vault>/kind/vault.conf

Wolfgang Ortmann vor 8 Jahren
Ursprung
Commit
5446d502cc
3 geänderte Dateien mit 39 neuen und 18 gelöschten Zeilen
  1. 14 0
      src/KindConfig.cpp
  2. 2 0
      src/KindConfig.h
  3. 23 18
      src/kind.ag

+ 14 - 0
src/KindConfig.cpp

@@ -51,6 +51,20 @@ void KindConfig::addFile(const std::string& fn)
     }
 }
 
+int KindConfig::addOneFile(const std::vector<std::string> &fns)
+{
+  if (fns.empty())
+    throw Exception("Read config file", "file list empty");
+  unsigned int i=0;
+  while (!fileExists(fns[i]) && i<fns.size())
+    i++;
+
+  if (i>=fns.size())
+    throw Exception("Read config file","no file found");
+  addFile(fns[i]);
+  return i;
+}
+
 bool KindConfig::hasKey(std::string key) const
 {
   key = trim(key);

+ 2 - 0
src/KindConfig.h

@@ -5,6 +5,7 @@
 #include <string>
 #include "Strings.h"
 #include "stringtools.h"
+#include "filetools.h"
 
 class KindConfig
 {
@@ -13,6 +14,7 @@ public:
   KindConfig(const std::string& fn);
 
   void addFile(const std::string& fn);
+  int addOneFile(const std::vector<std::string>& fns);
 
   void addString(const std::string& key, const std::string& value)
   {

+ 23 - 18
src/kind.ag

@@ -122,22 +122,22 @@ void debugPrint(const string& text)
     cout << "    " << text << endl;
 }
 
-void readMasterConfig1(const string& fn, KindConfig& conf)
-{
-  verbosePrint("reading master config " + fn);
-  conf.addFile(fn);
-}
-
-void readMasterConfig(const string& fn, KindConfig& conf)
+void readMasterConfig(string fn, KindConfig& conf)
 {
   if (!fn.empty())  // master config given by user on commandline
-    readMasterConfig1(fn, conf);
-  else if (fileExists("/etc/kind/master.conf"))
-    readMasterConfig1("/etc/kind/master.conf", conf);
-  else if (fileExists("/ffp/etc/kind/master.conf"))
-    readMasterConfig1("/ffp/etc/kind/master.conf", conf);
-  else
-    throw Exception("MasterConfig", "no file");
+    conf.addFile(fn);
+  else 
+    {
+      vector<string> fns{
+	"/etc/kind/master.conf",
+	  "/etc/kind.master",
+	  "/ffp/etc/kind/master.conf",
+	  "/ffp/etc/kind.master",
+	  };
+      int i=conf.addOneFile(fns);
+      fn=fns[i];
+    }
+  verbosePrint("Read master config " + fn );
 }
 
 string findVault(const string& v)
@@ -161,10 +161,14 @@ void readVaultConfig(const string& vault, KindConfig& conf)
 {
   string vaultPath = findVault(vault);
 
-  const string& vaultConfigName = vaultPath + '/' + conf.getString("vaultConfigName");
-  verbosePrint("reading vault config:");
-  verbosePrint("  " + vaultConfigName);
-  conf.addFile(vaultConfigName);
+  Strings configNames= conf.getStrings("vaultConfigName");
+
+  vector<string> vaultConfigNames;
+  for (auto name:configNames)
+    vaultConfigNames.push_back(vaultPath + '/' + name);
+
+  int i = conf.addOneFile(vaultConfigNames);
+  verbosePrint("Read vault config "+vaultConfigNames[i]);
 
   // postprocessing
 
@@ -676,6 +680,7 @@ int main(int argc, char* argv[])
       // default-values
       conf.addString("imageName", "image");
       conf.addString("vaultConfigName", "kind/vault.conf");
+      conf.addString("vaultConfigName", "vault.conf");
       conf.addString("expireFailedImage", "3 days");
       conf.addString("expireRule", "* * * * 1 month");
       conf.addString("ping", "ping -c 1 -W 5 %host");