Skip to content
This repository has been archived by the owner on Feb 14, 2024. It is now read-only.

Commit

Permalink
Merge pull request #91 from cisagov/CD-wip-db-config
Browse files Browse the repository at this point in the history
Add database connection config
  • Loading branch information
cduhn17 committed Nov 2, 2021
2 parents e8dc44b + 699ac5e commit 46c05c1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
7 changes: 5 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ def get_version(version_file):
keywords="posture and exposure report",
packages=find_packages(where="src"),
package_dir={"": "src"},
package_data={"pe_reports": ["data/shell/*.pptx"], "pe_mailer": ["data/*"]},
package_data={
"pe_reports": ["data/shell/*.pptx", "data/*.config"],
"pe_mailer": ["data/*"],
},
py_modules=[splitext(basename(path))[0] for path in glob("src/*.py")],
include_package_data=True,
install_requires=[
Expand All @@ -93,7 +96,7 @@ def get_version(version_file):
"chevron",
"docopt",
"glob2",
"mongo-db-from-config @ http://github.com/cisagov/mongo-db-from-config/tarball/develop",
"mongo-db-from-config@http://github.com/cisagov/mongo-db-from-config/tarball/develop",
"openpyxl",
"pandas",
"pyyaml",
Expand Down
25 changes: 25 additions & 0 deletions src/pe_reports/data/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""Configuration to connect to a PostgreSQL database."""

# Standard Python Libraries
from configparser import ConfigParser
from importlib.resources import files

REPORT_DB_CONFIG = files("pe_reports").joinpath("data/dbconfig.config")


def config(filename=REPORT_DB_CONFIG, section="postgres"):
"""Parse Postgres configuration details from database configuration file."""
parser = ConfigParser()

parser.read(filename, encoding="utf-8")

db = dict()

if parser.has_section(section):
for key, value in parser.items(section):
db[key] = value

else:
raise Exception(f"Section {section} not found in {filename}")

return db

0 comments on commit 46c05c1

Please sign in to comment.