From 62fcc8e81574adcc69be1a4a03a0e5ab4831687d Mon Sep 17 00:00:00 2001 From: David Kegley Date: Thu, 22 Feb 2024 16:33:16 -0500 Subject: [PATCH] Add sample content from Connect external review demo --- connect-content/.posit/publish/default.toml | 10 ++++ .../bd37754b-a24d-4a9a-b787-de16c2357726.toml | 20 +++++++ .../d307564a-d2ff-4101-9e16-7dfdcd86517d.toml | 20 +++++++ .../publish/deployments/databricks.toml | 20 +++++++ .../edb61425-1551-4285-9f34-4813313e825f.toml | 20 +++++++ connect-content/README.md | 23 ++++++++ connect-content/requirements.txt | 56 +++++++++++++++++++ connect-content/sample-content.py | 46 +++++++++++++++ 8 files changed, 215 insertions(+) create mode 100644 connect-content/.posit/publish/default.toml create mode 100644 connect-content/.posit/publish/deployments/bd37754b-a24d-4a9a-b787-de16c2357726.toml create mode 100644 connect-content/.posit/publish/deployments/d307564a-d2ff-4101-9e16-7dfdcd86517d.toml create mode 100644 connect-content/.posit/publish/deployments/databricks.toml create mode 100644 connect-content/.posit/publish/deployments/edb61425-1551-4285-9f34-4813313e825f.toml create mode 100644 connect-content/README.md create mode 100644 connect-content/requirements.txt create mode 100644 connect-content/sample-content.py diff --git a/connect-content/.posit/publish/default.toml b/connect-content/.posit/publish/default.toml new file mode 100644 index 00000000..e90ff57c --- /dev/null +++ b/connect-content/.posit/publish/default.toml @@ -0,0 +1,10 @@ +'$schema' = 'https://cdn.posit.co/publisher/schemas/posit-publishing-schema-v3.json' +type = 'python-streamlit' +entrypoint = 'sample-content.py' +validate = true +title = 'Databricks Viewer App' + +[python] +version = '3.11.3' +package-file = 'requirements.txt' +package-manager = 'pip' diff --git a/connect-content/.posit/publish/deployments/bd37754b-a24d-4a9a-b787-de16c2357726.toml b/connect-content/.posit/publish/deployments/bd37754b-a24d-4a9a-b787-de16c2357726.toml new file mode 100644 index 00000000..7982b345 --- /dev/null +++ b/connect-content/.posit/publish/deployments/bd37754b-a24d-4a9a-b787-de16c2357726.toml @@ -0,0 +1,20 @@ +'$schema' = 'https://cdn.posit.co/publisher/schemas/posit-publishing-record-schema-v3.json' +server-type = 'connect' +server-url = 'http://localhost:3939' +client-version = '1.0.alpha1' +id = 'bd37754b-a24d-4a9a-b787-de16c2357726' +configuration-name = 'default' +files = ['.env', '.posit/publish/default.toml', '.posit/publish/deployments/d307564a-d2ff-4101-9e16-7dfdcd86517d.toml', '.python-version', 'requirements.txt', 'sample-content.py'] +deployed-at = '2024-02-21T20:06:53Z' + +[configuration] +'$schema' = 'https://cdn.posit.co/publisher/schemas/posit-publishing-schema-v3.json' +type = 'python-streamlit' +entrypoint = 'sample-content.py' +validate = true +title = 'connect-content' + +[configuration.python] +version = '3.11.3' +package-file = 'requirements.txt' +package-manager = 'pip' diff --git a/connect-content/.posit/publish/deployments/d307564a-d2ff-4101-9e16-7dfdcd86517d.toml b/connect-content/.posit/publish/deployments/d307564a-d2ff-4101-9e16-7dfdcd86517d.toml new file mode 100644 index 00000000..0aa80454 --- /dev/null +++ b/connect-content/.posit/publish/deployments/d307564a-d2ff-4101-9e16-7dfdcd86517d.toml @@ -0,0 +1,20 @@ +'$schema' = 'https://cdn.posit.co/publisher/schemas/posit-publishing-record-schema-v3.json' +server-type = 'connect' +server-url = 'http://localhost:3939' +client-version = '1.0.alpha1' +id = 'd307564a-d2ff-4101-9e16-7dfdcd86517d' +configuration-name = 'default' +files = ['.env', '.posit/publish/default.toml', '.python-version', 'requirements.txt', 'sample-content.py'] +deployed-at = '2024-02-21T19:45:20Z' + +[configuration] +'$schema' = 'https://cdn.posit.co/publisher/schemas/posit-publishing-schema-v3.json' +type = 'python-streamlit' +entrypoint = 'sample-content.py' +validate = true +title = 'connect-content' + +[configuration.python] +version = '3.11.3' +package-file = 'requirements.txt' +package-manager = 'pip' diff --git a/connect-content/.posit/publish/deployments/databricks.toml b/connect-content/.posit/publish/deployments/databricks.toml new file mode 100644 index 00000000..73500dec --- /dev/null +++ b/connect-content/.posit/publish/deployments/databricks.toml @@ -0,0 +1,20 @@ +'$schema' = 'https://cdn.posit.co/publisher/schemas/posit-publishing-record-schema-v3.json' +server-type = 'connect' +server-url = 'http://localhost:3939' +client-version = '1.0.alpha1' +id = '324f7003-1c22-452d-8ae5-72e0ad575de6' +configuration-name = 'default' +files = ['.env', '.posit/publish/default.toml', '.posit/publish/deployments/bd37754b-a24d-4a9a-b787-de16c2357726.toml', '.posit/publish/deployments/d307564a-d2ff-4101-9e16-7dfdcd86517d.toml', '.posit/publish/deployments/databricks.toml', '.posit/publish/deployments/edb61425-1551-4285-9f34-4813313e825f.toml', '.python-version', 'README.md', 'requirements.txt', 'sample-content.py'] +deployed-at = '2024-02-22T17:36:17Z' + +[configuration] +'$schema' = 'https://cdn.posit.co/publisher/schemas/posit-publishing-schema-v3.json' +type = 'python-streamlit' +entrypoint = 'sample-content.py' +validate = true +title = 'Databricks Viewer App' + +[configuration.python] +version = '3.11.3' +package-file = 'requirements.txt' +package-manager = 'pip' diff --git a/connect-content/.posit/publish/deployments/edb61425-1551-4285-9f34-4813313e825f.toml b/connect-content/.posit/publish/deployments/edb61425-1551-4285-9f34-4813313e825f.toml new file mode 100644 index 00000000..9dd86d49 --- /dev/null +++ b/connect-content/.posit/publish/deployments/edb61425-1551-4285-9f34-4813313e825f.toml @@ -0,0 +1,20 @@ +'$schema' = 'https://cdn.posit.co/publisher/schemas/posit-publishing-record-schema-v3.json' +server-type = 'connect' +server-url = 'http://localhost:3939' +client-version = '1.0.alpha1' +id = 'edb61425-1551-4285-9f34-4813313e825f' +configuration-name = 'default' +files = ['.env', '.posit/publish/default.toml', '.posit/publish/deployments/bd37754b-a24d-4a9a-b787-de16c2357726.toml', '.posit/publish/deployments/d307564a-d2ff-4101-9e16-7dfdcd86517d.toml', '.python-version', 'requirements.txt', 'sample-content.py'] +deployed-at = '2024-02-21T20:19:23Z' + +[configuration] +'$schema' = 'https://cdn.posit.co/publisher/schemas/posit-publishing-schema-v3.json' +type = 'python-streamlit' +entrypoint = 'sample-content.py' +validate = true +title = 'Databricks Viewer App' + +[configuration.python] +version = '3.11.3' +package-file = 'requirements.txt' +package-manager = 'pip' diff --git a/connect-content/README.md b/connect-content/README.md new file mode 100644 index 00000000..dba5a10b --- /dev/null +++ b/connect-content/README.md @@ -0,0 +1,23 @@ +```bash +# start streamlit locally +DATABRICKS_TOKEN= \ +CONNECT_SERVER=http://localhost:3939/__api__ \ +CONNECT_API_KEY=$CONNECT_INSECURE_ADMIN_API_KEY \ +streamlit run ./sample-content.py + + +# deploy the app the first time +publisher deploy -a localhost:3939 -n databricks ./ + +# re-deploy the databricks app +publisher redeploy databricks +``` + + +TODO: Test this content with databricks-connect + + +``` +# install the sdk from this branch +pip install git+https://github.com/posit-dev/posit-sdk-py.git@kegs/databricks-oauth +``` diff --git a/connect-content/requirements.txt b/connect-content/requirements.txt new file mode 100644 index 00000000..41b2b241 --- /dev/null +++ b/connect-content/requirements.txt @@ -0,0 +1,56 @@ +altair==5.2.0 +attrs==23.2.0 +blinker==1.7.0 +cachetools==5.3.2 +certifi==2024.2.2 +charset-normalizer==3.3.2 +click==8.1.7 +databricks-sdk==0.20.0 +databricks-sql-connector==3.1.0 +et-xmlfile==1.1.0 +gitdb==4.0.11 +GitPython==3.1.42 +google-auth==2.28.0 +idna==3.6 +importlib-metadata==7.0.1 +Jinja2==3.1.3 +jsonschema==4.21.1 +jsonschema-specifications==2023.12.1 +lz4==4.3.3 +markdown-it-py==3.0.0 +MarkupSafe==2.1.5 +mdurl==0.1.2 +numpy==1.26.4 +oauthlib==3.2.2 +openpyxl==3.1.2 +packaging==23.2 +pandas==2.1.4 +pillow==10.2.0 +posit-sdk @ git+https://github.com/posit-dev/posit-sdk-py.git@56b1bd330e7ca76c8ca81b4854e99898fe9bd857 +protobuf==4.25.3 +pyarrow==14.0.2 +pyasn1==0.5.1 +pyasn1-modules==0.3.0 +pydeck==0.8.1b0 +Pygments==2.17.2 +python-dateutil==2.8.2 +pytz==2024.1 +referencing==0.33.0 +requests==2.31.0 +rich==13.7.0 +rpds-py==0.18.0 +rsa==4.9 +six==1.16.0 +smmap==5.0.1 +streamlit==1.31.1 +tenacity==8.2.3 +thrift==0.16.0 +toml==0.10.2 +toolz==0.12.1 +tornado==6.4 +typing_extensions==4.9.0 +tzdata==2024.1 +tzlocal==5.2 +urllib3==2.2.1 +validators==0.22.0 +zipp==3.17.0 diff --git a/connect-content/sample-content.py b/connect-content/sample-content.py new file mode 100644 index 00000000..e2bbc6af --- /dev/null +++ b/connect-content/sample-content.py @@ -0,0 +1,46 @@ +import os + +from posit.connect.client import Client +from posit.connect.external.databricks import viewer_credentials_provider + +from databricks import sql +from databricks.sdk.service.iam import CurrentUserAPI +from databricks.sdk.core import ApiClient, Config + +import pandas as pd +import streamlit as st +from streamlit.web.server.websocket_headers import _get_websocket_headers + +DB_PAT=os.getenv("DATABRICKS_TOKEN") + +DB_HOST="adb-138962681435081.1.azuredatabricks.net" +DB_HOST_URL = f"https://{DB_HOST}" +SQL_HTTP_PATH="/sql/1.0/warehouses/684d08139179d1dd" + +CONTENT_IDENTITY = None + +# Read the viewer's individual content identity token from the streamlit ws header. +headers = _get_websocket_headers() +if headers: + CONTENT_IDENTITY = headers.get('Posit-Connect-Content-Identity') + +with Client() as connect_client: + credentials_provider = viewer_credentials_provider( + connect_client.oauth, content_identity=CONTENT_IDENTITY) + cfg = Config(host=DB_HOST_URL, credentials_provider=credentials_provider) + #cfg = Config(host=DB_HOST_URL, token=DB_PAT) + + databricks_user = CurrentUserAPI(ApiClient(cfg)).me() + st.write(f"Hello, {databricks_user.display_name}!") + + with sql.connect( + server_hostname=DB_HOST, + http_path=SQL_HTTP_PATH, + #access_token=DB_PAT) as connection: + auth_type='databricks-oauth', + credentials_provider=credentials_provider) as connection: + with connection.cursor() as cursor: + cursor.execute("SELECT * FROM catalog_zverham.example_schema_zverham.example_data_zverham") + result = cursor.fetchall() + st.table(pd.DataFrame(result)) +