Spaces:
Sleeping
Sleeping
Commit
·
ea3ced9
1
Parent(s):
382eeb3
Create creds.py
Browse files
creds.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import json
|
| 2 |
+
import tempfile
|
| 3 |
+
|
| 4 |
+
# process of getting credentials
|
| 5 |
+
def get_credentials():
|
| 6 |
+
creds_json_str = os.getenv("creds") # get json credentials stored as a string
|
| 7 |
+
if creds_json_str is None:
|
| 8 |
+
raise ValueError("GOOGLE_APPLICATION_CREDENTIALS_JSON not found in environment")
|
| 9 |
+
|
| 10 |
+
# create a temporary file
|
| 11 |
+
with tempfile.NamedTemporaryFile(mode="w+", delete=False, suffix=".json") as temp:
|
| 12 |
+
temp.write(creds_json_str) # write in json format
|
| 13 |
+
temp_filename = temp.name
|
| 14 |
+
|
| 15 |
+
return temp_filename
|
| 16 |
+
|
| 17 |
+
# pass
|
| 18 |
+
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]= get_credentials()
|