Skip to content

Commit

Permalink
vdk-oracle: support thick mode by default (#2970)
Browse files Browse the repository at this point in the history
## Why?

Internal deployments use thick mode and have the oracle driver bundled
in their docker image.

## What?

Add a config option for thick mode and set the default to True

## How was this tested?

Ran code connection against a version 10c database, which requires thick
mode
CI

## What kind of change is this?

Feature/non-breaking

Signed-off-by: Dilyan Marinov <[email protected]>
  • Loading branch information
DeltaMichael authored Dec 14, 2023
1 parent 1d2bfba commit 356879d
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 9 deletions.
17 changes: 9 additions & 8 deletions projects/vdk-plugins/vdk-oracle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ pip install vdk-oracle

(`vdk config-help` is useful command to browse all config options of your installation of vdk)

| Name | Description | (example) Value |
| ------------------------ | -------------------------------------------------------------- | --------------------- |
| oracle_user | Username used when connecting to Oracle database | "my_user" |
| oracle_password | Password used when connecting to Oracle database | "super_secret_shhhh" |
| oracle_user_secret | The user name secret key if using secrets to connect to Oracle | "user_secret_key" |
| oracle_password_secret | The password secret key if using secrets to connect to Oracle | "password_secret_key" |
| oracle_use_secrets | Set to True to use secrets to connect to Oracle | "True" |
| oracle_connection_string | The Oracle connection string | "localhost:1521/free" |
| Name | Description | (example) Value |
|--------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------|
| oracle_user | Username used when connecting to Oracle database | my_user |
| oracle_password | Password used when connecting to Oracle database | super_secret_shhhh |
| oracle_user_secret | The user name secret key if using secrets to connect to Oracle | user_secret_key |
| oracle_password_secret | The password secret key if using secrets to connect to Oracle | password_secret_key |
| oracle_use_secrets | Set to True to use secrets to connect to Oracle | True |
| oracle_connection_string | The Oracle connection string | localhost:1521/free |
| oracle_thick_mode | Python-oracledb is said to be in Thick mode when Oracle Client libraries are used. True by default. Set to False to disable Oracle Thick mode. More info: https://python-oracledb.readthedocs.io/en/latest/user_guide/appendix_b.html | True |

### Example

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
ORACLE_USER = "ORACLE_USER"
ORACLE_PASSWORD = "ORACLE_PASSWORD"
ORACLE_USE_SECRETS = "ORACLE_USE_SECRETS"
ORACLE_THICK_MODE = "ORACLE_THICK_MODE"
ORACLE_USER_SECRET = "ORACLE_USER_SECRET"
ORACLE_PASSWORD_SECRET = "ORACLE_PASSWORD_SECRET"
ORACLE_CONNECTION_STRING = "ORACLE_CONNECTION_STRING"
Expand Down Expand Up @@ -39,6 +40,9 @@ def get_oracle_connection_string(self) -> str:
def oracle_use_secrets(self) -> bool:
return self.__config.get_value(ORACLE_USE_SECRETS)

def oracle_thick_mode(self) -> bool:
return self.__config.get_value(ORACLE_THICK_MODE)

@staticmethod
def add_definitions(config_builder: ConfigurationBuilder):
config_builder.add(
Expand Down Expand Up @@ -74,3 +78,8 @@ def add_definitions(config_builder: ConfigurationBuilder):
default_value=None,
description="The password secret key if using secrets to connect to Oracle",
)
config_builder.add(
key=ORACLE_THICK_MODE,
default_value=True,
description="Use oracle thick mode, default is True. Set to False to disable oracle thick mode. More info: https://python-oracledb.readthedocs.io/en/latest/user_guide/appendix_b.html",
)
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@


class OracleConnection(ManagedConnectionBase):
def __init__(self, user: str, password: str, connection_string: str):
def __init__(
self, user: str, password: str, connection_string: str, thick_mode: bool = True
):
super().__init__(log)
self._oracle_user = user
self._oracle_password = password
self._oracle_connection_string = connection_string
self._thick_mode = thick_mode

def _connect(self) -> PEP249Connection:
import oracledb

if self._thick_mode:
oracledb.init_oracle_client()
conn = oracledb.connect(
user=self._oracle_user,
password=self._oracle_password,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def initialize_job(self, context: JobContext):
oracle_user,
oracle_pass,
conf.get_oracle_connection_string(),
conf.oracle_thick_mode(),
),
)
context.ingester.add_ingester_factory_method(
Expand Down
2 changes: 2 additions & 0 deletions projects/vdk-plugins/vdk-oracle/tests/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
ORACLE_USER = "ORACLE_USER"
ORACLE_PASSWORD = "ORACLE_PASSWORD"
ORACLE_CONNECTION_STRING = "ORACLE_CONNECTION_STRING"
ORACLE_THICK_MODE = "ORACLE_THICK_MODE"
VDK_LOG_EXECUTION_RESULT = "VDK_LOG_EXECUTION_RESULT"
VDK_INGEST_METHOD_DEFAULT = "VDK_INGEST_METHOD_DEFAULT"

Expand All @@ -27,6 +28,7 @@
ORACLE_USER: "SYSTEM",
ORACLE_PASSWORD: "Gr0mh3llscr3am",
ORACLE_CONNECTION_STRING: "localhost:1521/FREE",
ORACLE_THICK_MODE: "False",
VDK_LOG_EXECUTION_RESULT: "True",
VDK_INGEST_METHOD_DEFAULT: "ORACLE",
},
Expand Down
4 changes: 4 additions & 0 deletions projects/vdk-plugins/vdk-oracle/tests/test_secrets_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ def test_oracle_secrets_sql_only(httpserver: PluginHTTPServer):
"VDK_ORACLE_USE_SECRETS": "True",
"VDK_ORACLE_CONNECTION_STRING": "localhost:1521/FREE",
"VDK_LOG_EXECUTION_RESULT": "True",
"VDK_ORACLE_THICK_MODE": "False",
"VDK_INGEST_METHOD_DEFAULT": "ORACLE",
"DB_DEFAULT_TYPE": "oracle",
},
Expand All @@ -57,6 +58,7 @@ def test_oracle_secrets_sql_only(httpserver: PluginHTTPServer):
"VDK_ORACLE_CONNECTION_STRING": "localhost:1521/FREE",
"VDK_LOG_EXECUTION_RESULT": "True",
"VDK_INGEST_METHOD_DEFAULT": "ORACLE",
"VDK_ORACLE_THICK_MODE": "False",
"DB_DEFAULT_TYPE": "oracle",
},
):
Expand Down Expand Up @@ -85,6 +87,7 @@ def test_oracle_secrets_ingest_job(httpserver: PluginHTTPServer):
"VDK_ORACLE_CONNECTION_STRING": "localhost:1521/FREE",
"VDK_LOG_EXECUTION_RESULT": "True",
"VDK_INGEST_METHOD_DEFAULT": "ORACLE",
"VDK_ORACLE_THICK_MODE": "False",
"DB_DEFAULT_TYPE": "oracle",
},
):
Expand All @@ -104,6 +107,7 @@ def test_oracle_secrets_ingest_job(httpserver: PluginHTTPServer):
"VDK_ORACLE_CONNECTION_STRING": "localhost:1521/FREE",
"VDK_LOG_EXECUTION_RESULT": "True",
"VDK_INGEST_METHOD_DEFAULT": "ORACLE",
"VDK_ORACLE_THICK_MODE": "False",
"DB_DEFAULT_TYPE": "oracle",
},
):
Expand Down

0 comments on commit 356879d

Please sign in to comment.