File 0001-Revert-eventsapi-Add-JWT-signing-support.patch of Package GlusterFS-3.13.1

From e54d034bdd43bf7e640651f57f0ddbddead294c8 Mon Sep 17 00:00:00 2001
From: Niels de Vos <ndevos@redhat.com>
Date: Wed, 22 Nov 2017 10:59:02 +0100
Subject: [PATCH] Revert "eventsapi: Add JWT signing support"

This reverts commit 9d39bd926006d1b6b4850e8d07f9cc340baa9ed5.

Change-Id: I6780792e4569a48402d3c58f865559cd40388e8f
URL: http://lists.gluster.org/pipermail/maintainers/2017-November/003661.html
Signed-off-by: Niels de Vos <ndevos@redhat.com>
---
 events/src/peer_eventsapi.py | 40 +++++----------------------------------
 events/src/utils.py          | 45 +++++++++-----------------------------------
 glusterfs.spec.in            |  4 ++--
 3 files changed, 16 insertions(+), 73 deletions(-)

diff --git a/events/src/peer_eventsapi.py b/events/src/peer_eventsapi.py
index d72fdbe99..e3920aed7 100644
--- a/events/src/peer_eventsapi.py
+++ b/events/src/peer_eventsapi.py
@@ -18,7 +18,6 @@ import fcntl
 from errno import EACCES, EAGAIN
 import signal
 import sys
-import time
 
 import requests
 from prettytable import PrettyTable
@@ -27,7 +26,7 @@ from gluster.cliutils import (Cmd, node_output_ok, node_output_notok,
                               sync_file_to_peers, GlusterCmdException,
                               output_error, execute_in_peers, runcli,
                               set_common_args_func)
-from events.utils import LockedOpen, get_jwt_token, save_https_cert
+from events.utils import LockedOpen, save_https_cert
 
 from events.eventsapiconf import (WEBHOOKS_FILE_TO_SYNC,
                                   WEBHOOKS_FILE,
@@ -309,8 +308,6 @@ class WebhookAddCmd(Cmd):
         parser.add_argument("url", help="URL of Webhook")
         parser.add_argument("--bearer_token", "-t", help="Bearer Token",
                             default="")
-        parser.add_argument("--secret", "-s",
-                            help="Secret to add JWT Bearer Token", default="")
 
     def run(self, args):
         create_webhooks_file_if_not_exists(args)
@@ -322,8 +319,7 @@ class WebhookAddCmd(Cmd):
                                     errcode=ERROR_WEBHOOK_ALREADY_EXISTS,
                                     json_output=args.json)
 
-            data[args.url] = {"token": args.bearer_token,
-                              "secret": args.secret}
+            data[args.url] = args.bearer_token
             file_content_overwrite(WEBHOOKS_FILE, data)
 
         sync_to_peers(args)
@@ -336,8 +332,6 @@ class WebhookModCmd(Cmd):
         parser.add_argument("url", help="URL of Webhook")
         parser.add_argument("--bearer_token", "-t", help="Bearer Token",
                             default="")
-        parser.add_argument("--secret", "-s",
-                            help="Secret to add JWT Bearer Token", default="")
 
     def run(self, args):
         create_webhooks_file_if_not_exists(args)
@@ -349,16 +343,7 @@ class WebhookModCmd(Cmd):
                                     errcode=ERROR_WEBHOOK_NOT_EXISTS,
                                     json_output=args.json)
 
-            if isinstance(data[args.url], str) or \
-               isinstance(data[args.url], unicode):
-                data[args.url]["token"] = data[args.url]
-
-            if args.bearer_token != "":
-                data[args.url]["token"] = args.bearer_token
-
-            if args.secret != "":
-                data[args.url]["secret"] = args.secret
-
+            data[args.url] = args.bearer_token
             file_content_overwrite(WEBHOOKS_FILE, data)
 
         sync_to_peers(args)
@@ -392,19 +377,11 @@ class NodeWebhookTestCmd(Cmd):
     def args(self, parser):
         parser.add_argument("url")
         parser.add_argument("bearer_token")
-        parser.add_argument("secret")
 
     def run(self, args):
         http_headers = {}
-        hashval = ""
         if args.bearer_token != ".":
-            hashval = args.bearer_token
-
-        if args.secret != ".":
-            hashval = get_jwt_token(args.secret, "TEST", int(time.time()))
-
-        if hashval:
-            http_headers["Authorization"] = "Bearer " + hashval
+            http_headers["Authorization"] = "Bearer " + args.bearer_token
 
         urldata = requests.utils.urlparse(args.url)
         parts = urldata.netloc.split(":")
@@ -456,23 +433,16 @@ class WebhookTestCmd(Cmd):
     def args(self, parser):
         parser.add_argument("url", help="URL of Webhook")
         parser.add_argument("--bearer_token", "-t", help="Bearer Token")
-        parser.add_argument("--secret", "-s",
-                            help="Secret to generate Bearer Token")
 
     def run(self, args):
         url = args.url
         bearer_token = args.bearer_token
-        secret = args.secret
-
         if not args.url:
             url = "."
         if not args.bearer_token:
             bearer_token = "."
-        if not args.secret:
-            secret = "."
 
-        out = execute_in_peers("node-webhook-test", [url, bearer_token,
-                                                     secret])
+        out = execute_in_peers("node-webhook-test", [url, bearer_token])
 
         if not args.json:
             table = PrettyTable(["NODE", "NODE STATUS", "WEBHOOK STATUS"])
diff --git a/events/src/utils.py b/events/src/utils.py
index 851543e8f..8ac7a2656 100644
--- a/events/src/utils.py
+++ b/events/src/utils.py
@@ -13,11 +13,10 @@ import json
 import os
 import logging
 import fcntl
-from errno import EBADF
+from errno import ESRCH, EBADF
 from threading import Thread
 import multiprocessing
 from Queue import Queue
-from datetime import datetime, timedelta
 
 from eventsapiconf import (LOG_FILE,
                            WEBHOOKS_FILE,
@@ -185,17 +184,6 @@ def autoload_webhooks():
             load_webhooks()
 
 
-def get_jwt_token(secret, event_type, event_ts, jwt_expiry_time_seconds=60):
-    import jwt
-    payload = {
-        "exp": datetime.utcnow() + timedelta(seconds=jwt_expiry_time_seconds),
-        "iss": "gluster",
-        "sub": event_type,
-        "iat": event_ts
-    }
-    return jwt.encode(payload, secret, algorithm='HS256')
-
-
 def save_https_cert(domain, port, cert_path):
     import ssl
 
@@ -208,7 +196,7 @@ def save_https_cert(domain, port, cert_path):
         f.write(cert_data)
 
 
-def publish_to_webhook(url, token, secret, message_queue):
+def publish_to_webhook(url, token, message_queue):
     # Import requests here since not used in any other place
     import requests
 
@@ -224,16 +212,9 @@ def publish_to_webhook(url, token, secret, message_queue):
     cert_path = os.path.join(CERTS_DIR, url.replace("/", "_").strip())
 
     while True:
-        hashval = ""
-        event_type, event_ts, message_json = message_queue.get()
+        message_json = message_queue.get()
         if token != "" and token is not None:
-            hashval = token
-
-        if secret != "" and secret is not None:
-            hashval = get_jwt_token(secret, event_type, event_ts)
-
-        if hashval:
-            http_headers["Authorization"] = "Bearer " + hashval
+            http_headers["Authorization"] = "Bearer " + token
 
         verify = True
         while True:
@@ -289,7 +270,7 @@ def publish_to_webhook(url, token, secret, message_queue):
 def plugin_webhook(message):
     message_json = json.dumps(message, sort_keys=True)
     logger.debug("EVENT: {0}".format(message_json))
-    webhooks_pool.send(message["event"], message["ts"], message_json)
+    webhooks_pool.send(message_json)
 
 
 class LockedOpen(object):
@@ -369,17 +350,9 @@ class PidFile(object):
 
 def webhook_monitor(proc_queue, webhooks):
     queues = {}
-    for url, data in webhooks.items():
-        if isinstance(data, str) or isinstance(data, unicode):
-            token = data
-            secret = None
-        else:
-            token = data["token"]
-            secret = data["secret"]
-
+    for url, token in webhooks.items():
         queues[url] = Queue()
-        t = Thread(target=publish_to_webhook, args=(url, token, secret,
-                                                    queues[url]))
+        t = Thread(target=publish_to_webhook, args=(url, token, queues[url]))
         t.start()
 
     # Get the message sent to Process queue and distribute to all thread queues
@@ -408,8 +381,8 @@ class WebhookThreadPool(object):
         self.proc.terminate()
         self.start()
 
-    def send(self, event_type, event_ts, message):
-        self.queue.put((event_type, event_ts, message))
+    def send(self, message):
+        self.queue.put(message)
 
 
 def init_webhook_pool():
diff --git a/glusterfs.spec.in b/glusterfs.spec.in
index 8b4fa349e..f68e38fff 100644
--- a/glusterfs.spec.in
+++ b/glusterfs.spec.in
@@ -626,9 +626,9 @@ Requires:         %{name}-server%{?_isa} = %{version}-%{release}
 Requires:         python2 python-prettytable
 Requires:         python2-gluster = %{version}-%{release}
 %if ( 0%{?rhel} )
-Requires:         python-requests python-jwt
+Requires:         python-requests
 %else
-Requires:         python2-requests python2-jwt
+Requires:         python2-requests
 %endif
 %if ( 0%{?rhel} && 0%{?rhel} < 7 )
 Requires:         python-argparse
-- 
2.14.3