Skip to content

Commit f50591a

Browse files
committed
Trying local file, then environment for secrets
1 parent 4450fb2 commit f50591a

File tree

4 files changed

+66
-4
lines changed

4 files changed

+66
-4
lines changed

src/server/api/common_api.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,23 @@
77
import time
88
from datetime import datetime
99
import dateutil.parser
10-
from secrets import SHELTERLUV_SECRET_TOKEN
10+
11+
12+
try:
13+
from secrets import SHELTERLUV_SECRET_TOKEN
14+
except ImportError:
15+
# Not running locally
16+
print("Couldn't get SL_TOKEN from file, trying environment **********")
17+
from os import environ
18+
19+
try:
20+
SHELTERLUV_SECRET_TOKEN = environ['SHELTERLUV_SECRET_TOKEN']
21+
except KeyError:
22+
# Nor in environment
23+
# You're SOL for now
24+
print("Couldn't get secrets from file or environment")
25+
26+
1127

1228
from api import jwt_ops
1329

src/server/app.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,21 @@
44

55
from flask_jwt_extended import JWTManager
66

7-
from secrets import JWT_SECRET, APP_SECRET_KEY
7+
try:
8+
from secrets import JWT_SECRET, APP_SECRET_KEY
9+
except ImportError:
10+
# Not running locally
11+
print("Could not get secrets from file, trying environment **********")
12+
from os import environ
13+
14+
try:
15+
JWT_SECRET = environ['JWT_SECRET']
16+
APP_SECRET_KEY = environ['APP_SECRET_KEY']
17+
except KeyError:
18+
# Nor in environment
19+
# You're SOL for now
20+
print("Couldn't get secrets from file or environment")
21+
822

923
app = Flask(__name__)
1024

src/server/pipeline/shelterluv_api_handler.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
import requests
22
import csv
33
from config import RAW_DATA_PATH
4-
from secrets import SHELTERLUV_SECRET_TOKEN
4+
5+
try:
6+
from secrets import SHELTERLUV_SECRET_TOKEN
7+
except ImportError:
8+
# Not running locally
9+
print("Couldn't get SL_TOKEN from file, trying environment **********")
10+
from os import environ
11+
12+
try:
13+
SHELTERLUV_SECRET_TOKEN = environ['SHELTERLUV_SECRET_TOKEN']
14+
except KeyError:
15+
# Nor in environment
16+
# You're SOL for now
17+
print("Couldn't get secrets from file or environment")
18+
519

620

721
def write_csv(json_data):

src/server/user_mgmt/base_users.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,25 @@
33
from api import user_api
44
import sqlalchemy as sa
55

6-
from secrets import BASEUSER_PW, BASEEDITOR_PW, BASEADMIN_PW
6+
try:
7+
from secrets import BASEUSER_PW, BASEEDITOR_PW, BASEADMIN_PW
8+
except ImportError:
9+
# Not running locally
10+
print("Couldn't get BASE user PWs from file, trying environment **********")
11+
from os import environ
12+
13+
try:
14+
BASEUSER_PW = environ['BASEUSER_PW']
15+
BASEEDITOR_PW = environ['BASEEDITOR_PW']
16+
BASEADMIN_PW = environ['BASEADMIN_PW']
17+
18+
except KeyError:
19+
# Nor in environment
20+
# You're SOL for now
21+
print("Couldn't get secrets from file or environment")
22+
23+
24+
725

826

927
from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey

0 commit comments

Comments
 (0)