forked from microsoft/python-sample-tweeterapp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpsql.py
More file actions
34 lines (29 loc) · 791 Bytes
/
Copy pathpsql.py
File metadata and controls
34 lines (29 loc) · 791 Bytes
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
import os
import subprocess
import urllib.request
import dotenv
dotenv.read_dotenv(os.getcwd() + "/.env")
REQUIRED_ENV_VARS = (
'DB_USER',
'DB_PASSWORD',
'DB_NAME',
'DB_HOST'
)
missing = []
for v in REQUIRED_ENV_VARS:
if v not in os.environ:
missing.append(v)
if missing:
print("Required Environment Variables Unset:")
print("\t" + "\n\t".join(missing))
print("Exiting.")
exit()
os.environ.setdefault('PGPASSWORD', os.environ.get('DB_PASSWORD'))
psql_command = [
"psql",
"-v", f"db_password=\"'{os.environ.get('DB_PASSWORD')}",
"-h", f"{os.environ.get('DB_HOST')}.postgres.database.azure.com",
"-U", f"{os.environ.get('DB_USER')}@{os.environ.get('DB_HOST')}",
"postgres"
]
subprocess.check_call(psql_command, shell=True)