Skip to content

Commit eee4e4b

Browse files
authored
Merge pull request #228 from Sambruk/bugfix/227
Dummy objects placed in cache to force an update are now proper JSON.
2 parents cf45490 + 4558884 commit eee4e4b

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

src/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ void make_dirty(std::shared_ptr<rendered_object_list> objects, const std::vector
126126
auto obj = objects->get_object(uuid);
127127

128128
if (obj) {
129-
auto new_obj = std::make_shared<rendered_object>(obj->get_id(), obj->get_type(), std::to_string(time(NULL)));
129+
auto new_obj = std::make_shared<rendered_object>(obj->get_id(), obj->get_type(), dummy_SCIM_object(obj->get_id(), "force update"));
130130
objects->remove_object(uuid);
131131
objects->add_object(new_obj);
132132
}

src/scim.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,8 @@ int ScimActions::create_func::operator()(const ScimActions &actions, bool& confl
467467
actions.scim_new_cache->add_object(std::make_shared<rendered_object>(create));
468468
else {
469469
if (conflict) {
470-
// Put it in cache, but make sure we update in the next run
471-
auto copied_object = std::make_shared<rendered_object>(create.get_id(), create.get_type(), std::to_string(time(NULL)) + " (create conflict)");
470+
// Put it in cache, but with a dummy object to make sure we update in the next run
471+
auto copied_object = std::make_shared<rendered_object>(create.get_id(), create.get_type(), dummy_SCIM_object(create.get_id(), "create conflict"));
472472
actions.scim_new_cache->add_object(copied_object);
473473
}
474474
return -1;
@@ -497,8 +497,8 @@ int ScimActions::update_func::operator()(const ScimActions &actions, bool& non_e
497497
/* Insert copied object into new cache */
498498
if (!response_json) {
499499
if (!non_existent) {
500-
// Keep it in cache, but make sure we retry the update next run
501-
auto copied_object = std::make_shared<rendered_object>(object.get_id(), object.get_type(), std::to_string(time(NULL)) + " (failed update)");
500+
// Keep it in cache, but with a dummy object to make sure we retry the update next run
501+
auto copied_object = std::make_shared<rendered_object>(object.get_id(), object.get_type(), dummy_SCIM_object(object.get_id(), "failed update"));
502502
actions.scim_new_cache->add_object(copied_object);
503503
}
504504
return -1;

src/utility/utils.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,8 @@ void parse_override(const std::string& override_str,
230230

231231
variable = override_str.substr(0, pos);
232232
value = override_str.substr(pos+1);
233-
}
233+
}
234+
235+
std::string dummy_SCIM_object(const std::string& uuid, const std::string& dbg) {
236+
return "{\"externalId\":\"" + uuid + "\",\"dbg\":\"" + dbg + "\"}";
237+
}

src/utility/utils.hpp

+16
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,20 @@ void parse_override(const std::string& override_str,
126126
std::string& variable,
127127
std::string& value);
128128

129+
/**
130+
* Creates a JSON object for a dummy SCIM object.
131+
*
132+
* This is used when we want to place something in the cache file to force an
133+
* update. The object should be in JSON format so print-cache will work, and
134+
* it will include an "externalId" attribute. It will also include a "dbg"
135+
* attribute to give some context to why the odd object is in the cache file
136+
* in case anyone is looking at it.
137+
*
138+
* The whole returned object should be smaller than any real SCIM object in
139+
* order for the cache file size estimate to work. Since all real SCIM objects
140+
* should include a "scheme" and attributes other than externalId, this shouldn't
141+
* be a problem as long as the dbg string isn't long.
142+
*/
143+
std::string dummy_SCIM_object(const std::string& uuid, const std::string& dbg);
144+
129145
#endif //SIMPLESCIM_UTILS_HPP

0 commit comments

Comments
 (0)