2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-30 21:45:37 +00:00

[#2947] Extra updates

This commit is contained in:
Francis Dupont
2023-06-28 17:20:30 +02:00
parent a3c87ba5f4
commit e16ade899f
6 changed files with 19 additions and 8 deletions

View File

@@ -296,7 +296,7 @@ ControlledDhcpv4Srv::commandConfigGetHandler(const string&,
ConstElementPtr
ControlledDhcpv4Srv::commandConfigHashGetHandler(const string&,
ConstElementPtr /*args*/) {
ElementPtr config = CfgMgr::instance().getCurrentCfg()->toElement();
ConstElementPtr config = CfgMgr::instance().getCurrentCfg()->toElement();
string hash = BaseCommandMgr::getHash(config);

View File

@@ -3273,8 +3273,8 @@ TEST_F(LoadUnloadDhcpv4SrvTest, Dhcpv4SrvConfigured) {
parseAnswer(status_code, answer);
if (parameters.empty()) {
EXPECT_EQ(0, status_code);
EXPECT_EQ(answer->str(), "{ \"arguments\": { \"hash\": \"FA868B7A5983A80A83A7E9EFD8E"
"3DA4CC78B57A44817AEB9EF9DD6E4B9B0B116\" }, \"result\": 0, \"text\": "
EXPECT_EQ(answer->str(), "{ \"arguments\": { \"hash\": \"C725E95F74A5BD2DC085B2F8A2877257"
"1BE04E99F127D3D78439264071A315B1\" }, \"result\": 0, \"text\": "
"\"Configuration successful.\" }");
} else {
EXPECT_EQ(1, status_code);

View File

@@ -299,7 +299,7 @@ ControlledDhcpv6Srv::commandConfigGetHandler(const string&,
ConstElementPtr
ControlledDhcpv6Srv::commandConfigHashGetHandler(const string&,
ConstElementPtr /*args*/) {
ElementPtr config = CfgMgr::instance().getCurrentCfg()->toElement();
ConstElementPtr config = CfgMgr::instance().getCurrentCfg()->toElement();
string hash = BaseCommandMgr::getHash(config);
ElementPtr params = Element::createMap();

View File

@@ -5675,8 +5675,8 @@ TEST_F(LoadUnloadDhcpv6SrvTest, Dhcpv6SrvConfigured) {
if (parameters.empty()) {
EXPECT_EQ(0, status_code);
EXPECT_EQ(answer->str(), "{ \"arguments\": { \"hash\": \"AF30DC19D03AB71CB5AB6A77C0B8D"
"2B4D8C5F5A939D7457DF723CBFB09F80744\" }, \"result\": 0, \"text\": "
EXPECT_EQ(answer->str(), "{ \"arguments\": { \"hash\": \"A6695A043B32703BA06D981929076F1C"
"94DEC0CF414E45AF146CEF5B50DB3EAA\" }, \"result\": 0, \"text\": "
"\"Configuration successful.\" }");
} else {
EXPECT_EQ(1, status_code);

View File

@@ -193,6 +193,11 @@ BaseCommandMgr::listCommandsHandler(const std::string& /* name */,
std::string
BaseCommandMgr::getHash(const isc::data::ConstElementPtr& config) {
// Sanity.
if (!config) {
isc_throw(Unexpected, "BaseCommandMgr::getHash called with null");
}
// First, get the string representation.
std::string config_txt = config->str();
isc::util::OutputBuffer hash_data(0);
@@ -213,6 +218,5 @@ BaseCommandMgr::getHash(const isc::data::ConstElementPtr& config) {
return (isc::util::encode::encodeHex(hash));
}
} // namespace isc::config
} // namespace isc

View File

@@ -462,7 +462,7 @@ DControllerBase::configGetHandler(const std::string&,
ConstElementPtr
DControllerBase::configHashGetHandler(const std::string&,
ConstElementPtr /*args*/) {
ElementPtr config = process_->getCfgMgr()->getContext()->toElement();
ConstElementPtr config = process_->getCfgMgr()->getContext()->toElement();
std::string hash = BaseCommandMgr::getHash(config);
ElementPtr params = Element::createMap();
params->set("hash", Element::create(hash));
@@ -650,6 +650,13 @@ DControllerBase::configSetHandler(const std::string&, ConstElementPtr args) {
ConstElementPtr answer = updateConfig(module_config);
int rcode = 0;
parseAnswer(rcode, answer);
// When succeeded append the SHA256 hash of the config that
// was just set to the response.
if (rcode == CONTROL_RESULT_SUCCESS) {
// @todo
}
// In all cases the right logging configuration is in the context.
process_->getCfgMgr()->getContext()->applyLoggingCfg();
return (answer);