From: Slawek Figiel Date: Tue, 27 Jun 2023 15:28:11 +0000 (+0200) Subject: [#2467] Remove the kea_connector2.py X-Git-Tag: Kea-2.4.0~34 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7e9c84467f6d3cb4b5cd1dcce999d4a20efd285c;p=thirdparty%2Fkea.git [#2467] Remove the kea_connector2.py --- diff --git a/configure.ac b/configure.ac index dbf64c2477..15b070cb1d 100644 --- a/configure.ac +++ b/configure.ac @@ -1125,15 +1125,20 @@ fi AM_CONDITIONAL([GENERATE_PARSER], [test x$enable_generate_parser != xno]) -# Kea-shell is written in python. It can work with python 2.7 or any 3.x. -# It may likely work with earlier versions, but 2.7 was the oldest one we tested -# it with. We require python only if kea-shell was enabled. It is disabled -# by default to not introduce hard dependency on python. +# Kea-shell is written in python. It can work with any 3.x. +# We require python only if kea-shell was enabled. It is disabled by default to +# not introduce hard dependency on python. AC_ARG_ENABLE(shell, [AS_HELP_STRING([--enable-shell], [enable kea-shell, a text management client for Control Agent [default=no]])], enable_shell=$enableval, enable_shell=no) +if test "x$enable_shell" != "xno"; then + major=`echo $PYTHON_VERSION | cut -d '.' -f 1` + if test "x$major" != "x3"; then + AC_MSG_WARN("kea-shell does not support python2") + fi +fi AC_ARG_ENABLE(generate_docs, [AS_HELP_STRING([--enable-generate-docs], @@ -1219,16 +1224,7 @@ if test "x${CRYPTO_NAME}" = "xBotan" && test "x$BOTAN_BOOST" = "xyes"; then fi # Decide if the shell TLS test can work. -### This will be simpler when Python 2 support will be dropped. -ca_tls_test=no -if test "x$enable_shell" != "xno"; then - major=`echo $PYTHON_VERSION | cut -d '.' -f 1` - if test "x$major" = "x3"; then - ca_tls_test="$tls_support" - else - AC_MSG_WARN("python2 kea-shell does not support HTTPS") - fi -fi +ca_tls_test="$tls_support" AM_CONDITIONAL(CA_TLS_TEST, test x$ca_tls_test != xno) AC_ARG_WITH([sphinx], diff --git a/doc/sphinx/arm/shell.rst b/doc/sphinx/arm/shell.rst index b723ada476..18853c82dc 100644 --- a/doc/sphinx/arm/shell.rst +++ b/doc/sphinx/arm/shell.rst @@ -116,7 +116,7 @@ servers, the default empty path in the URL is not enough, so the $ kea-shell --host 192.0.2.1 --port 8001 --path kea ... The Kea shell requires Python to be installed on the system. It has been -tested with Python 2.7 and various versions of Python 3, up to 3.5. +tested with various versions of Python 3, up to 3.5. Since not every Kea deployment uses this feature and there are deployments that do not have Python, the Kea shell is not enabled by default. To use it, specify ``--enable-shell`` when running ``configure`` diff --git a/src/bin/shell/Makefile.am b/src/bin/shell/Makefile.am index 786d4f676a..5dd6251610 100644 --- a/src/bin/shell/Makefile.am +++ b/src/bin/shell/Makefile.am @@ -1,6 +1,6 @@ SUBDIRS = . tests -pkgpython_PYTHON = kea_conn.py kea_connector2.py kea_connector3.py +pkgpython_PYTHON = kea_conn.py kea_connector3.py sbin_SCRIPTS = kea-shell diff --git a/src/bin/shell/kea-shell.in b/src/bin/shell/kea-shell.in index 62de548f8f..b56812d181 100644 --- a/src/bin/shell/kea-shell.in +++ b/src/bin/shell/kea-shell.in @@ -11,34 +11,25 @@ Text client for Control Agent process """ # First, let's import the right kea_connector. -# We have two versions: one for python 2.x and another for python 3.x. +# Only the python 3.x is supported. # Sadly, there's no unified way to handle http connections. The recommended # way is to use Requests (http://docs.python-requests.org/en/master/), but # that's a stand alone package that requires separate installation. One of # the design requirements was to not require any additional packages, so # the code uses standard libraries available in python. Hence two versions. -import sys -import signal import argparse +import signal +import sys from base64 import b64encode sys.path.append('@PKGPYTHONDIR@') +import kea_connector3 as kea_connector from kea_conn import CARequest # CAResponse -if sys.version_info[0] == 2: - # This is Python 2.x - import kea_connector2 as kea_connector - def auth8(string): - """Convert str into unicode""" - return unicode(string, 'utf-8') -elif sys.version_info[0] == 3: - # This is Python 3.x - import kea_connector3 as kea_connector - auth8 = str -else: - # This is... have no idea what it is. - raise SystemExit("Unknown python version:" + str(sys.version_info[0])) + +VERSION = "@PACKAGE_VERSION@" + def timeout_handler(signum, frame): """Connection timeout handler""" @@ -46,7 +37,6 @@ def timeout_handler(signum, frame): print("Connection timeout") sys.exit(1) -VERSION = "@PACKAGE_VERSION@" def shell_body(): """ @@ -82,9 +72,9 @@ def shell_body(): parser.add_argument('--service', nargs="?", action="append", help='target specified service. If not specified,' 'control agent will receive command.') - parser.add_argument('--auth-user', type=auth8, default='', + parser.add_argument('--auth-user', type=str, default='', help='Basic HTTP authentication user') - parser.add_argument('--auth-password', type=auth8, default='', + parser.add_argument('--auth-password', type=str, default='', help='Basic HTTP authentication password') parser.add_argument('command', type=str, nargs="?", default='list-commands', @@ -160,5 +150,6 @@ def shell_body(): sys.exit(0) + if __name__ == "__main__": shell_body() diff --git a/src/bin/shell/kea_connector2.py b/src/bin/shell/kea_connector2.py deleted file mode 100644 index fcd9d9bb1b..0000000000 --- a/src/bin/shell/kea_connector2.py +++ /dev/null @@ -1,45 +0,0 @@ -# Copyright (C) 2017-2021 Internet Systems Consortium, Inc. ("ISC") -# -# This Source Code Form is subject to the terms of the Mozilla Public -# License, v. 2.0. If a copy of the MPL was not distributed with this -# file, You can obtain one at http://mozilla.org/MPL/2.0/. - -""" -This is PYTHON 2.x version of HTTP connection establishment -""" - -import httplib - -from kea_conn import CAResponse # CARequest - -def send_to_control_agent(params): - """ Sends a request to Control Agent, receives a response and returns it.""" - - # No HTTP support. - if params.scheme == 'https': - raise NotImplementedError('python2 kea-shell does not support HTTPS') - - # Establish HTTP connection first. - conn = httplib.HTTPConnection(params.http_host, params.http_port) - conn.connect() - - # Use POST to send it - _ = conn.putrequest('POST', params.path) - - # Send the headers first - for k in params.headers: - conn.putheader(k, params.headers[k]) - conn.endheaders() - - # Send the body (i.e. the actual content) - conn.send(params.content) - - # Now get the response - resp = conn.getresponse() - - # Now get the response details, put it in CAResponse and - # return it - result = CAResponse(resp.status, resp.reason, resp.read()) - conn.close() - - return result