From 40f71541acdeb74e08efc43b4ee5ef5d19926652 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Rajmund=20Hru=C5=A1ka?= <rajmund.hruska@cesnet.cz>
Date: Thu, 3 Nov 2022 13:12:39 +0100
Subject: [PATCH] Expose clients via API
---
warden_server/test_warden_server.py | 13 +++++++++++++
warden_server/warden_server.py | 5 +++++
2 files changed, 18 insertions(+)
diff --git a/warden_server/test_warden_server.py b/warden_server/test_warden_server.py
index 2efe5b5..e1d0ff3 100755
--- a/warden_server/test_warden_server.py
+++ b/warden_server/test_warden_server.py
@@ -142,6 +142,19 @@ class Warden3ServerTest(unittest.TestCase):
status, _, _ = Request(self.app, query)()
self.assertEqual(status, expected_status)
+ def test_getClients_interface(self):
+ """Tests the getClients method invocation"""
+ tests_common = [
+ ("/getClients?secret=abc", "200 OK"),
+ ("/getClients?secret=abc&evil=false", "200 OK"),
+ ("/getClients?client=dwadaw", "403 I'm watching. Authenticate."),
+ ("/getClients?client=asdf.blefub&secret=abc", "403 I'm watching. Authenticate."),
+ ]
+ for query, expected_status in tests_common:
+ with self.subTest(query=query, expected_status=expected_status):
+ status, _, _ = Request(self.app, query)()
+ self.assertEqual(status, expected_status)
+
def test_getEvents_interface(self): # pylint: disable = locally-disabled, invalid-name
"""Tests the getEvents method invocation"""
tests_common = [
diff --git a/warden_server/warden_server.py b/warden_server/warden_server.py
index bbf4ff9..d66294d 100755
--- a/warden_server/warden_server.py
+++ b/warden_server/warden_server.py
@@ -1630,6 +1630,11 @@ class WardenHandler(ObjectBase):
info["description"] = self.description
return info
+ @expose(read=True)
+ @json_wrapper
+ def getClients(self):
+ return {"clients": self.db.get_clients()}
+
@expose(read=True)
@json_wrapper
def getEvents(
--
GitLab