[Kimchi-devel] [PATCH] [Wok 4/5] Implement User Request Logger API

Lucio Correia luciojhc at linux.vnet.ibm.com
Thu Feb 25 20:47:57 UTC 2016


Signed-off-by: Lucio Correia <luciojhc at linux.vnet.ibm.com>
---
 docs/API/logs.md        | 27 +++++++++++++++++++++++++++
 src/wok/control/logs.py | 43 +++++++++++++++++++++++++++++++++++++++++++
 src/wok/model/logs.py   | 31 +++++++++++++++++++++++++++++++
 3 files changed, 101 insertions(+)
 create mode 100644 docs/API/logs.md
 create mode 100644 src/wok/control/logs.py
 create mode 100644 src/wok/model/logs.py

diff --git a/docs/API/logs.md b/docs/API/logs.md
new file mode 100644
index 0000000..f808e1a
--- /dev/null
+++ b/docs/API/logs.md
@@ -0,0 +1,27 @@
+## REST API Specification for Logs
+
+### Collection: Logs
+
+**URI:** /logs
+
+**Methods:**
+
+* **GET**: Retrieve a list of entries from User Request Log
+    * Parameters:
+        * app: Filter entries by application that received the request.
+               Use "wok" or any plugin installed, like "kimchi".
+        * req: Filter entries by type of request: "DELETE", "POST", "PUT".
+               "GET" requests are not logged.
+        * user: Filter entries by user that performed the request.
+        * date: Filter entries by date of record in the format "YYYY-MM-DD"
+        * download: Generate text file for download of search results.
+
+#### Examples
+GET /logs?download=True
+{'records': [{entry-record1}, {entry-record2}, {entry-record3}, ...],
+'uri': "/data/logs/tmpbnOzP2.txt"}
+
+GET /logs?user=dev&app=ginger
+{'records': [{entry-record1}, {entry-record2}, {entry-record3}, ...],
+'uri': None}
+
diff --git a/src/wok/control/logs.py b/src/wok/control/logs.py
new file mode 100644
index 0000000..0eb04d7
--- /dev/null
+++ b/src/wok/control/logs.py
@@ -0,0 +1,43 @@
+#
+# Project Wok
+#
+# Copyright IBM Corp, 2016
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+
+import wok.template
+
+from wok.control.base import SimpleCollection
+from wok.control.utils import get_class_name, model_fn
+from wok.control.utils import UrlSubNode
+
+
+ at UrlSubNode("logs")
+class Logs(SimpleCollection):
+    def __init__(self, model):
+        super(Logs, self).__init__(model)
+        self.role_key = 'logs'
+        self.admin_methods = ['GET']
+
+    def get(self, filter_params):
+        res_list = []
+
+        try:
+            get_list = getattr(self.model, model_fn(self, 'get_list'))
+            res_list = get_list(filter_params)
+        except AttributeError:
+            pass
+
+        return wok.template.render(get_class_name(self), res_list)
diff --git a/src/wok/model/logs.py b/src/wok/model/logs.py
new file mode 100644
index 0000000..89a79ab
--- /dev/null
+++ b/src/wok/model/logs.py
@@ -0,0 +1,31 @@
+#
+# Project Wok
+#
+# Copyright IBM Corp, 2016
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+
+from wok.reqlogger import RequestParser
+
+
+class LogsModel(object):
+    def __init__(self, **kargs):
+        pass
+
+    def get_list(self, filter_params):
+        if filter_params:
+            return RequestParser().getFilteredRecords(filter_params)
+
+        return RequestParser().getRecords()
-- 
1.9.1




More information about the Kimchi-devel mailing list