Skip to content

Commit 191ba39

Browse files
Allow for the cryptography package to not be installed (use thick mode)
1 parent e8eaa9b commit 191ba39

File tree

7 files changed

+52
-8
lines changed

7 files changed

+52
-8
lines changed

doc/src/release_notes.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ Thin Mode Changes
3030
when connecting to a database that the listener configuration file states
3131
exists but actually doesn't
3232
(`issue 51 <https://github.com/oracle/python-oracledb/issues/51>`__).
33+
#) The error `DPY-3016: python-oracledb thin mode cannot be used because the
34+
cryptography package is not installed` is now raised when the cryptography
35+
package is not installed, instead of an ImportError. This allows platforms
36+
that are not capable of building the cryptography package to still use
37+
Thick mode.
3338
#) Fixed bug that prevented the `full_code` attribute from being populated on
3439
the errors returned by :func:`Cursor.getbatcherrors()`.
3540

@@ -51,7 +56,7 @@ Common Changes
5156
via the new parameter `access_token` to :func:`oracledb.connect()` and
5257
:func:`oracledb.create_pool()`.
5358
#) Added method :func:`oracledb.is_thin_mode()` to support determining whether
54-
the driver is using thin mode or not
59+
the driver is using Thin mode or not
5560
(`issue 16 <https://github.com/oracle/python-oracledb/issues/10>`__).
5661
#) Improved samples and documentation.
5762

doc/src/user_guide/installation.rst

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@ To use python-oracledb, you need:
158158

159159
- The Python cryptography package. This package is automatically installed as a
160160
dependency of python-oracledb. It is strongly recommended that you keep the
161-
cryptography package up to date whenever new versions are released.
161+
cryptography package up to date whenever new versions are released. If the
162+
cryptography package is not available, you can still install python-oracledb
163+
but can only use it in Thick mode, see :ref:`nocrypto`.
162164

163165
- Optionally, Oracle Client libraries can be installed to enable some additional
164166
advanced functionality. These can be from the free `Oracle Instant Client
@@ -745,6 +747,29 @@ offline computer and install it with::
745747
Then follow the general python-oracledb platform installation instructions
746748
to install Oracle client libraries.
747749

750+
.. _nocrypto:
751+
752+
Installing python-oracledb without the Cryptography Package
753+
===========================================================
754+
755+
If the Python cryptography package is not available, python-oracledb can still
756+
be installed but can only be used in Thick mode.
757+
758+
To install without the cryptography package, use pip's ``--no-deps`` option,
759+
for example:
760+
761+
.. code-block:: python
762+
763+
python -m pip install oracledb --no-deps
764+
765+
Oracle Client libraries must then be installed. See previous sections.
766+
767+
To use python-oracledb in Thick mode you must call
768+
:meth:`oracledb.init_oracle_client()` in your application, see
769+
:ref:`enablingthick`. Without this, your application will get the error
770+
``DPY-3016: python-oracledb thin mode cannot be used because the cryptography
771+
package is not installed``.
772+
748773
Installing from Source Code
749774
===========================
750775

@@ -803,7 +828,7 @@ used to install into a local directory::
803828
python setup.py install --user
804829

805830
Troubleshooting
806-
================
831+
===============
807832

808833
If installation fails:
809834

src/oracledb/errors.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ def _raise_from_string(exc_type: Exception, message: str) -> None:
183183
ERR_UNSUPPORTED_PYTHON_TYPE_FOR_VAR = 3013
184184
ERR_LOB_OF_WRONG_TYPE = 3014
185185
ERR_UNSUPPORTED_VERIFIER_TYPE = 3015
186+
ERR_NO_CRYPTOGRAPHY_PACKAGE = 3016
186187

187188
# error numbers that result in DatabaseError
188189
ERR_TNS_ENTRY_NOT_FOUND = 4000
@@ -392,6 +393,9 @@ def _raise_from_string(exc_type: Exception, message: str) -> None:
392393
'no configuration directory to search for tnsnames.ora',
393394
ERR_NO_CREDENTIALS:
394395
'no credentials specified',
396+
ERR_NO_CRYPTOGRAPHY_PACKAGE:
397+
'python-oracledb thin mode cannot be used because the '
398+
'cryptography package is not installed',
395399
ERR_NO_STATEMENT:
396400
'no statement specified and no prior statement prepared',
397401
ERR_NO_STATEMENT_EXECUTED:

src/oracledb/impl/thin/connection.pyx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ cdef class ThinConnImpl(BaseConnImpl):
6767
str _cclass
6868

6969
def __init__(self, str dsn, ConnectParamsImpl params):
70+
if not HAS_CRYPTOGRAPHY:
71+
errors._raise_err(errors.ERR_NO_CRYPTOGRAPHY_PACKAGE)
7072
BaseConnImpl.__init__(self, dsn, params)
7173
self._protocol = Protocol()
7274

src/oracledb/impl/thin/crypto.pyx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,15 @@
2929
# (embedded in thin_impl.pyx).
3030
#------------------------------------------------------------------------------
3131

32-
from cryptography import x509
33-
from cryptography.hazmat.primitives import hashes, serialization
34-
from cryptography.hazmat.primitives.ciphers import algorithms, modes, Cipher
35-
from cryptography.hazmat.primitives.asymmetric import padding
36-
from cryptography.hazmat.primitives.kdf import pbkdf2
32+
try:
33+
from cryptography import x509
34+
from cryptography.hazmat.primitives import hashes, serialization
35+
from cryptography.hazmat.primitives.ciphers import algorithms, modes, Cipher
36+
from cryptography.hazmat.primitives.asymmetric import padding
37+
from cryptography.hazmat.primitives.kdf import pbkdf2
38+
except ImportError:
39+
HAS_CRYPTOGRAPHY = False
40+
3741

3842
DN_REGEX = '(?:^|,\s?)(?:(?P<name>[A-Z]+)=(?P<val>"(?:[^"]|"")+"|[^,]+))+'
3943
PEM_WALLET_FILE_NAME = "ewallet.pem"

src/oracledb/impl/thin/pool.pyx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ cdef class ThinPoolImpl(BasePoolImpl):
5252
bint _open
5353

5454
def __init__(self, str dsn, PoolParamsImpl params):
55+
if not HAS_CRYPTOGRAPHY:
56+
errors._raise_err(errors.ERR_NO_CRYPTOGRAPHY_PACKAGE)
5557
params._check_credentials()
5658
self.connect_params = params
5759
self.username = params.user

src/oracledb/thin_impl.pyx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ from .var import Var
8585

8686
ctypedef unsigned char char_type
8787

88+
cdef bint HAS_CRYPTOGRAPHY = True
89+
8890
include "impl/thin/constants.pxi"
8991
include "impl/thin/utils.pyx"
9092
include "impl/thin/crypto.pyx"

0 commit comments

Comments
 (0)