Skip to content

Commit

Permalink
#109 additional checks
Browse files Browse the repository at this point in the history
  • Loading branch information
jrse committed Dec 4, 2017
1 parent 0ce84c0 commit e47eb2b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 10 deletions.
42 changes: 42 additions & 0 deletions src/librmb/rados-ceph-config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,46 @@ int RadosCephConfig::load_cfg() {
return config.from_json(&buffer) ? 0 : -1;
}

bool RadosCephConfig::is_valid_key_value(std::string &key, std::string &value) {
bool success = false;
if (value.empty() || key.empty()) {
return false;
}

if (get_config()->get_key_generated_namespace().compare(key) == 0) {
if (key.compare("true") == 0 || key.compare("false") == 0) {
success = true;
}
} else if (get_config()->get_key_ns_cfg().compare(key) == 0) {
success = true;
} else if (get_config()->get_key_ns_suffix().compare(key) == 0) {
success = true;
} else if (get_config()->get_key_public_namespace().compare(key) == 0) {
success = true;
}
return success;
}

bool RadosCephConfig::update_valid_key_value(std::string &key, std::string &value) {
bool success = false;
if (value.empty() || key.empty()) {
return false;
}
if (get_config()->get_key_generated_namespace().compare(key) == 0) {
get_config()->set_generated_namespace(value);
success = true;

} else if (get_config()->get_key_ns_cfg().compare(key) == 0) {
get_config()->set_ns_cfg(value);
success = true;
} else if (get_config()->get_key_ns_suffix().compare(key) == 0) {
get_config()->set_ns_suffix(value);
success = true;
} else if (get_config()->get_key_public_namespace().compare(key) == 0) {
get_config()->set_public_namespace(value);
success = true;
}
return success;
}

} /* namespace librmb */
3 changes: 3 additions & 0 deletions src/librmb/rados-ceph-config.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ class RadosCephConfig {
std::string get_cfg_object_name() { return config.get_cfg_object_name(); }
RadosCephJsonConfig *get_config() { return &config; }

bool is_valid_key_value(std::string &key, std::string &value);
bool update_valid_key_value(std::string &key, std::string &value);

private:
RadosCephJsonConfig config;
RadosStorage *storage;
Expand Down
16 changes: 6 additions & 10 deletions src/librmb/tools/rmb/rmb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,18 +491,14 @@ int main(int argc, const char **argv) {
<< std::endl;
std::cout << "To confirm pass --yes-i-really-really-mean-it " << std::endl;
} else {
if (ceph_cfg.get_config()->get_key_generated_namespace().compare(key) == 0) {
ceph_cfg.get_config()->set_generated_namespace(key_val);
} else if (ceph_cfg.get_config()->get_key_ns_cfg().compare(key) == 0) {
ceph_cfg.set_ns_cfg(key_val);
} else if (ceph_cfg.get_config()->get_key_ns_suffix().compare(key) == 0) {
ceph_cfg.set_ns_suffix(key_val);
} else if (ceph_cfg.get_config()->get_key_public_namespace().compare(key) == 0) {
ceph_cfg.set_public_namespace(key_val);
if (ceph_cfg.is_valid_key_value(key, key_val)) {
failed = ceph_cfg.update_valid_key_value(key, key_val);
} else {
std::cout << "ERROR: not a valid key: " << key << std::endl;
std::cout << ceph_cfg.get_config()->to_string() << std::endl;
failed = true;
std::cout << "Error: key : " << key << " value: " << key_val << " is not valid !" << std::endl;
if (key_val.compare("TRUE") == 0 || key_val.compare("FALSE") == 0) {
std::cout << "Error: value: TRUE|FALSE not supported use lower case! " << std::endl;
}
}
if (!failed) {
ceph_cfg.save_cfg();
Expand Down

0 comments on commit e47eb2b

Please sign in to comment.