espin086 / espin086/EmoTrack

Set Up `.streamlit` Folder and `secrets.toml` File for Secure Secrets Management

Open
#6 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
6
Forks
2
PR merge metrics
No merged PRs in 30d

Description

### **Summary**
This issue outlines the steps needed to set up a `.streamlit` folder with a `secrets.toml` file for securely managing secrets in our Streamlit application.

### **Steps to Complete**

1. **Create a `.streamlit` Folder:**
- In the root directory of the project, create a folder named `.streamlit`.

2. **Create a `secrets.toml` File:**
- Inside the newly created `.streamlit` folder, create a file named `secrets.toml`.
- This file will store our secrets in a structured and secure manner.

3. **Add Secrets to `secrets.toml`:**
- Add secrets to the `secrets.toml` file in the following format:

```toml
[database]
user = "your_username"
password = "your_password"
host = "your_host"
port = "your_port"

[api_keys]
google_maps = "your_google_maps_api_key"
sendgrid = "your_sendgrid_api_key"
```

- Example:
```toml
[database]
user = "admin"
password = "password123"
host = "localhost"
port = "5432"

[api_keys]
google_maps = "your_google_maps_api_key"
sendgrid = "your_sendgrid_api_key"
```

4. **Access Secrets in the Streamlit App:**
- Access the secrets in the Streamlit app using the `st.secrets` object:
```python
import streamlit as st

# Access database credentials
db_user = st.secrets["database"]["user"]
db_password = st.secrets["database"]["password"]
db_host = st.secrets["database"]["host"]
db_port = st.secrets["database"]["port"]

# Access API keys
google_maps_api_key = st.secrets["api_keys"]["google_maps"]
sendgrid_api_key = st.secrets["api_keys"]["sendgrid"]
```

5. **Update `.gitignore`:**
- Add `.streamlit/secrets.toml` to the `.gitignore` file to prevent secrets from being committed to version control:
```plaintext
# .gitignore
.streamlit/secrets.toml
```

6. **Deploying to Streamlit Cloud:**
- When deploying to Streamlit Cloud, set the secrets directly in the Streamlit Cloud interface under the "Secrets" section of the app's settings.

### **Additional Information**
By following these steps, we ensure that our secrets are securely managed and not exposed in version control.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.