Skip to content

Commit

Permalink
Merge pull request #120 from cisagov/bugfix/fix_run_script
Browse files Browse the repository at this point in the history
Resolve Issue with run Script
  • Loading branch information
mcdonnnj committed Aug 26, 2020
2 parents 830cc7a + b0d6c3c commit c0f3665
Show file tree
Hide file tree
Showing 11 changed files with 608 additions and 365 deletions.
25 changes: 25 additions & 0 deletions .flake8
@@ -0,0 +1,25 @@
[flake8]
max-line-length = 80
# Select (turn on)
# * Complexity violations reported by mccabe (C) -
# http://flake8.pycqa.org/en/latest/user/error-codes.html#error-violation-codes
# * Documentation conventions compliance reported by pydocstyle (D) -
# http://www.pydocstyle.org/en/stable/error_codes.html
# * Default errors and warnings reported by pycodestyle (E and W) -
# https://pycodestyle.readthedocs.io/en/latest/intro.html#error-codes
# * Default errors reported by pyflakes (F) -
# http://flake8.pycqa.org/en/latest/glossary.html#term-pyflakes
# * Default warnings reported by flake8-bugbear (B) -
# https://github.com/PyCQA/flake8-bugbear#list-of-warnings
# * The B950 flake8-bugbear opinionated warning -
# https://github.com/PyCQA/flake8-bugbear#opinionated-warnings
select = C,D,E,F,W,B,B950
# Ignore flake8's default warning about maximum line length, which has
# a hard stop at the configured value. Instead we use
# flake8-bugbear's B950, which allows up to 10% overage.
#
# Also ignore flake8's warning about line breaks before binary
# operators. It no longer agrees with PEP8. See, for example, here:
# https://github.com/ambv/black/issues/21. Guido agrees here:
# https://github.com/python/peps/commit/c59c4376ad233a62ca4b3a6060c81368bd21e85b.
ignore = E501,W503
19 changes: 8 additions & 11 deletions .travis.yml
@@ -1,5 +1,7 @@
language: python

dist: xenial

services:
- docker

Expand All @@ -9,22 +11,17 @@ env:
- DOCKER_USER=jsf9k
- secure: "IAbtmubLq2hL71aollQEfoV+t9Zbqn4rNVqi5YNerqxvXr6WiDzwmYUujOCnQiHli8xkIU0J8OSPX0aA4cOTxPGiZeNguGuVWmR2ZCB8SMyjbKJOEIpLZv/jG1Be6dVXiJwKwQM3yX4pqPfLIuYkE6S1GAodudPzcJ8xM/h1qzJijknJEqsCJQw43zSHZ/epYulgWcmnCAmaoehZTCjVcW4l8iyVHSNfgO7gu5iWC9y4AIIX96E9TZkSDeud1yqUcORMwfdOl2pHhDh3KnF8HZSOCetTHP7JacLUMJiiCpKN34Xn9RQgjbVKOrF/rcC8WEDrWKn14SFfgUP0dl6lCr6P9HE4aHKvrH/nCyflFOANbEKMywE8DzNA3zd7MC0HQkyb40LAiBSbTD58myUsc+WlmaZyvpJ7akukbmVjVPQWNvs1laz/bqyLdPh4WMqgOTbP7BrgDeIrCVedwdvhqq9KEaoak8RBs/Wb8LisI6j+vAY/HKlVnuIXRL0RNGTko96kBluEpAsWDjls39Hmu5hl1glbqCWDW9+dE0/Zx4MuSt4OVAywMW+lzxA16SdqDLCZqGv00vnPpxuBAvEEQbVtsmQ6lR+fwTYKFEDZM7axRwBlLzIDEzSoz4K0fSq3EuU4mkoVZKcHGnuHuRqaNhce0zzZx3lHdNTm7oa7b0U="

# Matrix approach here due to: https://github.com/travis-ci/travis-ci/issues/9815
matrix:
include:
- python: 3.6
dist: xenial
sudo: true
- python: 3.7
dist: xenial
sudo: true
python:
- 3.6
- 3.7
- 3.8

before_install:
- sudo apt-get install -y shellcheck

install:
- pip install flake8 pytest-cov pytest coveralls
- pip install -e .
- pip install --editable .

script:
- shellcheck bump_version.sh tag.sh travis_scripts/*.sh
Expand All @@ -43,7 +40,7 @@ deploy:
distributions: sdist bdist_wheel
on:
tags: true
python: '3.7'
python: '3.8'
# - provider: script
# script: bash travis_scripts/deploy_to_docker_hub.sh
# on:
Expand Down
16 changes: 13 additions & 3 deletions Dockerfile
Expand Up @@ -2,11 +2,21 @@ FROM python:3

WORKDIR /app

COPY requirements.txt requirements.txt
RUN pip install --no-cache-dir --upgrade pip setuptools wheel

RUN pip install --no-cache-dir -r requirements.txt
COPY requirements.txt .

COPY . .
RUN pip install --no-cache-dir --requirement requirements.txt

COPY scripts/ scripts/

COPY trustymail/ trustymail/

COPY README.md .

COPY requirements-dev.txt .

COPY setup.py .

RUN pip install --editable .

Expand Down
16 changes: 12 additions & 4 deletions bump_version.sh
Expand Up @@ -10,7 +10,7 @@ VERSION_FILE=trustymail/__init__.py

HELP_INFORMATION="bump_version.sh (show|major|minor|patch|prerelease|build|finalize)"

old_version=$(sed -n "s/^__version__ = '\(.*\)'$/\1/p" $VERSION_FILE)
old_version=$(sed -n "s/^__version__ = \"\(.*\)\"$/\1/p" $VERSION_FILE)

if [ $# -ne 1 ]
then
Expand All @@ -20,17 +20,25 @@ else
major|minor|patch|prerelease|build)
new_version=$(python -c "import semver; print(semver.bump_$1('$old_version'))")
echo Changing version from "$old_version" to "$new_version"
sed -i "s/$old_version/$new_version/" $VERSION_FILE
# A temp file is used to provide compatability with macOS development
# as a result of macOS using the BSD version of sed
tmp_file=/tmp/version.$$
sed "s/$old_version/$new_version/" $VERSION_FILE > $tmp_file
mv $tmp_file $VERSION_FILE
git add $VERSION_FILE
git commit -m"Bump version from $old_version to $new_version"
git push
;;
finalize)
new_version=$(python -c "import semver; print(semver.finalize_version('$old_version'))")
echo Changing version from "$old_version" to "$new_version"
sed -i "s/$old_version/$new_version/" $VERSION_FILE
# A temp file is used to provide compatability with macOS development
# as a result of macOS using the BSD version of sed
tmp_file=/tmp/version.$$
sed "s/$old_version/$new_version/" $VERSION_FILE > $tmp_file
mv $tmp_file $VERSION_FILE
git add $VERSION_FILE
git commit -m"Finalize version from $old_version to $new_version"
git commit -m"Bump version from $old_version to $new_version"
git push
;;
show)
Expand Down
6 changes: 4 additions & 2 deletions run
Expand Up @@ -7,5 +7,7 @@ docker build -t trustymail/cli .

docker run --rm -it \
--name trustymail \
-v $(pwd):/app \
trustymail/cli $@
--volume "$(pwd)":/workspace \
--workdir="/workspace" \
--user "$(id -u)" \
trustymail/cli "$@"
90 changes: 49 additions & 41 deletions scripts/trustymail
Expand Up @@ -68,97 +68,105 @@ def main():
args = docopt.docopt(__doc__, version=trustymail.__version__)

# Monkey patching trustymail to make it cache the PSL where we want
if args['--psl-filename'] is not None:
trustymail.PublicSuffixListFilename = args['--psl-filename']
if args["--psl-filename"] is not None:
trustymail.PublicSuffixListFilename = args["--psl-filename"]
# Monkey patching trustymail to make the PSL cache read-only
if args['--psl-read-only']:
if args["--psl-read-only"]:
trustymail.PublicSuffixListReadOnly = True
import trustymail.trustymail as tmail

log_level = logging.WARN
if args['--debug']:
if args["--debug"]:
log_level = logging.DEBUG
logging.basicConfig(format='%(asctime)-15s %(message)s', level=log_level)
logging.basicConfig(format="%(asctime)-15s %(message)s", level=log_level)

# Allow for user to input a csv for many domain names.
if args['INPUT'][0].endswith('.csv'):
domains = tmail.domain_list_from_csv(open(args['INPUT'][0]))
if args["INPUT"][0].endswith(".csv"):
domains = tmail.domain_list_from_csv(open(args["INPUT"][0]))
else:
domains = args['INPUT']
domains = args["INPUT"]

if args['--timeout'] is not None:
timeout = int(args['--timeout'])
if args["--timeout"] is not None:
timeout = int(args["--timeout"])
else:
timeout = 5

if args['--smtp-timeout'] is not None:
smtp_timeout = int(args['--smtp-timeout'])
if args["--smtp-timeout"] is not None:
smtp_timeout = int(args["--smtp-timeout"])
else:
smtp_timeout = 5

if args['--smtp-localhost'] is not None:
smtp_localhost = args['--smtp-localhost']
if args["--smtp-localhost"] is not None:
smtp_localhost = args["--smtp-localhost"]
else:
smtp_localhost = None

if args['--smtp-ports'] is not None:
smtp_ports = {int(port) for port in args['--smtp-ports'].split(',')}
if args["--smtp-ports"] is not None:
smtp_ports = {int(port) for port in args["--smtp-ports"].split(",")}
else:
smtp_ports = _DEFAULT_SMTP_PORTS

if args['--dns'] is not None:
dns_hostnames = args['--dns'].split(',')
if args["--dns"] is not None:
dns_hostnames = args["--dns"].split(",")
else:
dns_hostnames = None

# --starttls implies --mx
if args['--starttls']:
args['--mx'] = True
if args["--starttls"]:
args["--mx"] = True

# User might not want every scan performed.
scan_types = {
'mx': args['--mx'],
'starttls': args['--starttls'],
'spf': args['--spf'],
'dmarc': args['--dmarc']
"mx": args["--mx"],
"starttls": args["--starttls"],
"spf": args["--spf"],
"dmarc": args["--dmarc"],
}

domain_scans = []
for domain_name in domains:
domain_scans.append(tmail.scan(domain_name, timeout,
smtp_timeout, smtp_localhost,
smtp_ports, not args['--no-smtp-cache'],
scan_types, dns_hostnames))
domain_scans.append(
tmail.scan(
domain_name,
timeout,
smtp_timeout,
smtp_localhost,
smtp_ports,
not args["--no-smtp-cache"],
scan_types,
dns_hostnames,
)
)

# Default output file name is results.
if args['--output'] is None:
output_file_name = 'results'
if args["--output"] is None:
output_file_name = "results"
else:
output_file_name = args['--output']
output_file_name = args["--output"]

# Ensure file extension is present in filename.
if args['--json'] and '.json' not in output_file_name:
output_file_name += '.json'
elif '.csv' not in output_file_name:
output_file_name += '.csv'
if args["--json"] and ".json" not in output_file_name:
output_file_name += ".json"
elif ".csv" not in output_file_name:
output_file_name += ".csv"

if args['--json']:
if args["--json"]:
json_out = tmail.generate_json(domain_scans)
if args['--output'] is None:
if args["--output"] is None:
print(json_out)
else:
write(json_out, output_file_name)
logging.warn('Wrote results to %s.' % output_file_name)
logging.warn("Wrote results to %s." % output_file_name)
else:
tmail.generate_csv(domain_scans, output_file_name)


def write(content, out_file):
parent = os.path.dirname(out_file)
if parent is not '':
if parent != "":
mkdir_p(parent)

f = open(out_file, 'w') # no utf-8 in python 2
f = open(out_file, "w") # no utf-8 in python 2
f.write(content)
f.close()

Expand All @@ -175,5 +183,5 @@ def mkdir_p(path):
raise


if __name__ == '__main__':
if __name__ == "__main__":
main()
58 changes: 23 additions & 35 deletions setup.py
Expand Up @@ -11,67 +11,55 @@


def readme():
with open('README.md') as f:
with open("README.md") as f:
return f.read()


with open('requirements.txt') as fp:
with open("requirements.txt") as fp:
reqs = [line.strip() for line in fp.readlines() if line]

with open('requirements-dev.txt') as fp:
with open("requirements-dev.txt") as fp:
lines = [line.strip() for line in fp.readlines() if line]
dev_reqs = [line for line in lines if line and '-r requirements.txt' not in line]
dev_reqs = [line for line in lines if line and "-r requirements.txt" not in line]


setup(
name='trustymail',
name="trustymail",
version=__version__,
description='Scan domains and return data based on trustworthy email best practices',
description="Scan domains and return data based on trustworthy email best practices",
long_description=readme(),
long_description_content_type='text/markdown',

long_description_content_type="text/markdown",
# NCATS "homepage"
url="https://www.us-cert.gov/resources/ncats",
# The project's main homepage
download_url='https://github.com/cisagov/trustymail',

download_url="https://github.com/cisagov/trustymail",
# Author details
author='Cyber and Infrastructure Security Agency',
author_email='ncats@hq.dhs.gov',

license='License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication',

author="Cyber and Infrastructure Security Agency",
author_email="ncats@hq.dhs.gov",
license="License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication",
# See https://pypi.python.org/pypi?%3Aaction=list_classifiers
classifiers=[
# How mature is this project? Common values are
# 3 - Alpha
# 4 - Beta
# 5 - Production/Stable
'Development Status :: 4 - Beta',

"Development Status :: 4 - Beta",
# Indicate who your project is intended for
'Intended Audience :: Developers',

"Intended Audience :: Developers",
# Pick your license as you wish (should match "license" above)
'License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication',

"License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication",
# Specify the Python versions you support here. In particular, ensure
# that you indicate whether you support Python 2, Python 3 or both.
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
],

python_requires=">=3.6",
# What does your project relate to?
keywords='email authentication, STARTTLS',

packages=['trustymail'],

keywords="email authentication, STARTTLS",
packages=["trustymail"],
install_requires=reqs,

extras_require={
'dev': dev_reqs,
},

scripts=['scripts/trustymail']
extras_require={"dev": dev_reqs},
scripts=["scripts/trustymail"],
)
2 changes: 1 addition & 1 deletion tox.ini
@@ -1,5 +1,5 @@
[tox]
envlist = py34,py35,py36,py37,flake8
envlist = py36,py37,py38,flake8
skip_missing_interpreters = true
; usedevelop = true

Expand Down

0 comments on commit c0f3665

Please sign in to comment.