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

Commit

Permalink
Merge branch 'develop' into wip-pe-mailer-tests
Browse files Browse the repository at this point in the history
  • Loading branch information
schmelz21 committed Oct 8, 2021
2 parents 354ec1b + 9fc29ef commit 27378c8
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 42 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ repos:
hooks:
- id: mypy
additional_dependencies:
- types-requests
- types-PyYAML
- types-requests
- types-setuptools
- repo: https://github.com/asottile/pyupgrade
rev: v2.23.3
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
[![Coverage Status](https://coveralls.io/repos/github/cisagov/pe-reports/badge.svg?branch=develop)](https://coveralls.io/github/cisagov/pe-reports?branch=develop)
[![Total alerts](https://img.shields.io/lgtm/alerts/g/cisagov/pe-reports.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/cisagov/pe-reports/alerts/)
[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/cisagov/pe-reports.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/cisagov/pe-reports/context:python)
[![Known Vulnerabilities](https://snyk.io/test/github/cisagov/pe-reports/develop/badge.svg)](https://snyk.io/test/github/cisagov/pe-reports)

This package is used to generate and deliver CISA Posture & Exposure Reports
(P&E Reports). Reports are delivered by email and include an encrypted PDF
attachment with a series of embedded raw-data files of the collected materials.
The reports are delivered in a two step process. First the `pe_reports` module
collects the raw-data and creates the encrypted PDFs. The `pe_mailer` then
collects the raw data and creates the encrypted PDFs. The `pe_mailer` then
securely delivers the content.

Topics of interest include *Exposed Credentials, Domain Masquerading, Malware,
Expand All @@ -32,15 +33,15 @@ is gathered on the 1st and 15th of each month.

## Create P&E Reports ##

- Connect to [cisagov MongoDB](https://github.com/cisagov/mongo-db-from-config)
- Configure [cisagov MongoDB connection](https://github.com/cisagov/mongo-db-from-config)

```consol
```console
Usage:
pe-reports REPORT_DATE DATA_DIRECTORY OUTPUT_DIRECTORY [--db-creds-file=FILENAME] [--log-level=LEVEL]

Arguments:
REPORT_DATE Date of the report, format YYYY-MM-DD.
DATA_DIRECTORY The directory where the excel data files are located.
DATA_DIRECTORY The directory where the Excel data files are located.
Organized by owner.
OUTPUT_DIRECTORY The directory where the final PDF reports should be saved.
-c --db-creds-file=FILENAME A YAML file containing the Cyber
Expand All @@ -56,11 +57,11 @@ Options:

## Deliver P&E Reports ##

- Connect to [cisagov MongoDB](https://github.com/cisagov/mongo-db-from-config)
- Configure [cisagov MongoDB connection](https://github.com/cisagov/mongo-db-from-config)

- Load [AWS Profile](https://github.com/cisagov/cool-dns-cyber.dhs.gov)
- Load an AWS profile that assumes [this role](https://github.com/cisagov/cool-dns-cyber.dhs.gov/blob/develop/sessendemail_rolerole.tf#L33-L39)

```consol
```console
Usage:
pe-mailer [--pe-report-dir=DIRECTORY] [--db-creds-file=FILENAME] [--log-level=LEVEL]

Expand Down
8 changes: 3 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ def get_version(version_file):
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
# TODO: PyYAML is not compatable with 3.9
# Create Issue
# "Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.9",
],
python_requires=">=3.6",
# What does your project relate to?
Expand All @@ -92,19 +90,19 @@ def get_version(version_file):
install_requires=[
"boto3",
"botocore",
"chevron",
"docopt",
"glob2",
"mongo-db-from-config @ http://github.com/cisagov/mongo-db-from-config/tarball/develop",
"openpyxl",
"pandas",
"pyyaml",
"types-PyYAML",
"pymongo",
"pymupdf",
"pystache",
"python-pptx",
"schema",
"setuptools >= 24.2.0",
"types-PyYAML",
],
extras_require={
"test": [
Expand Down
4 changes: 0 additions & 4 deletions src/pe_mailer/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
"""The pe_mailer library."""
# We disable a Flake8 check for "Module imported but unused (F401)" here because
# although this import is not directly used, it populates the value
# package_name.__version__, which is used to get version information about this
# Python package.

from ._version import __version__ # noqa: F401

Expand Down
2 changes: 1 addition & 1 deletion src/pe_mailer/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""Working version of pe-reports."""
"""This file defines the version of this module."""
__version__ = "1.0.0"
11 changes: 5 additions & 6 deletions src/pe_mailer/pe_message.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""This module contains the PEMessage class."""

# Third-Party Libraries
import pystache
import chevron

from .message import Message
from .report_message import ReportMessage
Expand Down Expand Up @@ -97,8 +97,7 @@ def __init__(
report_date : str
The date corresponding to the Posture and Exposure
report attachment. We have been using dates of the
form December 12, 2017.
report attachment. Specify dates using the format "December 12, 2017".
to_addrs : array of str
An array of string objects, each of which is an email
Expand All @@ -120,9 +119,9 @@ def __init__(
mustache_data = {"report_date": report_date}

# Render the templates
subject = pystache.render(PEMessage.Subject, mustache_data)
text_body = pystache.render(PEMessage.TextBody, mustache_data)
html_body = pystache.render(PEMessage.HtmlBody, mustache_data)
subject = chevron.render(PEMessage.Subject, mustache_data)
text_body = chevron.render(PEMessage.TextBody, mustache_data)
html_body = chevron.render(PEMessage.HtmlBody, mustache_data)

ReportMessage.__init__(
self,
Expand Down
26 changes: 13 additions & 13 deletions src/pe_mailer/stats_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import datetime

# Third-Party Libraries
import pystache
import chevron

from .message import Message

Expand All @@ -28,21 +28,21 @@ class StatsMessage(Message):
"""

Subject = "cyhy-mailer summary from {{date}}"
Subject = "pe-mailer summary from {{date}}"

TextBody = """Greetings!
Here is the cyhy-mailer summary from the run ending at {{date}}:
Here is the pe-mailer summary from the run ending at {{date}}:
{{#strings}}
* {{string}}
{{/strings}}
Please direct feedback and questions to ncats-dev@beta.dhs.gov and/or the cyhy-mailer GitHub project.
Please direct feedback and questions to vulnerability@cisa.dhs.gov and/or the pe-reports GitHub project.
Regards,
The VM Development Team
The P&E Development Team
Cybersecurity and Infrastructure Security Agency (CISA)
ncats-dev@beta.dhs.gov
vulnerability@cisa.dhs.gov
"""

HtmlBody = """<html>
Expand All @@ -52,7 +52,7 @@ class StatsMessage(Message):
<p>Greetings!</p>
<p>
Here is the cyhy-mailer summary from {{date}}:
Here is the pe-mailer summary from {{date}}:
<ul>
{{#strings}}
<li>{{string}}</li>
Expand All @@ -61,16 +61,16 @@ class StatsMessage(Message):
</p>
<p> Please direct feedback and questions to <a
href="mailto:ncats-dev@beta.dhs.gov">the VM Development Team</a>
href="mailto:vulnerability@cisa.dhs.gov">the P&E Development Team</a>
and/or the <a
href="https://github.com/cisagov/cyhy-mailer">cyhy-mailer GitHub
href="https://github.com/cisagov/pe-reports">pe-mailer GitHub
project</a>.</p>
<p>
Regards,<br>
The VM Development Team<br><br>
Cybersecurity and Infrastructure Security Agency<br>
<a href="mailto:ncats-dev@beta.dhs.gov">ncats-dev@beta.dhs.gov</a>
<a href="mailto:vulnerability@cisa.dhs.gov">vulnerability@cisa.dhs.gov</a>
</div>
</body>
</html>
Expand Down Expand Up @@ -102,8 +102,8 @@ def __init__(self, to_addrs, list_of_strings):
}

# Render the templates
subject = pystache.render(StatsMessage.Subject, mustache_data)
text_body = pystache.render(StatsMessage.TextBody, mustache_data)
html_body = pystache.render(StatsMessage.HtmlBody, mustache_data)
subject = chevron.render(StatsMessage.Subject, mustache_data)
text_body = chevron.render(StatsMessage.TextBody, mustache_data)
html_body = chevron.render(StatsMessage.HtmlBody, mustache_data)

Message.__init__(self, to_addrs, subject, text_body, html_body)
2 changes: 1 addition & 1 deletion src/pe_reports/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""Working version of pe-reports."""
"""This file defines the version of this module."""
__version__ = "1.2.1"
6 changes: 2 additions & 4 deletions src/pe_reports/report_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Arguments:
REPORT_DATE Date of the report, format YYYY-MM-DD.
DATA_DIRECTORY The directory where the excel data files are located.
DATA_DIRECTORY The directory where the Excel data files are located.
Organized by owner.
OUTPUT_DIRECTORY The directory where the final PDF reports should be saved.
-c --db-creds-file=FILENAME A YAML file containing the Cyber
Expand Down Expand Up @@ -56,11 +56,9 @@ def export_set(prs, out_dir):

def generate_reports(data, data_dir, out_dir, db_creds_file):
"""Gather assets to produce reports."""
# TODO: build code to connect customer db, encrypt and embed pdf reports.
# Issue 7: https://github.com/cisagov/pe-reports/issues/7


def main():
def main() -> None:
"""Set up logging and call the generate_reports function."""
args: Dict[str, str] = docopt.docopt(__doc__, version=__version__)
# Validate and convert arguments as needed
Expand Down

0 comments on commit 27378c8

Please sign in to comment.