-
-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from hummingbot/add_helpers
feat / add helper script for authentication
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import streamlit_authenticator as stauth | ||
import ruamel.yaml as yaml | ||
import os | ||
|
||
# enter email address | ||
new_email = input("Enter dashboard email >> ") | ||
|
||
# if user enter no email address, exit setup! | ||
if len(new_email) == 0: | ||
print("\nNo email added, please try again!\n") | ||
exit() | ||
|
||
# load the YAML file | ||
yaml_file = "../credentials.yml" | ||
with open(yaml_file, "r") as file: | ||
data = yaml.safe_load(file) | ||
|
||
# append the email address to credentials.yml | ||
data["preauthorized"]["emails"].append(new_email) | ||
|
||
# write the updated data back to the file | ||
with open(yaml_file, "w") as file: | ||
yaml.dump(data, file, Dumper=yaml.RoundTripDumper) | ||
|
||
print("Email has been successfully added!") |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import streamlit_authenticator as stauth | ||
import ruamel.yaml as yaml | ||
import os | ||
|
||
# enter admin password or use default t3st01 | ||
new_password = input("Enter dashboard password >> ") | ||
new_password = new_password or "t3st01" | ||
|
||
# extract the hash password from the List | ||
hash_password = stauth.Hasher([new_password]).generate()[0] | ||
|
||
# load the YAML file | ||
yaml_file = "../credentials.yml" | ||
with open(yaml_file, "r") as file: | ||
data = yaml.safe_load(file) | ||
|
||
# update the admin password on credentials.yml | ||
data["credentials"]["usernames"]["admin"]["password"] = hash_password | ||
|
||
# write the updated data back to the file | ||
with open(yaml_file, "w") as file: | ||
yaml.dump(data, file, Dumper=yaml.RoundTripDumper) | ||
|
||
print("Admin password has been updated! ") |