Jon Solow commited on
Commit
24d027c
·
1 Parent(s): d8aaa4e

Create custom gsheets connection class to overwrite secrets access

Browse files
Files changed (1) hide show
  1. src/login.py +20 -1
src/login.py CHANGED
@@ -1,9 +1,28 @@
1
  import hmac
2
  import streamlit as st
3
  from streamlit_gsheets import GSheetsConnection
 
4
 
5
 
6
- conn = st.connection("gsheets", type=GSheetsConnection)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
 
8
 
9
  def get_user_id_from_email_if_exists(email: str) -> int:
 
1
  import hmac
2
  import streamlit as st
3
  from streamlit_gsheets import GSheetsConnection
4
+ from streamlit.runtime.secrets import AttrDict, secrets_singleton
5
 
6
 
7
+ class HFFriendlyGSheetsConnection(GSheetsConnection):
8
+ # HF doesnt currently support nested secrets as in secrets.toml
9
+ # this class overwrites the logic for where to find the secrets and instead creates them from the top level of secrets
10
+ @property
11
+ def _secrets(self) -> AttrDict:
12
+ """Get the secrets for this connection from the corresponding st.secrets section.
13
+
14
+ We expect this property to be used primarily by connection authors when they
15
+ are implementing their class' ``_connect`` method. User scripts should, for the
16
+ most part, have no reason to use this property.
17
+ """
18
+ connections_section = None
19
+ if secrets_singleton.load_if_toml_exists():
20
+ connections_section = secrets_singleton
21
+
22
+ return AttrDict(connections_section)
23
+
24
+
25
+ conn = st.connection("gsheets", type=HFFriendlyGSheetsConnection)
26
 
27
 
28
  def get_user_id_from_email_if_exists(email: str) -> int: