Skip to content

Commit 1ae6aa0

Browse files
committed
Updated docs and samples for to separate privilege
1 parent 4b964d6 commit 1ae6aa0

17 files changed

+211
-42
lines changed

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ jobs:
88
fail-fast: true
99
matrix:
1010
os: [ ubuntu-latest ]
11-
python-version: ['3.9', '3.13']
11+
python-version: ['3.11', '3.12', '3.13']
1212

1313
steps:
1414
- name: Check out python-select-ai repository code

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ doc/drawio
1313
test.env
1414
test_19c.env
1515
pytest.env
16+
.venv3.10/
17+
.venv3.11/
18+
.venv3.9/
19+
sample_connect.py
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
.. _privileges:
2+
3+
Admin user should grant execute privilege to select ai database users
4+
on the packages ``DBMS_CLOUD``, ``DBMS_CLOUD_AI``, ``DBMS_CLOUD_AI_AGENT``
5+
and ``DBMS_CLOUD_PIPELINE``
6+
7+
.. note::
8+
9+
All sample scripts in this documentation read Oracle database connection
10+
details from the environment. Create a dotenv file ``.env``, export the
11+
the following environment variables and source it before running the
12+
scripts.
13+
14+
.. code-block:: sh
15+
16+
export SELECT_AI_ADMIN_USER=<db_admin>
17+
export SELECT_AI_ADMIN_PASSWORD=<db_admin_password>
18+
export SELECT_AI_USER=<select_ai_db_user>
19+
export SELECT_AI_PASSWORD=<select_ai_db_password>
20+
export SELECT_AI_DB_CONNECT_STRING=<db_connect_string>
21+
export TNS_ADMIN=<path/to/dir_containing_tnsnames.ora>
22+
23+
***************
24+
Grant privilege
25+
***************
26+
27+
Connect as admin and run the method
28+
``select_ai.grant_privileges(users=select_ai_user)`` to grant relevant select ai
29+
privileges to other users
30+
31+
32+
.. literalinclude:: ../../../samples/select_ai_grant_privilege.py
33+
:language: python
34+
:lines: 15-
35+
36+
output::
37+
38+
Granted privileges to: <select_ai_db_user>
39+
40+
41+
****************
42+
Revoke privilege
43+
****************
44+
45+
Similarly, to revoke use the method
46+
``select_ai.revoke_privileges(users=select_ai_user)``
47+
48+
49+
.. literalinclude:: ../../../samples/select_ai_revoke_privilege.py
50+
:language: python
51+
:lines: 15-
52+
53+
output::
54+
55+
Granted privileges to: <select_ai_db_user>

doc/source/user_guide/provider.rst

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -87,32 +87,15 @@ for the supported providers
8787
Enable AI service provider
8888
**************************
8989

90-
.. note::
91-
92-
All sample scripts in this documentation read Oracle database connection
93-
details from the environment. Create a dotenv file ``.env``, export the
94-
the following environment variables and source it before running the
95-
scripts.
96-
97-
.. code-block:: sh
98-
99-
export SELECT_AI_ADMIN_USER=<db_admin>
100-
export SELECT_AI_ADMIN_PASSWORD=<db_admin_password>
101-
export SELECT_AI_USER=<select_ai_db_user>
102-
export SELECT_AI_PASSWORD=<select_ai_db_password>
103-
export SELECT_AI_DB_CONNECT_STRING=<db_connect_string>
104-
export TNS_ADMIN=<path/to/dir_containing_tnsnames.ora>
105-
10690
Sync API
10791
++++++++
10892

109-
This method grants execute privilege on the packages
110-
``DBMS_CLOUD``, ``DBMS_CLOUD_AI`` and ``DBMS_CLOUD_PIPELINE``. It
111-
also enables the database user to invoke the AI(LLM) endpoint
93+
This method adds ACL allowing database users to invoke AI provider's
94+
HTTP endpoint
11295

11396
.. literalinclude:: ../../../samples/enable_ai_provider.py
11497
:language: python
115-
:lines: 15-
98+
:lines: 14-
11699

117100
output::
118101

@@ -136,6 +119,9 @@ output::
136119
Disable AI service provider
137120
***************************
138121

122+
This method removes ACL blocking database users to invoke AI provider's
123+
HTTP endpoint
124+
139125
Sync API
140126
++++++++
141127

samples/async/disable_ai_provider.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# -----------------------------------------------------------------------------
99
# async/disable_ai_provider.py
1010
#
11-
# Async API to disable AI provider for database users
11+
# Remove ACL to invoke AI provider's HTTP endpoint
1212
# -----------------------------------------------------------------------------
1313

1414
import asyncio
@@ -24,7 +24,7 @@
2424

2525
async def main():
2626
await select_ai.async_connect(user=admin_user, password=password, dsn=dsn)
27-
await select_ai.async_disable_provider(
27+
await select_ai.async_revoke_http_access(
2828
users=select_ai_user, provider_endpoint="*.openai.azure.com"
2929
)
3030
print("Disabled AI provider for user: ", select_ai_user)

samples/async/enable_ai_provider.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
# -----------------------------------------------------------------------------
99
# async/enable_ai_provider.py
1010
#
11-
# Async API to enable AI provider for database users
11+
# Add ACL to invoke AI provider's HTTP endpoint
1212
# -----------------------------------------------------------------------------
1313

1414
import asyncio
@@ -24,7 +24,7 @@
2424

2525
async def main():
2626
await select_ai.async_connect(user=admin_user, password=password, dsn=dsn)
27-
await select_ai.async_enable_provider(
27+
await select_ai.async_grant_http_access(
2828
users=select_ai_user, provider_endpoint="*.openai.azure.com"
2929
)
3030
print("Enabled AI provider for user: ", select_ai_user)
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# -----------------------------------------------------------------------------
2+
# Copyright (c) 2025, Oracle and/or its affiliates.
3+
#
4+
# Licensed under the Universal Permissive License v 1.0 as shown at
5+
# http://oss.oracle.com/licenses/upl.
6+
# -----------------------------------------------------------------------------
7+
8+
# -----------------------------------------------------------------------------
9+
# async/select_ai_grant_privilege.py
10+
#
11+
# Grant execute privileges on DBMS_CLOUD, DMBS_CLOUD_AI, DBMS_CLOUD_AI_AGENT
12+
# and DBMS_CLOUD_PIPELINE PL/SQL packages
13+
# -----------------------------------------------------------------------------
14+
15+
import asyncio
16+
import os
17+
18+
import select_ai
19+
20+
admin_user = os.getenv("SELECT_AI_ADMIN_USER")
21+
password = os.getenv("SELECT_AI_ADMIN_PASSWORD")
22+
dsn = os.getenv("SELECT_AI_DB_CONNECT_STRING")
23+
select_ai_user = os.getenv("SELECT_AI_USER")
24+
25+
26+
async def main():
27+
await select_ai.async_connect(user=admin_user, password=password, dsn=dsn)
28+
await select_ai.async_grant_privileges(
29+
users=select_ai_user,
30+
)
31+
print("Granted privileges to: ", select_ai_user)
32+
33+
34+
asyncio.run(main())
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# -----------------------------------------------------------------------------
2+
# Copyright (c) 2025, Oracle and/or its affiliates.
3+
#
4+
# Licensed under the Universal Permissive License v 1.0 as shown at
5+
# http://oss.oracle.com/licenses/upl.
6+
# -----------------------------------------------------------------------------
7+
8+
# -----------------------------------------------------------------------------
9+
# async/select_ai_revoke_privilege.py
10+
#
11+
# Revoke execute privileges on DBMS_CLOUD, DMBS_CLOUD_AI, DBMS_CLOUD_AI_AGENT
12+
# and DBMS_CLOUD_PIPELINE PL/SQL packages
13+
# -----------------------------------------------------------------------------
14+
15+
import asyncio
16+
import os
17+
18+
import select_ai
19+
20+
admin_user = os.getenv("SELECT_AI_ADMIN_USER")
21+
password = os.getenv("SELECT_AI_ADMIN_PASSWORD")
22+
dsn = os.getenv("SELECT_AI_DB_CONNECT_STRING")
23+
select_ai_user = os.getenv("SELECT_AI_USER")
24+
25+
26+
async def main():
27+
await select_ai.async_connect(user=admin_user, password=password, dsn=dsn)
28+
await select_ai.async_revoke_privileges(
29+
users=select_ai_user,
30+
)
31+
print("Revoked privileges from: ", select_ai_user)
32+
33+
34+
asyncio.run(main())

samples/disable_ai_provider.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
# -----------------------------------------------------------------------------
99
# disable_ai_provider.py
1010
#
11-
# Revokes privileges from the database user and removes ACL to invoke the AI
12-
# Provider endpoint
11+
# Removes ACL to invoke the AI Provider's HTTP endpoint
1312
# -----------------------------------------------------------------------------
13+
1414
import os
1515

1616
import select_ai
@@ -21,7 +21,7 @@
2121
select_ai_user = os.getenv("SELECT_AI_USER")
2222

2323
select_ai.connect(user=admin_user, password=password, dsn=dsn)
24-
select_ai.disable_provider(
24+
select_ai.revoke_http_access(
2525
users=select_ai_user, provider_endpoint="*.openai.azure.com"
2626
)
2727
print("Disabled AI provider for user: ", select_ai_user)

samples/enable_ai_provider.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
# -----------------------------------------------------------------------------
99
# enable_ai_provider.py
1010
#
11-
# Grants privileges to the database user and add ACL to invoke the AI Provider
12-
# endpoint
11+
# Adds ACL to invoke the AI Provider's HTTP endpoint
1312
# -----------------------------------------------------------------------------
1413

1514
import os
@@ -22,7 +21,7 @@
2221
select_ai_user = os.getenv("SELECT_AI_USER")
2322

2423
select_ai.connect(user=admin_user, password=password, dsn=dsn)
25-
select_ai.enable_provider(
24+
select_ai.grant_http_access(
2625
users=select_ai_user, provider_endpoint="api.OPENAI.com"
2726
)
2827
print("Enabled AI provider for user: ", select_ai_user)

0 commit comments

Comments
 (0)