refactor: add black formatting

This commit is contained in:
Krrish Dholakia 2023-12-25 14:10:38 +05:30
parent b87d630b0a
commit 4905929de3
156 changed files with 19723 additions and 10869 deletions

View file

@ -2,6 +2,7 @@
Admin sets proxy url + allowed email subdomain
"""
from dotenv import load_dotenv
load_dotenv()
import streamlit as st
import base64, os
@ -9,34 +10,47 @@ import base64, os
# Replace your_base_url with the actual URL where the proxy auth app is hosted
your_base_url = os.getenv("BASE_URL") # Example base URL
# Function to encode the configuration
def encode_config(proxy_url, allowed_email_subdomain):
combined_string = f"proxy_url={proxy_url}&accepted_email_subdomain={allowed_email_subdomain}"
return base64.b64encode(combined_string.encode('utf-8')).decode('utf-8')
combined_string = (
f"proxy_url={proxy_url}&accepted_email_subdomain={allowed_email_subdomain}"
)
return base64.b64encode(combined_string.encode("utf-8")).decode("utf-8")
# Simple function to update config values
def update_config(proxy_url, allowed_email_subdomain):
st.session_state['proxy_url'] = proxy_url
st.session_state['allowed_email_subdomain'] = allowed_email_subdomain
st.session_state['user_auth_url'] = f"{your_base_url}/?page={encode_config(proxy_url=proxy_url, allowed_email_subdomain=allowed_email_subdomain)}"
st.session_state["proxy_url"] = proxy_url
st.session_state["allowed_email_subdomain"] = allowed_email_subdomain
st.session_state[
"user_auth_url"
] = f"{your_base_url}/?page={encode_config(proxy_url=proxy_url, allowed_email_subdomain=allowed_email_subdomain)}"
def admin_page():
# Display the form for the admin to set the proxy URL and allowed email subdomain
st.header("Admin Configuration")
# Create a configuration placeholder
st.session_state.setdefault('proxy_url', 'http://example.com')
st.session_state.setdefault('allowed_email_subdomain', 'example.com')
st.session_state.setdefault('user_auth_url', 'NOT_GIVEN')
st.session_state.setdefault("proxy_url", "http://example.com")
st.session_state.setdefault("allowed_email_subdomain", "example.com")
st.session_state.setdefault("user_auth_url", "NOT_GIVEN")
with st.form("config_form", clear_on_submit=False):
proxy_url = st.text_input("Set Proxy URL", st.session_state['proxy_url'])
allowed_email_subdomain = st.text_input("Set Allowed Email Subdomain", st.session_state['allowed_email_subdomain'])
proxy_url = st.text_input("Set Proxy URL", st.session_state["proxy_url"])
allowed_email_subdomain = st.text_input(
"Set Allowed Email Subdomain", st.session_state["allowed_email_subdomain"]
)
submitted = st.form_submit_button("Save")
if submitted:
update_config(proxy_url=proxy_url, allowed_email_subdomain=allowed_email_subdomain)
update_config(
proxy_url=proxy_url, allowed_email_subdomain=allowed_email_subdomain
)
# Display the current configuration
st.write(f"Current Proxy URL: {st.session_state['proxy_url']}")
st.write(f"Current Allowed Email Subdomain: {st.session_state['allowed_email_subdomain']}")
st.write(f"Current User Auth URL: {st.session_state['user_auth_url']}")
st.write(
f"Current Allowed Email Subdomain: {st.session_state['allowed_email_subdomain']}"
)
st.write(f"Current User Auth URL: {st.session_state['user_auth_url']}")