From d1dfa179b32d69c024dda75c97a741f1ca6b7f52 Mon Sep 17 00:00:00 2001 From: Moritz Langer <31667222+Moritz-Langer@users.noreply.github.com> Date: Wed, 31 Jul 2024 17:04:02 +0200 Subject: [PATCH] Add Wallet for Session pool connections in oracle.py (#1768) * Added Wallet to Connection Pool * Flake8 changes * Flake8 changes * Feedback from Pull Request * Flake8 --- .../data-publishing/ogcapi-features.rst | 2 +- pygeoapi/provider/oracle.py | 34 +++++++++++++------ 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/docs/source/data-publishing/ogcapi-features.rst b/docs/source/data-publishing/ogcapi-features.rst index ad84ade..30ccf07 100644 --- a/docs/source/data-publishing/ogcapi-features.rst +++ b/docs/source/data-publishing/ogcapi-features.rst @@ -420,7 +420,7 @@ Configured using environment variables. export ORACLE_POOL_MAX=10 -The ``ORACLE_POOL_MIN`` and ``ORACLE_POOL_MAX`` environment variables are used to trigger session pool creation in the Oracle Provider and the ``DatabaseConnection`` class. See https://python-oracledb.readthedocs.io/en/latest/api_manual/module.html#oracledb.create_pool for documentation of the ``create_pool`` function. +The ``ORACLE_POOL_MIN`` and ``ORACLE_POOL_MAX`` environment variables are used to trigger session pool creation in the Oracle Provider and the ``DatabaseConnection`` class. Supports auth via user + password or wallet. For an example of the configuration see above at Oracle - Connection. See https://python-oracledb.readthedocs.io/en/latest/api_manual/module.html#oracledb.create_pool for documentation of the ``create_pool`` function. If none or only one of the environment variables is set, session pooling will not be activated and standalone connections are established at every request. diff --git a/pygeoapi/provider/oracle.py b/pygeoapi/provider/oracle.py index 4bedde7..1359779 100644 --- a/pygeoapi/provider/oracle.py +++ b/pygeoapi/provider/oracle.py @@ -66,17 +66,31 @@ class DatabaseConnection: """Initialize the connection pool for the class Lock is implemented before function call at __init__""" dsn = cls._make_dsn(conn_dict) - # Create the pool - p = oracledb.create_pool( - user=conn_dict["user"], - password=conn_dict["password"], - dsn=dsn, - min=oracle_pool_min, - max=oracle_pool_max, - increment=1, - ) - LOGGER.debug("Connection pool created successfully.") + connect_kwargs = { + 'dsn': dsn, + 'min': oracle_pool_min, + 'max': oracle_pool_max, + 'increment': 1 + } + + # Create the pool + if conn_dict.get("external_auth") == "wallet": + # If Auth is via Wallet you need to save a wallet under + # the directory returned by this bash command if apache is used + # cat /etc/passwd |grep apache + # except another directory is specified in the sqlnet.ora file + LOGGER.debug("Connection pool from wallet.") + connect_kwargs["externalauth"] = True + connect_kwargs["homogeneous"] = False + + else: + LOGGER.debug("Connection pool from user and password.") + connect_kwargs["user"] = conn_dict["user"] + connect_kwargs["password"] = conn_dict["password"] + + p = oracledb.create_pool(**connect_kwargs) + LOGGER.debug("Connection pool created successfully") return p