Skip to content

Commit

Permalink
Merge pull request bareos#1850
Browse files Browse the repository at this point in the history
VMware Plugin: Adapt to Python 3.12
  • Loading branch information
BareosBot authored Jul 3, 2024
2 parents 8e9465c + bed6de4 commit b0a6229
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 22 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- pull-request-template: add milestone check to reviewers list [PR #1868]
- contrib: add pure python statefile parser [PR #1789]
- Use only MinGW VSS [PR #1847]
- VMware Plugin: Adapt to Python 3.12 [PR #1850]

### Removed
- plugins: remove old deprecated postgres plugin [PR #1606]
Expand Down Expand Up @@ -195,6 +196,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[PR #1829]: https://github.com/bareos/bareos/pull/1829
[PR #1840]: https://github.com/bareos/bareos/pull/1840
[PR #1847]: https://github.com/bareos/bareos/pull/1847
[PR #1850]: https://github.com/bareos/bareos/pull/1850
[PR #1853]: https://github.com/bareos/bareos/pull/1853
[PR #1865]: https://github.com/bareos/bareos/pull/1865
[PR #1868]: https://github.com/bareos/bareos/pull/1868
Expand Down
10 changes: 5 additions & 5 deletions core/cmake/get_python_compile_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

# BAREOS(R) - Backup Archiving REcovery Open Sourced
#
# Copyright (C) 2020-2020 Bareos GmbH & Co. KG
# Copyright (C) 2020-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
Expand Down Expand Up @@ -34,7 +34,7 @@
for var in ("CC", "BLDSHARED"):
value = sysconfig.get_config_var(var)
print(
'message(STATUS "Python{0}_{1}\ is\ {2}")'.format(
'message(STATUS "Python{0}_{1} is {2}")'.format(
sys.version_info[0], var, value
)
)
Expand All @@ -47,7 +47,7 @@
value = ""
# as these vars contain the compiler itself, we remove the first word and return it as _FLAGS
print(
'message(STATUS "Python{0}_{1}_FLAGS\ is\ {2}")'.format(
'message(STATUS "Python{0}_{1}_FLAGS is {2}")'.format(
sys.version_info[0], var, value
)
)
Expand All @@ -56,7 +56,7 @@
for var in ("CFLAGS", "CCSHARED", "INCLUDEPY", "LDFLAGS"):
value = sysconfig.get_config_var(var)
print(
'message(STATUS "Python{0}_{1}\ is\ {2}")'.format(
'message(STATUS "Python{0}_{1} is {2}")'.format(
sys.version_info[0], var, value
)
)
Expand All @@ -67,7 +67,7 @@
if value is None:
value = ""
print(
'message(STATUS "Python{0}_{1}\ is\ {2}")'.format(
'message(STATUS "Python{0}_{1} is {2}")'.format(
sys.version_info[0], var, value
)
)
Expand Down
38 changes: 21 additions & 17 deletions core/src/plugins/filed/python/vmware/bareos-fd-vmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ def parse_config_file(self):
self.config = configparser.ConfigParser()

try:
self.config.readfp(open(self.options["config_file"]))
with open(self.options["config_file"]) as fp:
self.config.read_file(fp)
except IOError as err:
bareosfd.JobMessage(
bareosfd.M_FATAL,
Expand Down Expand Up @@ -2957,36 +2958,39 @@ def cleanup_tmp_files(self):

def fetch_vcthumbprint(self):
"""
Retrieve the SSL Cert thumbprint from VC Server
Fetch the SSL Cert thumbprint from VC Server
"""
if self.fetched_vcthumbprint:
return True

success = True
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.settimeout(5)
wrappedSocket = ssl.wrap_socket(sock)
ssl_context = ssl.create_default_context()
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE

bareosfd.DebugMessage(
100,
"retrieve_vcthumbprint() Retrieving SSL ThumbPrint from %s\n"
"fetch_vcthumbprint() Retrieving SSL ThumbPrint from %s\n"
% (self.options["vcserver"]),
)

try:
wrappedSocket.connect((self.options["vcserver"], 443))
with socket.create_connection(
(self.options["vcserver"], 443), timeout=5
) as sock:
with ssl_context.wrap_socket(
sock, server_hostname=self.options["vcserver"]
) as wrappedSocket:
der_cert_bin = wrappedSocket.getpeercert(True)
thumb_sha1 = hashlib.sha1(der_cert_bin).hexdigest()
self.fetched_vcthumbprint = thumb_sha1.upper()
return True
except Exception as e:
bareosfd.JobMessage(
bareosfd.M_FATAL,
"Could not retrieve SSL Cert from %s: %s\n"
"Could not fetch SSL Cert from %s: %s\n"
% (self.options["vcserver"], str(e)),
)
success = False
else:
der_cert_bin = wrappedSocket.getpeercert(True)
thumb_sha1 = hashlib.sha1(der_cert_bin).hexdigest()
self.fetched_vcthumbprint = thumb_sha1.upper()

wrappedSocket.close()
return success
return False

def retrieve_vcthumbprint(self):
"""
Expand Down

0 comments on commit b0a6229

Please sign in to comment.