Skip to content

Commit dd36d62

Browse files
committed
quick fix
1 parent eceaed1 commit dd36d62

2 files changed

Lines changed: 31 additions & 6 deletions

File tree

src/schema.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from src.models.report import Report as ReportModel
2929
from src.models.hourly_average_capacity import HourlyAverageCapacity as HourlyAverageCapacityModel
3030
from src.models.user_workout_goal_history import UserWorkoutGoalHistory as UserWorkoutGoalHistoryModel
31+
from src.utils.constants import get_digital_ocean_s3_endpoint_url
3132
from src.database import db_session
3233
import requests
3334
from firebase_admin import messaging
@@ -847,7 +848,11 @@ def mutate(self, info, name, net_id, email, encoded_image=None):
847848
path = f"uplift-dev/user-profile/{net_id}-profile.png"
848849
region = "nyc3"
849850

850-
logging.info(f"DIGITAL_OCEAN_URL: {os.getenv('DIGITAL_OCEAN_URL')}")
851+
logging.info(
852+
"DIGITAL_OCEAN_URL raw=%r normalized=%r",
853+
os.getenv("DIGITAL_OCEAN_URL"),
854+
get_digital_ocean_s3_endpoint_url(),
855+
)
851856
logging.info(
852857
"CreateUser profile picture upload: net_id=%s, bucket=%s, key=%s",
853858
net_id,
@@ -869,7 +874,7 @@ def mutate(self, info, name, net_id, email, encoded_image=None):
869874
logging.info("Attempting S3 put_object for new user profile picture...")
870875
s3 = boto3.client(
871876
"s3",
872-
endpoint_url=os.getenv("DIGITAL_OCEAN_URL"),
877+
endpoint_url=get_digital_ocean_s3_endpoint_url(),
873878
aws_access_key_id=os.getenv("DIGITAL_OCEAN_ACCESS"),
874879
aws_secret_access_key=os.getenv("DIGITAL_OCEAN_SECRET_ACCESS"),
875880
config=Config(s3={"addressing_style": "path"}),
@@ -925,7 +930,11 @@ def mutate(self, info, user_id, name=None, email=None, encoded_image=None):
925930
path = f"uplift-dev/user-profile/{existing_user.net_id}-profile.png"
926931
region = "nyc3"
927932

928-
logging.info(f"DIGITAL_OCEAN_URL: {os.getenv('DIGITAL_OCEAN_URL')}")
933+
logging.info(
934+
"DIGITAL_OCEAN_URL raw=%r normalized=%r",
935+
os.getenv("DIGITAL_OCEAN_URL"),
936+
get_digital_ocean_s3_endpoint_url(),
937+
)
929938
logging.info(
930939
"EditUser profile picture upload: user_id=%s, net_id=%s, bucket=%s, key=%s",
931940
user_id,
@@ -948,7 +957,7 @@ def mutate(self, info, user_id, name=None, email=None, encoded_image=None):
948957
logging.info("Attempting S3 put_object for edited user profile picture...")
949958
s3 = boto3.client(
950959
"s3",
951-
endpoint_url=os.getenv("DIGITAL_OCEAN_URL"),
960+
endpoint_url=get_digital_ocean_s3_endpoint_url(),
952961
aws_access_key_id=os.getenv("DIGITAL_OCEAN_ACCESS"),
953962
aws_secret_access_key=os.getenv("DIGITAL_OCEAN_SECRET_ACCESS"),
954963
config=Config(s3={"addressing_style": "path"}),
@@ -1231,15 +1240,19 @@ def mutate(self, info, user_id):
12311240
if int(get_jwt_identity()) != user_id:
12321241
raise GraphQLError("Unauthorized operation")
12331242

1234-
logging.info(f"DIGITAL_OCEAN_URL: {os.getenv('DIGITAL_OCEAN_URL')}")
1243+
logging.info(
1244+
"DIGITAL_OCEAN_URL raw=%r normalized=%r",
1245+
os.getenv("DIGITAL_OCEAN_URL"),
1246+
get_digital_ocean_s3_endpoint_url(),
1247+
)
12351248
logging.info(f"User encoded_image: {user.encoded_image}")
12361249

12371250
if user.encoded_image:
12381251
try:
12391252
logging.info("Attempting S3 delete...")
12401253
s3 = boto3.client(
12411254
"s3",
1242-
endpoint_url=os.getenv("DIGITAL_OCEAN_URL"),
1255+
endpoint_url=get_digital_ocean_s3_endpoint_url(),
12431256
aws_access_key_id=os.getenv("DIGITAL_OCEAN_ACCESS"),
12441257
aws_secret_access_key=os.getenv("DIGITAL_OCEAN_SECRET_ACCESS"),
12451258
config=Config(s3={"addressing_style": "path"}),

src/utils/constants.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,15 @@
142142

143143
# The path for Teagle Up Fitness Center details
144144
TEAGLE_UP_DETAILS = "https://scl.cornell.edu/recreation/facility/teagle-upstairs"
145+
146+
147+
def get_digital_ocean_s3_endpoint_url():
148+
"""
149+
DIGITAL_OCEAN_URL for boto3. Strips whitespace and surrounding quotes that
150+
often appear when the value is copied into .env or secret managers with quotes.
151+
"""
152+
raw = os.getenv("DIGITAL_OCEAN_URL")
153+
if not raw:
154+
return None
155+
u = raw.strip().strip("\"'")
156+
return u or None

0 commit comments

Comments
 (0)