-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.py
50 lines (41 loc) · 1.39 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import json
import os
from google.cloud import secretmanager
def _get_project():
try:
service_creds = os.environ.get("GOOGLE_APPLICATION_CREDENTIALS", None)
if service_creds:
with open(service_creds, "r") as creds_json:
creds = json.load(creds_json)
project = creds["project_id"]
if project:
return project
else:
project = os.environ.get("PROJECT_ID", None)
if project:
return project
else:
raise ValueError
except ValueError:
print("Could not determine project id.")
_PROJECT = _get_project()
_SECRET_CLIENT = secretmanager.SecretManagerServiceClient()
def _get_secret(secret, version):
name = _SECRET_CLIENT.secret_version_path(_PROJECT, secret, version)
response = _SECRET_CLIENT.access_secret_version(name)
return response.payload.data.decode("UTF-8")
def is_cloud_service(service_config):
config_string = json.dumps(service_config)
if "Firebase" in service_config.get("title"):
return False
if "auth/firebase" in config_string:
return False
if "auth/cloud-platform" in config_string:
return True
if "auth/drive" in config_string:
return True
if "auth/apps" in config_string:
return True
if "tos/cloud" in config_string:
return True
return False