Module: check_mk
Branch: master
Commit: 9f4ede341672ccf411df3569a0fca9102212cf67
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=9f4ede341672cc…
Author: Óscar Nájera <on(a)mathias-kettner.de>
Date: Thu Feb 21 16:56:57 2019 +0100
A bit more compatible py3 omdlib/certs
Change-Id: Id47cb22ec5421d7f88f0b80aa844ffd5aff0beba
---
omd/packages/omd/omdlib/certs.py | 11 +++++++----
tests/unit/omdlib/test_certs.py | 5 ++++-
2 files changed, 11 insertions(+), 5 deletions(-)
diff --git a/omd/packages/omd/omdlib/certs.py b/omd/packages/omd/omdlib/certs.py
index 7037786..b91fa16 100644
--- a/omd/packages/omd/omdlib/certs.py
+++ b/omd/packages/omd/omdlib/certs.py
@@ -27,7 +27,10 @@
import sys
from typing import Tuple # pylint: disable=unused-import
import random
-from pathlib2 import Path # pylint: disable=unused-import
+try:
+ from pathlib import Path # pylint: disable=unused-import
+except ImportError:
+ from pathlib2 import Path # pylint: disable=unused-import
from OpenSSL import crypto
from OpenSSL.SSL import FILETYPE_PEM # type: ignore
@@ -72,9 +75,9 @@ class CertificateAuthority(object):
cert.set_issuer(cert.get_subject())
cert.set_pubkey(key)
cert.add_extensions([
- crypto.X509Extension("subjectKeyIdentifier", False,
"hash", subject=cert),
- crypto.X509Extension("basicConstraints", True, "CA:TRUE,
pathlen:0"),
- crypto.X509Extension("keyUsage", True, "keyCertSign,
cRLSign"),
+ crypto.X509Extension(b"subjectKeyIdentifier", False,
b"hash", subject=cert),
+ crypto.X509Extension(b"basicConstraints", True, b"CA:TRUE,
pathlen:0"),
+ crypto.X509Extension(b"keyUsage", True, b"keyCertSign,
cRLSign"),
])
cert.sign(key, "sha512")
diff --git a/tests/unit/omdlib/test_certs.py b/tests/unit/omdlib/test_certs.py
index 72a0fdd..9c5c92f 100644
--- a/tests/unit/omdlib/test_certs.py
+++ b/tests/unit/omdlib/test_certs.py
@@ -2,7 +2,10 @@
import OpenSSL
import pytest # type: ignore
-from pathlib2 import Path
+try:
+ from pathlib import Path
+except ImportError:
+ from pathlib2 import Path
import omdlib.certs as certs