From 985705dfa4a47d66e82902fb61675d94132a947a Mon Sep 17 00:00:00 2001 From: Mark Veidemanis Date: Sat, 13 Aug 2022 22:25:42 +0100 Subject: [PATCH] Implement button to enable authentication for relay --- app/urls.py | 6 +++++ core/lib/manage/threshold.py | 7 ++++++ .../manage/threshold/irc/network/relays.html | 12 +++++++++ core/views/manage/threshold/irc.py | 25 +++++++++++++++++++ 4 files changed, 50 insertions(+) diff --git a/app/urls.py b/app/urls.py index b837317..2a7d6f0 100644 --- a/app/urls.py +++ b/app/urls.py @@ -39,6 +39,7 @@ from core.views.manage.threshold.irc import ( ThresholdIRCNetworkDel, ThresholdIRCNetworkInfo, ThresholdIRCNetworkInfoEdit, + ThresholdIRCNetworkRelayAuth, ThresholdIRCNetworkRelayDel, ThresholdIRCNetworkRelayProvision, ThresholdIRCNetworkRelays, @@ -143,6 +144,11 @@ urlpatterns = [ ThresholdIRCNetworkRelayProvision.as_view(), name="threshold_irc_network_relay_provision", ), + path( + "manage/threshold/irc/network///auth/", + ThresholdIRCNetworkRelayAuth.as_view(), + name="threshold_irc_network_relay_auth", + ), path( "manage/threshold/irc/actions/registration/", ThresholdIRCActionsRegistration.as_view(), diff --git a/core/lib/manage/threshold.py b/core/lib/manage/threshold.py index 1aea1e1..c2a4fc6 100644 --- a/core/lib/manage/threshold.py +++ b/core/lib/manage/threshold.py @@ -241,3 +241,10 @@ def irc_provision_relay(net, num): payload = {} provisioned = threshold_request(url, payload, method="POST") return provisioned + + +def irc_enable_auth(net, num): + url = f"irc/network/{net}/{num}/auth" + payload = {} + enabled = threshold_request(url, payload, method="POST") + return enabled diff --git a/core/templates/manage/threshold/irc/network/relays.html b/core/templates/manage/threshold/irc/network/relays.html index 37af50e..0d99164 100644 --- a/core/templates/manage/threshold/irc/network/relays.html +++ b/core/templates/manage/threshold/irc/network/relays.html @@ -123,6 +123,18 @@ +
+ +
diff --git a/core/views/manage/threshold/irc.py b/core/views/manage/threshold/irc.py index a770ee1..86a3486 100644 --- a/core/views/manage/threshold/irc.py +++ b/core/views/manage/threshold/irc.py @@ -158,6 +158,31 @@ class ThresholdIRCNetworkRelayProvision(SuperUserRequiredMixin, APIView): return render(request, self.template_name, context) +class ThresholdIRCNetworkRelayAuth(SuperUserRequiredMixin, APIView): + template_name = "manage/threshold/irc/network/relays.html" + + def post(self, request, net, num): + """ + Provision a relay + """ + provisioned = threshold.irc_enable_auth(net, num) + if provisioned["success"]: + + message = f"Enabled authentication on relay {num}" + message_class = "success" + else: + message = provisioned["reason"] + message_class = "danger" + relays = threshold.get_irc_relays(net) + context = { + "net": net, + "message": message, + "class": message_class, + "relays": relays["relays"], + } + return render(request, self.template_name, context) + + class ThresholdIRCNetworkRelayStatus(SuperUserRequiredMixin, APIView): template_name = "manage/threshold/irc/network/relays.html"