Skip to content

Commit 367e508

Browse files
Added attribute proxy_user on connections, as requested (#250).
1 parent 007c4c4 commit 367e508

File tree

8 files changed

+38
-0
lines changed

8 files changed

+38
-0
lines changed

doc/src/api_manual/connection.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -822,6 +822,15 @@ Connection Attributes
822822

823823
This attribute is an extension to the DB API definition.
824824

825+
.. attribute:: Connection.proxy_user
826+
827+
This read-only attribute returns the name of the user which was used as a
828+
proxy when creating the connection to the database.
829+
830+
.. note::
831+
832+
This attribute is an extension to the DB API definition.
833+
825834
.. attribute:: Connection.service_name
826835

827836
This read-only attribute specifies the Oracle Database service name

doc/src/release_notes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ Common Changes
4444
associated with columns that are being fetched. SQL domains and annotations
4545
require Oracle Database 23c. If using python-oracledb Thick mode, Oracle
4646
Client 23c is also required.
47+
#) Added attribute :data:`Connection.proxy_user` as requested
48+
(`issue 250 <https://github.com/oracle/python-oracledb/issues/250>`__).
4749
#) Added type :data:`~oracledb.DB_TYPE_XMLTYPE` to represent data of type
4850
``SYS.XMLTYPE`` in the database. Previously the value of
4951
:data:`FetchInfo.type_code` for data of this type was

src/oracledb/base_impl.pxd

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ cdef class BaseConnImpl:
237237
cdef:
238238
readonly str username
239239
readonly str dsn
240+
readonly str proxy_user
240241
public object inputtypehandler
241242
public object outputtypehandler
242243
public bint autocommit

src/oracledb/connection.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,14 @@ def prepare(self) -> bool:
656656
"""
657657
return self.tpc_prepare()
658658

659+
@property
660+
def proxy_user(self) -> Union[str, None]:
661+
"""
662+
Returns the name of the proxy user, if applicable.
663+
"""
664+
self._verify_connected()
665+
return self._impl.proxy_user
666+
659667
def queue(
660668
self,
661669
name: str,

src/oracledb/impl/base/connection.pyx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ cdef class BaseConnImpl:
3434
def __init__(self, str dsn, ConnectParamsImpl params):
3535
self.dsn = dsn
3636
self.username = params.user
37+
self.proxy_user = params.proxy_user
3738

3839
cdef object _check_value(self, DbType dbtype, BaseDbObjectTypeImpl objtype,
3940
object value, bint* is_ok):

tests/test_1100_connection.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,13 @@ def test_1142_db_domain(self):
827827
(db_domain,) = cursor.fetchone()
828828
self.assertEqual(conn.db_domain, db_domain)
829829

830+
def test_1143_proxy_user(self):
831+
"1143 - test connecting with a proxy user"
832+
proxy_user = test_env.get_proxy_user()
833+
conn = test_env.get_connection(proxy_user=proxy_user)
834+
self.assertEqual(conn.username, test_env.get_main_user())
835+
self.assertEqual(conn.proxy_user, proxy_user)
836+
830837

831838
if __name__ == "__main__":
832839
test_env.run_test_cases()

tests/test_2400_pool.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,8 @@ def test_2407_heterogeneous(self):
367367
conn.close()
368368
user_str = f"{test_env.get_main_user()}[{test_env.get_proxy_user()}]"
369369
conn = pool.acquire(user_str, test_env.get_main_password())
370+
self.assertEqual(conn.username, test_env.get_main_user())
371+
self.assertEqual(conn.proxy_user, test_env.get_proxy_user())
370372
self.__verify_connection(
371373
conn, test_env.get_proxy_user(), test_env.get_main_user()
372374
)

utils/templates/connection.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,14 @@ def prepare(self) -> bool:
654654
"""
655655
return self.tpc_prepare()
656656

657+
@property
658+
def proxy_user(self) -> Union[str, None]:
659+
"""
660+
Returns the name of the proxy user, if applicable.
661+
"""
662+
self._verify_connected()
663+
return self._impl.proxy_user
664+
657665
def queue(
658666
self,
659667
name: str,

0 commit comments

Comments
 (0)