Skip to content

Commit

Permalink
Locked mode
Browse files Browse the repository at this point in the history
  • Loading branch information
iwatkot authored Dec 29, 2024
1 parent 471c64f commit f6dc743
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
22 changes: 22 additions & 0 deletions webui/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
STREAMLIT_COMMUNITY_VALUE = "streamlit"
PUBLIC_HOSTNAME_KEY = "PUBLIC_HOSTNAME"
PUBLIC_HOSTNAME_VALUE = "maps4fs"
PUBLIC_PASSWORD_KEY = "PUBLIC_PASSWORD"

DOCS_DIRECTORY = os.path.join(WORKING_DIRECTORY, "docs")
MD_FILES = {
Expand Down Expand Up @@ -77,6 +78,27 @@ def is_public() -> bool:
return os.environ.get(PUBLIC_HOSTNAME_KEY) == PUBLIC_HOSTNAME_VALUE


def public_password_is_correct(password: str) -> bool:
"""Check if the public password is correct.
Arguments:
password (str): The password to check.
Returns:
bool: True if the password is correct, False otherwise.
"""
return password == os.environ.get(PUBLIC_PASSWORD_KEY)


def public_password_is_set() -> bool:
"""Check if the public password is set.
Returns:
bool: True if the public password is set, False otherwise.
"""
return PUBLIC_PASSWORD_KEY in os.environ


def remove_with_delay_without_blocking(
file_path: str,
logger: mfs.Logger,
Expand Down
17 changes: 17 additions & 0 deletions webui/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ def __init__(self):
self.logger = mfs.Logger(level="INFO", to_file=False)

self.public = config.is_public()
self.locked = False
if self.public and config.public_password_is_set():
# Maintainance mode is enabled.
self.locked = True
st.warning("The app is in maintenance mode, enter the password or get back later.")

password = st.text_input("Password", type="password", key="password")

if st.button("Enter", key="enter_btn"):
if not config.public_password_is_correct(password):
return
else:
self.locked = False

if self.locked:
return

self.logger.debug("The application launched on a public server: %s", self.public)

self.left_column, self.right_column = st.columns(2, gap="large")
Expand Down

0 comments on commit f6dc743

Please sign in to comment.