From 2281afb309452fd6c1dfa280c841bb64cb9155b9 Mon Sep 17 00:00:00 2001 From: Joerg Steffens Date: Thu, 28 Mar 2024 18:51:15 +0100 Subject: [PATCH] python-bareos: improve protocolversion handling --- python-bareos/bareos/bsock/directorconsole.py | 8 +++++--- python-bareos/bareos/bsock/protocolversions.py | 6 ++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/python-bareos/bareos/bsock/directorconsole.py b/python-bareos/bareos/bsock/directorconsole.py index 26af12b062d..b8668f52269 100644 --- a/python-bareos/bareos/bsock/directorconsole.py +++ b/python-bareos/bareos/bsock/directorconsole.py @@ -104,9 +104,11 @@ def argparser_add_default_command_line_arguments(argparser): group.add_argument( "--protocolversion", - default=ProtocolVersions.last, type=int, - help="Specify the Bareos console protocol version. Default: %(default)s (current).", + choices=set(protocolversion.value for protocolversion in ProtocolVersions) + | set([0]), + default=ProtocolVersions.last.value, + help="Specify the Bareos console protocol version (0: auto-detect, %(default)s: latest). Default: %(default)s.", dest="BAREOS_protocolversion", ) @@ -192,7 +194,7 @@ def __init__( if tls_version is not None: self.tls_version = tls_version self.identity_prefix = "R_CONSOLE" - if protocolversion is not None: + if protocolversion is not None and protocolversion > 0: self.requested_protocol_version = int(protocolversion) self.protocol_messages.set_version(self.requested_protocol_version) self.connect( diff --git a/python-bareos/bareos/bsock/protocolversions.py b/python-bareos/bareos/bsock/protocolversions.py index 8e1456254a4..22ed4e95d39 100644 --- a/python-bareos/bareos/bsock/protocolversions.py +++ b/python-bareos/bareos/bsock/protocolversions.py @@ -1,6 +1,6 @@ # BAREOS - Backup Archiving REcovery Open Sourced # -# Copyright (C) 2019-2021 Bareos GmbH & Co. KG +# Copyright (C) 2019-2024 Bareos GmbH & Co. KG # # This program is Free Software; you can redistribute it and/or # modify it under the terms of version three of the GNU Affero General Public @@ -21,8 +21,10 @@ Bareos Protocol Versions. """ +from enum import IntEnum -class ProtocolVersions(object): + +class ProtocolVersions(IntEnum): """ Bareos Protocol Versions. """