-
Notifications
You must be signed in to change notification settings - Fork 0
/
secret.py
32 lines (24 loc) · 1.12 KB
/
secret.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
import json
import os
from firebase_admin.credentials import Certificate
from google.cloud import secretmanager
if os.getenv("BOWIE_BACKEND_DEBUG") is None: # ie if the env var isn't set
client = secretmanager.SecretManagerServiceClient()
project_id = os.environ["GCP_PROJECT"]
square_secret = "square_application_token"
square_resource_name = f"projects/{project_id}/secrets/{square_secret}/versions/latest"
response = client.access_secret_version(square_resource_name)
square_secret_string = response.payload.data.decode('UTF-8')
google_secret = "firebase_admin_sdk"
google_resource_name = f"projects/{project_id}/secrets/{google_secret}/versions/latest"
response = client.access_secret_version(google_resource_name)
google_secret_string = response.payload.data.decode('UTF-8')
google_secret_dict: str = json.loads(google_secret_string)
def square_application_token():
if os.getenv("BOWIE_BACKEND_DEBUG") is not None:
return os.getenv("SQUARE_APPLICATION_TOKEN")
return square_secret_string
def google_credential():
if os.getenv("BOWIE_BACKEND_DEBUG") is not None:
return None
return Certificate(google_secret_dict)