Skip to content

Commit afe623c

Browse files
authored
[ez] make all connections to the database allow DISABLE_SSL (#297)
* [ez] make all connections to the database allow DISABLE_SSL * lint
1 parent 543e16f commit afe623c

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

scripts/flush_db.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
#!/usr/bin/env python3
22

3-
import os
43

54
import psycopg2
65
from dotenv import load_dotenv
6+
from env import DATABASE_URL, DISABLE_SSL
77
from psycopg2 import Error
88

99

1010
def flush_database():
1111
# Load environment variables
1212
load_dotenv()
1313

14-
DATABASE_URL = os.getenv("DATABASE_URL")
15-
1614
if DATABASE_URL is None:
1715
print("❌ Missing DATABASE_URL environment variable")
1816
return
1917

2018
try:
2119
# Connect to database
2220
print("📡 Connecting to database...")
23-
connection = psycopg2.connect(DATABASE_URL, sslmode="require")
21+
connection = psycopg2.connect(
22+
DATABASE_URL,
23+
sslmode="disable" if DISABLE_SSL else "require"
24+
)
2425
cursor = connection.cursor()
2526

2627
# Drop existing tables

src/discord-cluster-manager/cogs/misc_cog.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import psycopg2
66
from discord import app_commands
77
from discord.ext import commands
8-
from env import DATABASE_URL
8+
from env import DATABASE_URL, DISABLE_SSL
99
from utils import send_discord_message, setup_logging
1010

1111
if TYPE_CHECKING:
@@ -33,7 +33,8 @@ async def verify_db(self, interaction: discord.Interaction):
3333
return
3434

3535
try:
36-
with psycopg2.connect(DATABASE_URL, sslmode="require") as conn:
36+
sslmode = "disable" if DISABLE_SSL else "require"
37+
with psycopg2.connect(DATABASE_URL, sslmode=sslmode) as conn:
3738
with conn.cursor() as cursor:
3839
cursor.execute("SELECT RANDOM()")
3940
result = cursor.fetchone()

0 commit comments

Comments
 (0)