aboutsummaryrefslogtreecommitdiff
path: root/src/ztdns_db_connectivity.py
blob: b754daaf80e7d853a0aafe5240b4b0b85bf0dd31 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import yaml
import psycopg2

db_config_path = '/etc/0tdns/db_connection_config.yml'

def start_db_connection():
    config = yaml.safe_load(open(db_config_path, 'r'))
    connection = psycopg2.connect(user=config['user'], password=config['password'],
                                  host=config['host'], port=config['port'],
                                  database=config['database'])
    # we might later decide that each user of start_db_connection()
    # should set it themselves - but for now, set it here
    connection.autocommit = True
    return connection