Skip to content

Commit

Permalink
Implement object config sync permissions and modified attributes base…
Browse files Browse the repository at this point in the history
…d on version

refs #9927
  • Loading branch information
Michael Friedrich committed Sep 10, 2015
1 parent 8306373 commit f0eafa7
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions lib/remote/apilistener-configsync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,29 @@ Value ApiListener::ConfigUpdateObjectAPIHandler(const MessageOrigin::Ptr& origin
Log(LogWarning, "ApiListener")
<< "Received update for object: " << JsonEncode(params);

/* check permissions */
ApiListener::Ptr listener = ApiListener::GetInstance();

if (!listener) {
Log(LogCritical, "ApiListener", "No instance available.");
return Empty;
}

if (!listener->GetAcceptConfig()) {
Log(LogWarning, "ApiListener")
<< "Ignoring config update. '" << listener->GetName() << "' does not accept config.";
return Empty;
}

Endpoint::Ptr endpoint = origin->FromClient->GetEndpoint();

if (!endpoint) {
Log(LogNotice, "ApiListener")
<< "Discarding 'config update object' message from '" << origin->FromClient->GetIdentity() << "': Invalid endpoint origin (client not allowed).";
return Empty;
}

/* update the object */
ConfigType::Ptr dtype = ConfigType::GetByName(params->Get("type"));

if (!dtype) {
Expand All @@ -82,6 +105,30 @@ Value ApiListener::ConfigUpdateObjectAPIHandler(const MessageOrigin::Ptr& origin
}

//TODO-MA: modified attributes, same version
} else {
/* object exists, update its attributes if version was changed */
if (params->Get("version") > object->GetVersion()) {
Log(LogInformation, "ApiListener")
<< "Processing config update for object '" << object->GetName()
<< "': Object version '" << object->GetVersion()
<< "' is older than the received version '" << params->Get("version") << "'.";

Dictionary::Ptr modified_attributes = params->Get("modified_attributes");

if (modified_attributes) {
ObjectLock olock(modified_attributes);
BOOST_FOREACH(const Dictionary::Pair& kv, modified_attributes) {
int fid = object->GetReflectionType()->GetFieldId(kv.first);
static_cast<Object::Ptr>(object)->SetField(fid, kv.second, false, origin);
}
}
} else {
Log(LogWarning, "ApiListener")
<< "Skipping config update for object '" << object->GetName()
<< "': Object version '" << object->GetVersion()
<< "' is more recent than the received version '" << params->Get("version") << "'.";
return Empty;
}
}

return Empty;
Expand Down

0 comments on commit f0eafa7

Please sign in to comment.