X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=aspects%2Fratelimitaspects.py;h=84af0231c7e99b95b5e3d698f04f0a0d56dafe3c;hb=641a829a3412936f80849d2bb43af54c4480d197;hp=ee2178b74511611991240bc003eb7018c0a63c3c;hpb=15b5e6e9e78985d0586becf36d5bf45d5707f963;p=plcapi.git diff --git a/aspects/ratelimitaspects.py b/aspects/ratelimitaspects.py index ee2178b..84af023 100644 --- a/aspects/ratelimitaspects.py +++ b/aspects/ratelimitaspects.py @@ -25,8 +25,8 @@ class BaseRateLimit(object): self.whitelist = [] - def log(self, line) - log = open("/var/log/plc_ratelimit.log", "a") + def log(self, line): + log = open("/var/log/plc_api_ratelimit.log", "a") date = datetime.now().strftime("%d/%m/%y %H:%M") log.write("%s - %s\n" % (date, line)) log.flush() @@ -40,13 +40,30 @@ class BaseRateLimit(object): api_method_name = wobj.name api_method_source = wobj.source - api_method_caller = args[0]["Username"] + + try: + api_method = args[0]["AuthMethod"] + except: + return + + if api_method == "session": + api_method_caller = args[0]["session"] + elif api_method == "password" or api_method == "capability": + api_method_caller = args[0]["Username"] + elif api_method == "gpg": + api_method_caller = args[0]["name"] + elif api_method == "hmac" or api_method == "hmac_dummybox": + api_method_caller = args[0]["node_id"] + elif api_method == "anonymous": + api_method_caller = "anonymous" + else: + api_method_caller = "unknown" if api_method_source == None or api_method_source[0] == self.config.PLC_API_IP or api_method_source[0] in self.whitelist: return if api_method_caller == None: - self.log("%s called with Username = None" % api_method_source[0]) + self.log("%s called from %s with Username = None?" % (api_method_name, api_method_source[0])) return mc = memcache.Client(["%s:11211" % self.config.PLC_API_HOST])