allow writePolicy plugins to filter events downloaded via sync

This commit is contained in:
Doug Hoyte
2023-06-06 01:06:43 -04:00
parent abb488a570
commit d2889bc491
2 changed files with 14 additions and 3 deletions

View File

@ -9,7 +9,6 @@
#include "Subscription.h" #include "Subscription.h"
#include "WSConnection.h" #include "WSConnection.h"
#include "events.h" #include "events.h"
#include "PluginWritePolicy.h" #include "PluginWritePolicy.h"
@ -76,7 +75,6 @@ void cmd_stream(const std::vector<std::string> &subArgs) {
} else { } else {
LI << "[" << ws.remoteAddr << "] write policy blocked event " << evJson.at("id").get_string() << ": " << okMsg; LI << "[" << ws.remoteAddr << "] write policy blocked event " << evJson.at("id").get_string() << ": " << okMsg;
} }
} else { } else {
LW << "Unexpected EVENT"; LW << "Unexpected EVENT";
} }

View File

@ -10,6 +10,7 @@
#include "DBQuery.h" #include "DBQuery.h"
#include "filters.h" #include "filters.h"
#include "events.h" #include "events.h"
#include "PluginWritePolicy.h"
static const char USAGE[] = static const char USAGE[] =
@ -73,6 +74,9 @@ void cmd_sync(const std::vector<std::string> &subArgs) {
WriterPipeline writer; WriterPipeline writer;
WSConnection ws(url); WSConnection ws(url);
PluginWritePolicy writePolicy;
ws.reconnect = false; ws.reconnect = false;
ws.onConnect = [&]{ ws.onConnect = [&]{
@ -128,7 +132,16 @@ void cmd_sync(const std::vector<std::string> &subArgs) {
LW << "Unable to upload event " << msg.at(1).get_string() << ": " << msg.at(3).get_string(); LW << "Unable to upload event " << msg.at(1).get_string() << ": " << msg.at(3).get_string();
} }
} else if (msg.at(0) == "EVENT") { } else if (msg.at(0) == "EVENT") {
writer.write({ std::move(msg.at(2)), EventSourceType::Sync, url }); if (msg.get_array().size() < 3) throw herr("array too short");
auto &evJson = msg.at(2);
std::string okMsg;
auto res = writePolicy.acceptEvent(evJson, hoytech::curr_time_s(), EventSourceType::Sync, ws.remoteAddr, okMsg);
if (res == WritePolicyResult::Accept) {
writer.write({ std::move(evJson), EventSourceType::Sync, url });
} else {
LI << "[" << ws.remoteAddr << "] write policy blocked event " << evJson.at("id").get_string() << ": " << okMsg;
}
} else if (msg.at(0) == "EOSE") { } else if (msg.at(0) == "EOSE") {
inFlightDown = false; inFlightDown = false;
writer.wait(); writer.wait();