-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
25 additions
and
31 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,28 +1,26 @@ | ||
import os | ||
import streamlit as st | ||
|
||
class SecretsHandler: | ||
_instance = None | ||
_directory = "/.streamlit" | ||
_directory = ".streamlit" | ||
_file_name = "app_secrets.toml" | ||
_file_path = os.path.join(_directory, _file_name) | ||
|
||
def __init__(self): | ||
if not os.path.exists(self._directory): | ||
os.makedirs(self._directory) | ||
with(open(os.path.join(self._directory, "secrets.toml"), "w")) as f: | ||
with(open(self._file_path, "w+")) as f: | ||
f.write("") | ||
|
||
def __new__(cls): | ||
if cls._instance is None: | ||
cls._instance = super().__new__(cls) | ||
|
||
return cls._instance | ||
|
||
def write_secret(self, key, value): | ||
with(open(os.path.join(self._directory, "secrets.toml"), "w")) as f: | ||
f.write(f"{key} = '{value}'") | ||
with(open(self._file_path, "w")) as f: | ||
f.write(f"{key}:{value};") | ||
|
||
def get_secret(self, key) -> str: | ||
if st.secrets and key in st.secrets: | ||
return st.secrets[key] | ||
return '' | ||
|
||
with(open(self._file_path, "r")) as f: | ||
secrets = f.read() | ||
secret_key = secrets.split(";") | ||
for key_value in secret_key: | ||
secret_key = key_value.split(":")[0] | ||
if key == secret_key: | ||
return key_value.split(":")[1] | ||
return '' |
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