Added maxchannels variable.
authorEric S. Raymond <esr@thyrsus.com>
Sun, 30 Sep 2012 16:35:27 +0000 (12:35 -0400)
committerEric S. Raymond <esr@thyrsus.com>
Sun, 30 Sep 2012 16:35:27 +0000 (12:35 -0400)
NEWS
irkerhook.py
irkerhook.xml

diff --git a/NEWS b/NEWS
index 10273552525ce87adecf923c200970240eb40e14..f964eca82ed17084a390d3074b35abc7707596be 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -16,6 +16,7 @@
 1.3 @
   Support for an irker.conf file to set irkerhook variables under Subversion.
   irkerhook.py now has its own manual page.
+  Added channelmax variable for rate-limiting
 
 
 
index 6a10862348d87691b369a639139be7e5b9d700ca..3e13ce2dcf438418c0675b448c306d4e9788d0a9 100755 (executable)
@@ -113,6 +113,7 @@ class GitExtractor:
         # for spammers' address harvesters - getting this wrong
         # would make the freenode #commits channel into harvester heaven.
         self.author = self.author.replace("<", "").split("@")[0].split()[-1]
+        self.maxchannels = 0
 
 def load_preferences(extractor, conf):
     "Load preferences from a file in the repository root."
@@ -138,6 +139,9 @@ def load_preferences(extractor, conf):
             val = True
         if val.lower() == "false":
             val = False
+        # User cannot set maxchannels - only a command-line arg can do that.
+        if fld == "maxchannels":
+            return
         setattr(extractor, fld, val)
 
 class SvnExtractor:
@@ -162,6 +166,7 @@ class SvnExtractor:
         self.template = '%(project)s: %(author)s %(repo)s * %(rev)s / %(files)s: %(logmsg)s %(url)s'
         self.urlprefix = "viewcvs"
         self.tinyifier = default_tinyifier
+        self.maxchannels = 0
         load_preferences(self, os.path.join(self.repository, "irker.conf"))
     def svnlook(self, info):
         return do("svnlook %s %s --revision %s" % (shellquote(info), shellquote(self.repository), shellquote(self.commit)))
@@ -207,6 +212,7 @@ if __name__ == "__main__":
     # Each argument of the form <key>=<value> can override the
     # <key> member of the extractor class. 
     booleans = ["tcp"]
+    numerics = ["maxchannels"]
     for tok in arguments:
         for key in extractor.__dict__:
             if tok.startswith(key + "="):
@@ -216,6 +222,8 @@ if __name__ == "__main__":
                         setattr(extractor, key, True)
                     elif val.lower() == "false":
                         setattr(extractor, key, False)
+                elif key in numerics:
+                    setattr(extractor, key, int(val))
                 else:
                     setattr(extractor, key, val)
 
@@ -246,6 +254,8 @@ if __name__ == "__main__":
         privmsg = extractor.template % extractor.__dict__
 
     channel_list = extractor.channels.split(",")
+    if extractor.maxchannels != 0:
+        channel_list = channel_list[:extractor.maxchannels]
     structure = {"to":channel_list, "privmsg":privmsg}
     message = json.dumps(structure)
     if not notify:
index d0ea0b722a2f8cb79d2fbd4c9e805521b219b887..a4d0019a5635c7b4fa4182985605b667285f16b1 100644 (file)
@@ -114,6 +114,20 @@ expanded to the value of the "repo" variable.</para>
 will take up less space in the notification line.</para>
 </listitem>
 </varlistentry>
+<varlistentry>
+<term>maxchannels</term>
+<listitem>
+<para>Interpreted as an integer. If not zero, limits the number of
+channels the hook will interpret from the "channels" variable.</para>
+
+<para>This variable cannot be set through VCS configuration variables
+or <filename>irker.conf</filename>; it can only be set with a command-line
+argument.  Thus, on a forge site in which repository owners are not
+allowed to modify their post-commit scripts, a site administrator can set it 
+to prevent shotgun spamming by malicious project owners.  Setting it to
+a value less than 2, however, would probably be unwise.</para>
+</listitem>
+</varlistentry>
 </variablelist>
 
 <refsect2 id="git"><title>git</title>