@@ -619,7 +619,7 @@ returned::
619
619
If :attr: `~ConnectParams.config_dir ` is not specified, then the following
620
620
error is returned::
621
621
622
- DPY-4027: no configuration directory to search for tnsnames.ora
622
+ DPY-4027: no configuration directory specified
623
623
624
624
When creating a standalone connection or connection pool the equivalent
625
625
internal extraction is done automatically when a value is passed to the ``dsn ``
@@ -911,6 +911,46 @@ modes, your connection code can be like:
911
911
cp.parse_connect_string(dsn)
912
912
connection = oracledb.connect(user = " hr" , password = userpwd, params = cp)
913
913
914
+ .. _registerpasswordtype :
915
+
916
+ Using oracledb.register_password_type()
917
+ ---------------------------------------
918
+
919
+ The :meth: `oracledb.register_password_type() ` method registers a user hook
920
+ function that will be called internally by python-oracledb prior to connection
921
+ or pool creation by :meth: `oracledb.connect() `, :meth: `oracledb.create_pool() `,
922
+ :meth: `oracledb.connect_async() `, or :meth: `oracledb.create_pool_async() `. If
923
+ the ``password ``, ``newpassword ``, or ``wallet_password `` parameters to those
924
+ methods are a dictionary containing the key "type", then the registered user
925
+ hook function will be invoked. Your hook function is expected to accept the
926
+ dictionary and return the actual password string.
927
+
928
+ Below is an example of a hook function that handles passwords of type base64.
929
+ Note this specific hook function is already included and registered in
930
+ python-oracledb:
931
+
932
+ .. code-block :: python
933
+
934
+ def mypasswordhook (args ):
935
+ return base64.b64decode(args[" value" ].encode()).decode()
936
+
937
+ oracledb.register_password_type(" base64" , mypasswordhook)
938
+
939
+ When :meth: `oracledb.connect() ` is called as shown below, the sample hook is
940
+ invoked internally. It decodes the base64-encoded string in the key "value" and
941
+ returns the password which is then used by python-oracledb to establish a
942
+ connection to the database:
943
+
944
+ .. code-block :: python
945
+
946
+ connection = oracledb.connect(user = " scott" ,
947
+ password = dict (type = " base64" , value = " dGlnZXI=" ),
948
+ dsn = " localhost/orclpdb" )
949
+
950
+ Calling :meth: `~oracledb.register_password_type() ` with the
951
+ ``hook_function `` parameter set to None will result in a previously
952
+ registered user function being removed and the default behavior restored.
953
+
914
954
.. _ldapconnections :
915
955
916
956
LDAP Directory Naming
@@ -3991,6 +4031,124 @@ typically the same directory where the ``wallet.zip`` file was extracted.
3991
4031
23ai. They contain important bug fixes for using multiple wallets in
3992
4032
the one process.
3993
4033
4034
+ .. _builtinconfigproviders :
4035
+
4036
+ Connecting Using the File Centralized Configuration Provider
4037
+ ============================================================
4038
+
4039
+ The file configuration provider enables the storage and management of Oracle
4040
+ Database connection information in a JSON file on your local file system. You
4041
+ must add the connect descriptor in the file. Optionally, you can add the
4042
+ database user name, password, and python-oracledb specific properties in the
4043
+ file. The sub-objects that can be added to the JSON file are listed in the
4044
+ table below.
4045
+
4046
+ .. list-table-with-summary :: Sub-objects for JSON File in File Configuration Provider
4047
+ :header-rows: 1
4048
+ :class: wy-table-responsive
4049
+ :widths: 20 60
4050
+ :name: _file_configuration_provider
4051
+ :summary: The first column displays the name of the sub-object. The second column displays the description of the sub-object.
4052
+
4053
+ * - Sub-object
4054
+ - Description
4055
+ * - ``user ``
4056
+ - The database user name.
4057
+ * - ``password ``
4058
+ - The password of the database user or a dictionary containing "type" and password type specific properties.
4059
+ * - ``connect_descriptor ``
4060
+ - The :ref: `connect descriptor <conndescriptor >` value.
4061
+ * - ``pyo ``
4062
+ - The python-oracledb specific attributes.
4063
+
4064
+ See `Oracle Net Service Administrator’s Guide <https://www.oracle.com/pls/
4065
+ topic/lookup?ctx=dblatest&id=GUID-B43EA22D-5593-40B3-87FC-C70D6DAF780E> `__ for
4066
+ more information on these sub-objects.
4067
+
4068
+ The following sample is an example of the configuration information defined in
4069
+ a JSON file that is stored in a local file system::
4070
+
4071
+ {
4072
+ "user": "scott",
4073
+ "password": {
4074
+ "type": "base64",
4075
+ "value": "dGlnZXI="
4076
+ },
4077
+ "connect_descriptor": "dbhost.example.com:1522/orclpdb",
4078
+ "pyo": {
4079
+ "stmtcachesize": 30,
4080
+ "min": 2,
4081
+ "max": 10
4082
+ }
4083
+ }
4084
+
4085
+ .. _multipleconfigurations :
4086
+
4087
+ Multiple configurations can be defined in a JSON file by using keys as
4088
+ shown in the example below::
4089
+
4090
+ {
4091
+ "key1": {
4092
+ "connect_descriptor": "localhost/orclpdb"
4093
+ },
4094
+ "key2": {
4095
+ "connect_descriptor": "localhost/orclpdb",
4096
+ "user": "scott",
4097
+ "password": {
4098
+ "type": "base64",
4099
+ "value": "dGlnZXI="
4100
+ }
4101
+ }
4102
+ }
4103
+
4104
+ You can use python-oracledb to access the configuration information stored in
4105
+ a JSON file on your local file system. For this, you must specify the
4106
+ connection string URL in the ``dsn `` parameter of :meth: `oracledb.connect() `,
4107
+ :meth: `oracledb.create_pool() `, :meth: `oracledb.connect_async() `, or
4108
+ :meth: `oracledb.create_pool_async() ` in the following format::
4109
+
4110
+ config-file://<file-name>?key=<key>
4111
+
4112
+ The parameters of the connection string are detailed in the table below.
4113
+
4114
+ .. list-table-with-summary :: Connection String Parameters for File Configuration Provider
4115
+ :header-rows: 1
4116
+ :class: wy-table-responsive
4117
+ :widths: 20 60
4118
+ :name: _connection_string_for_file_configuration_provider
4119
+ :summary: The first column displays the name of the connection string parameter. The second column displays the description of the connection string parameter.
4120
+
4121
+ * - Parameter
4122
+ - Description
4123
+ * - ``config-file ``
4124
+ - Indicates that the centralized configuration provider is a file in your local system.
4125
+ * - <file-name>
4126
+ - The file path (absolute or relative path) and name of the JSON file that contains the configuration information. For relative paths, python-oracledb will use the ``config_dir `` value to create an absolute path.
4127
+ * - ``key ``
4128
+ - The connection key name used to identify a specific configuration. If this parameter is specified, the file is assumed to contain multiple configurations that are indexed by the key. If not specified, the file is assumed to contain a single configuration.
4129
+
4130
+ For example, to access the "myfile.json" JSON file and the "key2" configuration
4131
+ from the :ref: `multiple configurations sample <multipleconfigurations >` shown
4132
+ above:
4133
+
4134
+ .. code-block :: python
4135
+
4136
+ configfileurl = " config-file://myfile.json?key=key2"
4137
+ oracledb.connect(dsn = configfileurl)
4138
+
4139
+ When :meth: `oracledb.connect() ` is called, the built-in hook function to handle
4140
+ connection strings prefixed with ``config-file:// `` is
4141
+ internally invoked. This hook function parses the connection string and
4142
+ extracts the name of the JSON file containing the configuration information
4143
+ and the connection key name that is stored in your local file system. Using
4144
+ these details, this hook function accesses the configuration information
4145
+ stored in the JSON file. The hook function sets the connection information
4146
+ from the JSON file in its ``connect_params `` parameter. This ConnectParams
4147
+ object is used by python-oracledb to establish a connection to Oracle
4148
+ Database.
4149
+
4150
+ Note that when using the password type handler for "base64", a warning will be
4151
+ generated: "base64 encoded passwords are insecure".
3994
4152
3995
4153
.. _connsharding :
3996
4154
0 commit comments