1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-22 18:50:08 +03:00

F #5189: Put limits in just one constant

This commit is contained in:
Ruben S. Montero 2017-08-01 13:43:31 +02:00
parent f87ca90bd7
commit 16b87308a1

View File

@ -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<Hinfo> template_atts;
};
const vector<Hinfo> EC2 = {
{"EC2_ACCESS", 21},
{"EC2_SECRET", 41}
};
const vector<Hinfo> AZURE = {
{"AZ_ID", 41},
{"AZ_CERT", 3130}
};
const vector<Hinfo> VCENTER = {
{"VCENTER_PASSWORD", 22}
};
const vector<HybridVariable> 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<Hinfo>& tfields, Host *host)
{
string att;
string name;
string crypted;
vector<Hinfo>::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<HybridVariable>& hvars, Host *host)
{
vector<HybridVariable>::const_iterator it;
for (it = hvars.begin(); it != hvars.end() ; ++it)
{
hide_auth_fields((*it).template_atts, host);
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
static const map<std::string, unsigned int> 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<std::string, unsigned int>::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);