Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Sprint12 #1

Merged
merged 3 commits into from
May 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
FROM debian:stretch
FROM weboaks/node-karma-protractor-chrome
# FROM debian:stretch

ENV PATH /usr/local/bin:$PATH

RUN apt-get update && \
apt-get install -y --no-install-recommends libffi-dev \
build-essential checkinstall libreadline-gplv2-dev \
libncursesw5-dev libssl-dev libsqlite3-dev tk-dev \
libgdbm-dev libc6-dev libbz2-dev \
libgdbm-dev libc6-dev libbz2-dev wkhtmltopdf xvfb xauth \
locales gcc libc6 libgcc1 libstdc++6 pdftk apt-utils \
tk-dev uuid-dev wget ca-certificates gnupg dirmngr && \
rm -rf /var/lib/apt/lists/* \
&& localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8

ENV LANG en_US.utf8


ENV GPG_KEY 0D96DF4D4110E5C43FBFB17F2D347EA6AA65421D
ENV PYTHON_VERSION 3.7.2

Expand Down Expand Up @@ -62,6 +64,7 @@ RUN set -ex; \
--no-cache-dir \
"pip==$PYTHON_PIP_VERSION" \
; \
pip install --upgrade pip \
pip --version; \
\
find /usr/local -depth \
Expand All @@ -77,9 +80,14 @@ RUN mkdir /opt/imagegenerator
WORKDIR /opt/imagegenerator
ADD . /opt/imagegenerator
RUN pip install -r requirements.txt

# remove the default xvfb-run file and replace it with our own.
RUN rm /usr/bin/xvfb-run
ADD ./xvfb-run /usr/bin/
ADD ./wkhtmltopdf.sh /usr/bin/
RUN chmod a+x /usr/bin/wkhtmltopdf.sh && ln -s /usr/bin/wkhtmltopdf.sh /usr/local/bin/wkhtmltopdf
#RUN flake8 .


EXPOSE 8080
ENTRYPOINT ["gunicorn", "-w", "4", "--bind", "0.0.0.0:8080", "wsgi:APP"]

Expand Down
113 changes: 59 additions & 54 deletions config.py
Original file line number Diff line number Diff line change
@@ -1,54 +1,59 @@
"""
Flask settings for fecfile-ImageGenerator project.

"""

import os
import tempfile

# Set the temporary directory
tempfile.tempdir = "temp"

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)

BASE_DIR = os.path.dirname(os.path.dirname(__file__))
DEBUG = os.environ.get("DEBUG", True)
ALLOWED_HOSTS = ["*"]

FORM_TEMPLATES_LOCATION = "templates/forms/{}.pdf"
REQUEST_FILE_LOCATION = "temp/json/{}.json"
# OUTPUT_FILE_LOCATION = 'output/pdf/{}.pdf'
OUTPUT_DIR_LOCATION = "output/pdf/{}/"
# ATTACHMENT_FILE_LOCATION = 'temp/{}.pdf'

# AWS settings

# AWS SES Configuration Settings

# AWS_ACCESS_KEY_ID = os.environ.get('ACCESS_KEY', None)
# AWS_SECRET_ACCESS_KEY = os.environ.get('SECRET_KEY', None)
# AWS_HOST_NAME = 'us-east-1'
# AWS_REGION = 'us-east-1'
AWS_SES_AUTO_THROTTLE = (
0.5
) # (default; safety factor applied to rate limit, turn off automatic throttling, set this to None)

# AWS FECFile components bucket name
AWS_FECFILE_COMPONENTS_BUCKET_NAME = "fecfile-dev-components"

# if False it will create unique file names for every uploaded file
AWS_S3_FILE_OVERWRITE = True
# the url, that your uploaded JSON and print output will be available at
AWS_S3_FECFILE_COMPONENTS_DOMAIN = (
"%s.s3.amazonaws.com" % AWS_FECFILE_COMPONENTS_BUCKET_NAME
)

# the sub-directories of temp and output files
# TEMP_FILES_LOCATION = 'temp'
# OUTPUT_FILE_FOLDER = 'output'

# TEMP_FILES_URL = "https://%s/%s/{}" % (AWS_S3_FECFILE_COMPONENTS_DOMAIN, TEMP_FILES_LOCATION)
PRINT_OUTPUT_FILE_URL = "https://%s/%s" % (
AWS_S3_FECFILE_COMPONENTS_DOMAIN,
OUTPUT_DIR_LOCATION,
)
"""
Flask settings for fecfile-ImageGenerator project.

"""

import os
import tempfile

# Set the temporary directory
tempfile.tempdir = "temp"

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)

BASE_DIR = os.path.dirname(os.path.dirname(__file__))
DEBUG = os.environ.get("DEBUG", True)
ALLOWED_HOSTS = ["*"]


FORM_TEMPLATES_LOCATION = 'templates/forms/{}.pdf'
HTML_FORM_TEMPLATES_LOCATION = 'templates/forms/F99/{}.html'
FORMS_LOCATION = 'templates/forms/{}'
REQUEST_FILE_LOCATION = 'temp/json/{}.json'
# OUTPUT_FILE_LOCATION = 'output/pdf/{}.pdf'
OUTPUT_DIR_LOCATION = "output/pdf/{}/"

# ATTACHMENT_FILE_LOCATION = 'temp/{}.pdf'

# AWS settings

# AWS SES Configuration Settings

# AWS_ACCESS_KEY_ID = os.environ.get('ACCESS_KEY', None)
# AWS_SECRET_ACCESS_KEY = os.environ.get('SECRET_KEY', None)
# AWS_HOST_NAME = 'us-east-1'
# AWS_REGION = 'us-east-1'
AWS_SES_AUTO_THROTTLE = (
0.5
) # (default; safety factor applied to rate limit, turn off automatic throttling, set this to None)

# AWS FECFile components bucket name
AWS_FECFILE_COMPONENTS_BUCKET_NAME = "fecfile-dev-components"

# if False it will create unique file names for every uploaded file
AWS_S3_FILE_OVERWRITE = True
# the url, that your uploaded JSON and print output will be available at
AWS_S3_FECFILE_COMPONENTS_DOMAIN = (
"%s.s3.amazonaws.com" % AWS_FECFILE_COMPONENTS_BUCKET_NAME
)

# the sub-directories of temp and output files
# TEMP_FILES_LOCATION = 'temp'
# OUTPUT_FILE_FOLDER = 'output'

# TEMP_FILES_URL = "https://%s/%s/{}" % (AWS_S3_FECFILE_COMPONENTS_DOMAIN, TEMP_FILES_LOCATION)
PRINT_OUTPUT_FILE_URL = "https://%s/%s" % (AWS_S3_FECFILE_COMPONENTS_DOMAIN, OUTPUT_DIR_LOCATION)

FECFILE_UTIL_PRINT_API_URL = os.environ.get('FECFILE_UTIL_URL', 'https://dev-efile-api.efdev.fec.gov/printpdf')
FECFILE_UTIL_API_VERSION = "/v1/fecfileutil"

4 changes: 4 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
BeautifulSoup4==4.7.1
certifi==2018.10.15
chardet==3.0.4
Click==7.0
Expand All @@ -15,12 +16,15 @@ requests==2.21.0
six==1.11.0
urllib3==1.24.2
Werkzeug==0.14.1
WeasyPrint==47

pypdftk==0.4
boto3==1.9.40
botocore==1.12.79
Flask-API==1.1
PyPDF2==1.26.0
pdfkit==0.6.1
beautifulsoup4==4.7.1

gunicorn==19.9.0
flake8==3.6.0
32 changes: 28 additions & 4 deletions routes/src/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from flask import request
from flask_cors import CORS
from routes.src import tmoflask, form99
from routes.src import tmoflask, form99, form3x

logger = logging.getLogger()

Expand All @@ -29,6 +29,30 @@ def print_pdf():
"success": "true"
}
"""
form_type = request.form["form_type"]
if form_type == "F99":
return form99.print_f99_pdftk()
form_type = request.form['form_type']
if form_type == 'F99':
return form99.print_f99_pdftk_html('')
elif form_type == 'F3X':
return form3x.print_pdftk('')

@app.route('/stamp_print', methods=['POST'])
def stamp_print_pdf():
"""
This function is being invoked from FECFile and Vendors
HTTP request needs to have form_type, file, and attachment_file
form_type : F99
json_file: please refer to below sample JSON
:return: return JSON response
sample:
{
"message": "",
"results": {
"pdf_url": "https://fecfile-dev-components.s3.amazonaws.com/output/bd78435a70a70d656145dae89e0e22bb.pdf"
},
"success": "true"
}
"""
form_type = request.form['form_type']
if form_type == 'F99':
return form99.print_f99_pdftk_html('stamp')

Loading