]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw: frontend: add rgw_frontend_defaults configurable
authorYehuda Sadeh <yehuda@redhat.com>
Tue, 18 Feb 2020 19:24:15 +0000 (11:24 -0800)
committerYehuda Sadeh <yehuda@redhat.com>
Sat, 29 Feb 2020 03:16:47 +0000 (19:16 -0800)
Allow setting default configuration per frontend config option. This allows
having defaults for part of the frontend config options and set others.

Signed-off-by: Yehuda Sadeh <yehuda@redhat.com>
src/common/options.cc
src/rgw/rgw_frontend.cc
src/rgw/rgw_frontend.h
src/rgw/rgw_main.cc

index 4442e97ba822b64e7bcb0e5088be2155ff14d855..890f0244bab4d78c165a8eccc943fa8ca81bf988 100644 (file)
@@ -6372,6 +6372,12 @@ std::vector<Option> get_rgw_options() {
         "the type of the frontend followed by an optional space delimited set of "
         "key=value config parameters."),
 
+    Option("rgw_frontend_defaults", Option::TYPE_STR, Option::LEVEL_ADVANCED)
+    .set_default("beast ssl_certificate=config://rgw/cert/$realm/$zone.crt ssl_private_key=config://rgw/cert/$realm/$zone.key")
+    .set_description("RGW frontends default configuration")
+    .set_long_description(
+        "A comma delimited list of default frontends configuration."),
+
     Option("rgw_user_quota_bucket_sync_interval", Option::TYPE_INT, Option::LEVEL_ADVANCED)
     .set_default(180)
     .set_description("User quota bucket sync interval")
index 75910749f9ffdb3e1bdb1094ad5f6e09b2bfc925..fbde27ae6cf25a0f81f0bcf25e0827f354faefe6 100644 (file)
@@ -45,6 +45,27 @@ int RGWFrontendConfig::parse_config(const string& config,
   return 0;
 }
 
+void RGWFrontendConfig::set_default_config(RGWFrontendConfig& def_conf)
+{
+  const auto& def_conf_map = def_conf.get_config_map();
+
+  for (auto& entry : def_conf_map) {
+    if (config_map.find(entry.first) == config_map.end()) {
+      config_map.emplace(entry.first, entry.second);
+    }
+  }
+}
+
+std::optional<string> RGWFrontendConfig::get_val(const std::string& key)
+{
+ auto iter = config_map.find(key);
+ if (iter == config_map.end()) {
+   return std::nullopt;
+ }
+
+ return iter->second;
+}
+
 bool RGWFrontendConfig::get_val(const string& key, const string& def_val,
                                string *out)
 {
index 2e5d0fd23b54679c589efd95726b61915db5d124..88ee0a3f7ff51381bab528efb332da083c232920 100644 (file)
@@ -43,6 +43,10 @@ public:
     return ret < 0 ? ret : 0;
   }
 
+  void set_default_config(RGWFrontendConfig& def_conf);
+
+  std::optional<string> get_val(const std::string& key);
+
   bool get_val(const std::string& key,
                const std::string& def_val,
                std::string* out);
index e0f49c193649cfae84db51e04d4e60a420a999c4..56000999484f116f42c8e40e6e05468343dd5e81 100644 (file)
@@ -499,12 +499,36 @@ int radosgw_Main(int argc, const char **argv)
 
   list<RGWFrontend *> fes;
 
+  string frontend_defs_str = g_conf().get_val<string>("rgw_frontend_defaults");
+
+  list<string> frontends_def;
+  get_str_list(frontend_defs_str, ",", frontends_def);
+
+  map<string, std::unique_ptr<RGWFrontendConfig> > fe_def_map;
+  for (auto& f : frontends_def) {
+    RGWFrontendConfig *config = new RGWFrontendConfig(f);
+    int r = config->init();
+    if (r < 0) {
+      delete config;
+      cerr << "ERROR: failed to init default config: " << f << std::endl;
+      return EINVAL;
+    }
+
+    fe_def_map[config->get_framework()].reset(config);
+  }
+
   int fe_count = 0;
 
   for (multimap<string, RGWFrontendConfig *>::iterator fiter = fe_map.begin();
        fiter != fe_map.end(); ++fiter, ++fe_count) {
     RGWFrontendConfig *config = fiter->second;
     string framework = config->get_framework();
+
+    auto def_iter = fe_def_map.find(framework);
+    if (def_iter != fe_def_map.end()) {
+      config->set_default_config(*def_iter->second);
+    }
+
     RGWFrontend *fe = NULL;
 
     if (framework == "civetweb" || framework == "mongoose") {