comparison mod_firewall/definitions.lib.lua @ 4512:b88f05c878ac

mod_firewall: Add basic LIST backend for receiving items from PubSub Relies on mod_pubsub_subscription
author Kim Alvefur <zash@zash.se>
date Sun, 14 Mar 2021 23:31:32 +0100
parents e9e10ec1b91c
children 0f943619e01a
comparison
equal deleted inserted replaced
4511:97fac0ba0469 4512:b88f05c878ac
186 end; 186 end;
187 contains = function (self, item) 187 contains = function (self, item)
188 return self.items and self.items[item] == true; 188 return self.items and self.items[item] == true;
189 end; 189 end;
190 }; 190 };
191
192 -- %LIST: pubsub:pubsub.example.com/node
193 -- TODO or the actual URI scheme? Bit overkill maybe?
194 -- TODO Publish items back to the service?
195 -- Step 1: Receiving pubsub events and storing them in the list
196 -- We'll start by using only the item id.
197 -- TODO Invent some custom schema for this? Needed for just a set of strings?
198 pubsubitemid = {
199 init = function(self, pubsub_spec, opts)
200 local service_addr, node = pubsub_spec:match("^([^/]*)/(.*)");
201 module:depends("pubsub_subscription");
202 module:add_item("pubsub-subscription", {
203 service = service_addr;
204 node = node;
205 on_subscribed = function ()
206 self.items = {};
207 end;
208 on_item = function (event)
209 self:add(event.item.attr.id);
210 end;
211 on_retract = function (event)
212 self:remove(event.item.attr.id);
213 end;
214 on_purge = function ()
215 self.items = {};
216 end;
217 on_unsubscribed = function ()
218 self.items = nil;
219 end;
220 on_delete= function ()
221 self.items = nil;
222 end;
223 });
224 -- TODO Initial fetch? Or should mod_pubsub_subscription do this?
225 end;
226 add = function (self, item)
227 if self.items then
228 self.items[item] = true;
229 end
230 end;
231 remove = function (self, item)
232 if self.items then
233 self.items[item] = nil;
234 end
235 end;
236 contains = function (self, item)
237 return self.items and self.items[item] == true;
238 end;
239 };
191 }; 240 };
192 list_backends.https = list_backends.http; 241 list_backends.https = list_backends.http;
193 242
194 local normalize_functions = { 243 local normalize_functions = {
195 upper = string.upper, lower = string.lower; 244 upper = string.upper, lower = string.lower;