Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/streamlit auth #71

Merged
merged 5 commits into from Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions credentials.yml
@@ -0,0 +1,13 @@
cookie:
expiry_days: 30
key: random_signature_key
name: random_cookie_name
credentials:
usernames:
master:
email: admin@gmail.com
name: Admin User
password: abc # To be replaced with hashed password: hashed_passwords = stauth.Hasher(['abc', 'def']).generate()
preauthorized: # the preferred way to add users since there is no need for manual hashing of passwords
emails:
- operations@hummingbot.org
1 change: 1 addition & 0 deletions environment_conda.yml
Expand Up @@ -26,5 +26,6 @@ dependencies:
- streamlit-ace
- st-pages
- streamlit-elements==0.1.*
- streamlit-authenticator
- git+https://github.com/hummingbot/hbot-remote-client-py.git
- git+https://github.com/hummingbot/docker-manager.git
89 changes: 60 additions & 29 deletions main.py
@@ -1,36 +1,67 @@
import streamlit as st
from st_pages import Page, Section, show_pages
from streamlit_authenticator import Authenticate

from utils.st_utils import initialize_st_page
from utils.os_utils import read_yaml_file, dump_dict_to_yaml

initialize_st_page(title="Hummingbot Dashboard", icon="📊", initial_sidebar_state="expanded")

show_pages(
[
config = read_yaml_file("credentials.yml")

if "authenticator" not in st.session_state:
st.session_state.authenticator = Authenticate(
config['credentials'],
config['cookie']['name'],
config['cookie']['key'],
config['cookie']['expiry_days'],
config['preauthorized']
)

if st.session_state["authentication_status"]:
config["credentials"] = st.session_state.authenticator.credentials
dump_dict_to_yaml(config, "credentials.yml")
with st.sidebar:
st.session_state.authenticator.logout('Logout', 'sidebar')
st.write(f'Welcome *{st.session_state["name"]}*')
show_pages(
[
Page("main.py", "Hummingbot Dashboard", "📊"),
Section("Bot Orchestration", "🐙"),
Page("pages/master_conf/app.py", "Credentials", "🗝️"),
Page("pages/launch_bot/app.py", "Launch Bot", "🙌"),
Page("pages/bot_orchestration/app.py", "Instances", "🦅"),
Page("pages/file_manager/app.py", "Strategy Configs", "🗂"),
Section("Backtest Manager", "⚙️"),
Page("pages/candles_downloader/app.py", "Get Data", "💾"),
Page("pages/backtest_manager/create.py", "Create", "⚔️"),
Page("pages/backtest_manager/optimize.py", "Optimize", "🧪"),
Page("pages/backtest_manager/analyze.py", "Analyze", "🔬"),
Page("pages/backtest_manager/analyze_v2.py", "Analyze v2", "🔬"),
Page("pages/backtest_manager/simulate.py", "Simulate", "📈"),
Section("Community Pages", "👨‍👩‍👧‍👦"),
Page("pages/strategy_performance/app.py", "Strategy Performance", "🚀"),
Page("pages/db_inspector/app.py", "DB Inspector", "🔍"),
Page("pages/token_spreads/app.py", "Token Spreads", "🧙"),
Page("pages/tvl_vs_mcap/app.py", "TVL vs Market Cap", "🦉"),
]
)
# initialize_st_page(title="Hummingbot Dashboard", icon="📊", initial_sidebar_state="expanded")
st.write("Watch this video to understand how the dashboard works! 🦅")
c1, c2, c3 = st.columns([1, 6, 1])
st.write("---")
with c2:
st.video("https://youtu.be/2q9HSyIPuf4")
st.write(
"Please give us feedback in the **#dashboard** channel of the [Hummingbot Discord](https://discord.gg/hummingbot)! 🙏")
else:
show_pages([
Page("main.py", "Hummingbot Dashboard", "📊"),
Section("Bot Orchestration", "🐙"),
Page("pages/master_conf/app.py", "Credentials", "🗝️"),
Page("pages/launch_bot/app.py", "Launch Bot", "🙌"),
Page("pages/bot_orchestration/app.py", "Instances", "🦅"),
Page("pages/file_manager/app.py", "Strategy Configs", "🗂"),
Section("Backtest Manager", "⚙️"),
Page("pages/candles_downloader/app.py", "Get Data", "💾"),
Page("pages/backtest_manager/create.py", "Create", "⚔️"),
Page("pages/backtest_manager/optimize.py", "Optimize", "🧪"),
Page("pages/backtest_manager/analyze.py", "Analyze", "🔬"),
Page("pages/backtest_manager/analyze_v2.py", "Analyze v2", "🔬"),
Page("pages/backtest_manager/simulate.py", "Simulate", "📈"),
Section("Community Pages", "👨‍👩‍👧‍👦"),
Page("pages/strategy_performance/app.py", "Strategy Performance", "🚀"),
Page("pages/db_inspector/app.py", "DB Inspector", "🔍"),
Page("pages/token_spreads/app.py", "Token Spreads", "🧙"),
Page("pages/tvl_vs_mcap/app.py", "TVL vs Market Cap", "🦉"),
]
)
])
name, authentication_status, username = st.session_state.authenticator.login('Login', 'main')
if st.session_state["authentication_status"] == False:
st.error('Username/password is incorrect')
elif st.session_state["authentication_status"] == None:
st.warning('Please enter your username and password')
st.write("---")
st.write("If you are pre-authorized, you can login with your pre-authorized mail!")
st.session_state.authenticator.register_user('Register', 'main')

st.write("Watch this video to understand how the dashboard works! 🦅")
c1, c2, c3 = st.columns([1, 6, 1])
st.write("---")
with c2:
st.video("https://youtu.be/2q9HSyIPuf4")
st.write("Please give us feedback in the **#dashboard** channel of the [Hummingbot Discord](https://discord.gg/hummingbot)! 🙏")