-
Notifications
You must be signed in to change notification settings - Fork 3
/
config.py
23 lines (20 loc) · 789 Bytes
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import configparser
import os
from pathlib import Path
def get_config():
"""Read and parse the application's config file.
Cryptographic (i.e. secret) keys are in the config file, so enforce that it
must have secure file system permissions.
"""
ini_path = os.environ.get("SPI_TOOLS_CONFIG_FILE",
(Path.home() / "www/python/config.ini").as_posix())
# Apparently git doesn't preserve file modes, so this fails on
# unsafe-sample-config.ini
#
# ini_mode = os.stat(ini_path).st_mode
# if ini_mode & 0o77:
# raise RuntimeError("%s has mode %o: access by non-owner disallowed" %
# (ini_path, ini_mode))
config = configparser.ConfigParser()
config.read(ini_path)
return config