diff --git a/credentials.yml b/credentials.yml new file mode 100644 index 00000000..f6c8dddc --- /dev/null +++ b/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 diff --git a/environment_conda.yml b/environment_conda.yml index d35aeb40..c66e00c1 100644 --- a/environment_conda.yml +++ b/environment_conda.yml @@ -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 diff --git a/main.py b/main.py index 3895c7e6..af7e626f 100644 --- a/main.py +++ b/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)! ๐Ÿ™")