You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
857 B
Python
28 lines
857 B
Python
import os
|
|
|
|
|
|
def build_postgres_uri(
|
|
host, user, dbname, port, sslmode=None, passwd=None, params=None
|
|
):
|
|
"""Builds a PostgreSQL uri.
|
|
|
|
See https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING for additional details.
|
|
"""
|
|
|
|
if passwd:
|
|
uri = f"postgresql://{user}:{passwd}@{host}:{port}/{dbname}"
|
|
else:
|
|
uri = f"postgresql://{user}@{host}:{port}/{dbname}"
|
|
if sslmode:
|
|
uri = f"{uri}?sslmode={sslmode}"
|
|
return uri
|
|
|
|
|
|
POSTGRES_HOST = os.getenv("POSTGRES_HOST")
|
|
POSTGRES_USER = os.getenv("POSTGRES_USER")
|
|
POSTGRES_APP_DATABASE = os.getenv("POSTGRES_APP_DATABASE")
|
|
POSTGRES_PASSWORD = os.getenv("POSTGRES_PASSWORD")
|
|
POSTGRES_PORT = os.getenv("POSTGRES_PORT", default="5432")
|
|
POSTGRES_SSL_MODE = os.getenv("POSTGRES_SSL_MODE", default="prefer")
|
|
POSTGRES_PARAMS = os.getenv("POSTGRES_PARAMS")
|