From 16b87308a1e61b395f6a439397dcfd54299c8f6b Mon Sep 17 00:00:00 2001 From: "Ruben S. Montero" Date: Tue, 1 Aug 2017 13:43:31 +0200 Subject: [PATCH] F #5189: Put limits in just one constant --- src/host/Host.cc | 101 ++++++++++++----------------------------------- 1 file changed, 26 insertions(+), 75 deletions(-) diff --git a/src/host/Host.cc b/src/host/Host.cc index 359080e6f1..e0a98c9e70 100644 --- a/src/host/Host.cc +++ b/src/host/Host.cc @@ -23,43 +23,6 @@ #include "Host.h" #include "Nebula.h" -/* -------------------------------------------------------------------------- */ -/* Hybrid constants */ -/* -------------------------------------------------------------------------- */ - -struct Hinfo -{ - const char *attr_name; - unsigned int bytes; -}; - -struct HybridVariable -{ - string hybrid_name; - vector template_atts; -}; - -const vector EC2 = { - {"EC2_ACCESS", 21}, - {"EC2_SECRET", 41} -}; - -const vector AZURE = { - {"AZ_ID", 41}, - {"AZ_CERT", 3130} -}; - -const vector VCENTER = { - {"VCENTER_PASSWORD", 22} -}; - -const vector REMOTE_PROVIDERS = { - {"vcenter", VCENTER}, - {"ec2", EC2}, - {"azure", AZURE} -}; - - /* ************************************************************************ */ /* Host :: Constructor/Destructor */ /* ************************************************************************ */ @@ -730,6 +693,9 @@ int Host::from_xml(const string& xml) return 0; } +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + static void nebula_crypt(const std::string in, std::string& out) { Nebula& nd = Nebula::instance(); @@ -751,53 +717,38 @@ static void nebula_crypt(const std::string in, std::string& out) out = in; } } -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ -/* HYBRID - static Interface */ -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ -static void hide_auth_fields (const vector& tfields, Host *host) -{ - string att; - string name; - string crypted; - vector::const_iterator it; - - for (it = tfields.begin(); it != tfields.end() ; ++it) - { - - name = (*it).attr_name; - - host->get_template_attribute(name.c_str(), att); - - if (!att.empty() && att.size() <= (*it).bytes) - { - nebula_crypt(att, crypted); - host->replace_template_attribute(name.c_str(), crypted); - } - } -} - -static void update_hybrid (const vector& hvars, Host *host) -{ - vector::const_iterator it; - - for (it = hvars.begin(); it != hvars.end() ; ++it) - { - hide_auth_fields((*it).template_atts, host); - } -} /* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ +static const map MAX_HOST_VAR_SIZES = { + {"EC2_ACCESS", 21}, + {"EC2_SECRET", 41}, + {"AZ_ID", 41}, + {"AZ_CERT", 3130}, + {"VCENTER_PASSWORD", 22} +}; int Host::post_update_template(string& error) { string new_im_mad; string new_vm_mad; - update_hybrid(REMOTE_PROVIDERS, this); + map::const_iterator it; + + for (it = MAX_HOST_VAR_SIZES.begin(); it != MAX_HOST_VAR_SIZES.end() ; ++it) + { + string att; + string crypted; + + get_template_attribute(it->first.c_str(), att); + + if (!att.empty() && att.size() <= it->second) + { + nebula_crypt(att, crypted); + + replace_template_attribute(it->first, crypted); + } + } get_template_attribute("IM_MAD", new_im_mad); get_template_attribute("VM_MAD", new_vm_mad);