From f6d4fef5e6151a9b4251344945bc3b018ea63e5e Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Tue, 18 Feb 2020 16:16:40 -0500 Subject: [PATCH] Improve error message for collective When trying to not run as root, give a better error message explaining the situation more clearly. --- confluent_server/bin/collective | 3 +++ confluent_server/confluent/sockapi.py | 31 ++++++++++++++++----------- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/confluent_server/bin/collective b/confluent_server/bin/collective index fee56ab5..e993e168 100644 --- a/confluent_server/bin/collective +++ b/confluent_server/bin/collective @@ -88,6 +88,9 @@ def show_collective(): s = client.Command().connection tlvdata.send(s, {'collective': {'operation': 'show'}}) res = tlvdata.recv(s) + if 'error' in res: + print(res['error']) + return if 'error' in res['collective']: print(res['collective']['error']) return diff --git a/confluent_server/confluent/sockapi.py b/confluent_server/confluent/sockapi.py index 8ea2ab15..6fe50770 100644 --- a/confluent_server/confluent/sockapi.py +++ b/confluent_server/confluent/sockapi.py @@ -154,20 +154,25 @@ def sessionhdl(connection, authname, skipauth=False, cert=None): cfm = authdata[1] send_data(connection, {'authpassed': 1}) request = tlvdata.recv(connection) - if request and 'collective' in request and skipauth: - if not libssl: + if request and 'collective' in request: + if skipauth: + if not libssl: + tlvdata.send( + connection, + {'collective': {'error': 'Server either does not have ' + 'python-pyopenssl installed or has an ' + 'incorrect version installed ' + '(e.g. pyOpenSSL would need to be ' + 'replaced with python-pyopenssl). ' + 'Restart confluent after updating ' + 'the dependency.'}}) + return + return collective.handle_connection(connection, None, request['collective'], + local=True) + else: tlvdata.send( - connection, - {'collective': {'error': 'Server either does not have ' - 'python-pyopenssl installed or has an ' - 'incorrect version installed ' - '(e.g. pyOpenSSL would need to be ' - 'replaced with python-pyopenssl). ' - 'Restart confluent after updating ' - 'the dependency.'}}) - return - return collective.handle_connection(connection, None, request['collective'], - local=True) + connection, + {'collective': {'error': 'collective management commands may only be used by root'}}) while request is not None: try: process_request(