Skip to content

Dummy objects placed in cache to force an update are now proper JSON. #228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void make_dirty(std::shared_ptr<rendered_object_list> objects, const std::vector
auto obj = objects->get_object(uuid);

if (obj) {
auto new_obj = std::make_shared<rendered_object>(obj->get_id(), obj->get_type(), std::to_string(time(NULL)));
auto new_obj = std::make_shared<rendered_object>(obj->get_id(), obj->get_type(), dummy_SCIM_object(obj->get_id(), "force update"));
objects->remove_object(uuid);
objects->add_object(new_obj);
}
Expand Down
8 changes: 4 additions & 4 deletions src/scim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,8 @@ int ScimActions::create_func::operator()(const ScimActions &actions, bool& confl
actions.scim_new_cache->add_object(std::make_shared<rendered_object>(create));
else {
if (conflict) {
// Put it in cache, but make sure we update in the next run
auto copied_object = std::make_shared<rendered_object>(create.get_id(), create.get_type(), std::to_string(time(NULL)) + " (create conflict)");
// Put it in cache, but with a dummy object to make sure we update in the next run
auto copied_object = std::make_shared<rendered_object>(create.get_id(), create.get_type(), dummy_SCIM_object(create.get_id(), "create conflict"));
actions.scim_new_cache->add_object(copied_object);
}
return -1;
Expand Down Expand Up @@ -497,8 +497,8 @@ int ScimActions::update_func::operator()(const ScimActions &actions, bool& non_e
/* Insert copied object into new cache */
if (!response_json) {
if (!non_existent) {
// Keep it in cache, but make sure we retry the update next run
auto copied_object = std::make_shared<rendered_object>(object.get_id(), object.get_type(), std::to_string(time(NULL)) + " (failed update)");
// Keep it in cache, but with a dummy object to make sure we retry the update next run
auto copied_object = std::make_shared<rendered_object>(object.get_id(), object.get_type(), dummy_SCIM_object(object.get_id(), "failed update"));
actions.scim_new_cache->add_object(copied_object);
}
return -1;
Expand Down
6 changes: 5 additions & 1 deletion src/utility/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,8 @@ void parse_override(const std::string& override_str,

variable = override_str.substr(0, pos);
value = override_str.substr(pos+1);
}
}

std::string dummy_SCIM_object(const std::string& uuid, const std::string& dbg) {
return "{\"externalId\":\"" + uuid + "\",\"dbg\":\"" + dbg + "\"}";
}
16 changes: 16 additions & 0 deletions src/utility/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,20 @@ void parse_override(const std::string& override_str,
std::string& variable,
std::string& value);

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

#endif //SIMPLESCIM_UTILS_HPP