-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathutils.py
More file actions
23 lines (20 loc) · 717 Bytes
/
utils.py
File metadata and controls
23 lines (20 loc) · 717 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import os
import json
def get_project_id() -> str:
"""Get google cloud project id from deployment site or locally
Raises:
Exception: exception if not able to deletemine project id
Returns:
[type]: Return project id
"""
# Deployed site
# GCP_PROJECT is supported only with --runtime `python37`
if 'GCP_PROJECT' in os.environ:
return os.environ['GCP_PROJECT']
# Local development
elif 'GOOGLE_APPLICATION_CREDENTIALS' in os.environ:
with open(os.environ['GOOGLE_APPLICATION_CREDENTIALS'], 'r') as fp:
credentials = json.load(fp)
return credentials['project_id']
else:
raise Exception('Failed to determine project_id')