-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add external access support in streamlit (#1439)
- Loading branch information
1 parent
903b2b1
commit a7fdf08
Showing
16 changed files
with
193 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
from pathlib import Path | ||
from textwrap import dedent | ||
from unittest import mock | ||
from unittest.mock import MagicMock | ||
|
||
from snowflake.cli._plugins.streamlit.manager import StreamlitManager | ||
from snowflake.cli.api.project.schemas.entities.streamlit_entity_model import ( | ||
StreamlitEntityModel, | ||
) | ||
|
||
|
||
@mock.patch("snowflake.cli._plugins.streamlit.manager.StageManager") | ||
@mock.patch("snowflake.cli._plugins.streamlit.manager.StreamlitManager.get_url") | ||
@mock.patch("snowflake.cli._plugins.streamlit.manager.StreamlitManager._execute_query") | ||
def test_deploy_streamlit(mock_execute_query, _, mock_stage_manager, temp_dir): | ||
mock_stage_manager().get_standard_stage_prefix.return_value = "stage_root" | ||
|
||
main_file = Path(temp_dir) / "main.py" | ||
main_file.touch() | ||
|
||
st = StreamlitEntityModel( | ||
type="streamlit", | ||
identifier="my_streamlit_app", | ||
title="MyStreamlit", | ||
query_warehouse="My_WH", | ||
main_file=str(main_file), | ||
# Possibly can be PathMapping | ||
artifacts=[main_file], | ||
) | ||
|
||
StreamlitManager(MagicMock(database="DB", schema="SH")).deploy( | ||
streamlit=st, replace=False | ||
) | ||
|
||
mock_execute_query.assert_called_once_with( | ||
dedent( | ||
f"""\ | ||
CREATE STREAMLIT IDENTIFIER('DB.SH.my_streamlit_app') | ||
ROOT_LOCATION = 'stage_root' | ||
MAIN_FILE = '{main_file}' | ||
QUERY_WAREHOUSE = My_WH | ||
TITLE = 'MyStreamlit'""" | ||
) | ||
) | ||
|
||
|
||
@mock.patch("snowflake.cli._plugins.streamlit.manager.StageManager") | ||
@mock.patch("snowflake.cli._plugins.streamlit.manager.StreamlitManager.get_url") | ||
@mock.patch("snowflake.cli._plugins.streamlit.manager.StreamlitManager._execute_query") | ||
def test_deploy_streamlit_with_api_integrations( | ||
mock_execute_query, _, mock_stage_manager, temp_dir | ||
): | ||
mock_stage_manager().get_standard_stage_prefix.return_value = "stage_root" | ||
|
||
main_file = Path(temp_dir) / "main.py" | ||
main_file.touch() | ||
|
||
st = StreamlitEntityModel( | ||
type="streamlit", | ||
identifier="my_streamlit_app", | ||
title="MyStreamlit", | ||
query_warehouse="My_WH", | ||
main_file=str(main_file), | ||
# Possibly can be PathMapping | ||
artifacts=[main_file], | ||
external_access_integrations=["MY_INTERGATION", "OTHER"], | ||
secrets={"my_secret": "SecretOfTheSecrets", "other": "other_secret"}, | ||
) | ||
|
||
StreamlitManager(MagicMock(database="DB", schema="SH")).deploy( | ||
streamlit=st, replace=False | ||
) | ||
|
||
mock_execute_query.assert_called_once_with( | ||
dedent( | ||
f"""\ | ||
CREATE STREAMLIT IDENTIFIER('DB.SH.my_streamlit_app') | ||
ROOT_LOCATION = 'stage_root' | ||
MAIN_FILE = '{main_file}' | ||
QUERY_WAREHOUSE = My_WH | ||
TITLE = 'MyStreamlit' | ||
external_access_integrations=(MY_INTERGATION, OTHER) | ||
secrets = ('my_secret' = SecretOfTheSecrets, 'other' = other_secret)""" | ||
) | ||
) |
5 changes: 0 additions & 5 deletions
5
tests_integration/test_data/projects/streamlit_v2/environment.yml
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
tests_integration/test_data/projects/streamlit_v2/pages/my_page.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,3 @@ entities: | |
main_file: streamlit_app.py | ||
artifacts: | ||
- streamlit_app.py | ||
- utils/utils.py | ||
- pages/ | ||
- environment.yml |
4 changes: 2 additions & 2 deletions
4
tests_integration/test_data/projects/streamlit_v2/streamlit_app.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import streamlit as st | ||
from utils.utils import hello | ||
|
||
st.title(f"Example streamlit app. {hello()}") | ||
|
||
st.title(f"Example streamlit app.") |
2 changes: 0 additions & 2 deletions
2
tests_integration/test_data/projects/streamlit_v2/utils/utils.py
This file was deleted.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
tests_integration/test_data/projects/streamlit_v2_external_access/snowflake.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
definition_version: 2 | ||
entities: | ||
my_streamlit: | ||
type: "streamlit" | ||
identifier: | ||
name: test_streamlit_deploy_snowcli_ext_access | ||
title: "My Fancy Streamlit" | ||
stage: streamlit | ||
query_warehouse: xsmall | ||
main_file: streamlit_app.py | ||
external_access_integrations: | ||
- snowflake_docs_access_integration | ||
secrets: | ||
generic_secret: external_access_db.public.test_secret | ||
artifacts: | ||
- streamlit_app.py |
6 changes: 6 additions & 0 deletions
6
tests_integration/test_data/projects/streamlit_v2_external_access/streamlit_app.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import streamlit as st | ||
import _snowflake | ||
|
||
|
||
st.title(f"Example streamlit app.") | ||
secret = _snowflake.get_generic_secret_string("generic_secret") |
Oops, something went wrong.