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

Commit

Permalink
Simplify package versioning
Browse files Browse the repository at this point in the history
Add VERSION file containing the version string, e.g. 0.1.3, which will
be read in setup.py and securedrop_proxy/version.py. Now we just have
to remember to update the package version in one place.

Add a test making sure that the proxy reports the same version used in
setup.py.
  • Loading branch information
rmol committed Apr 15, 2019
1 parent a844e02 commit 6a8972a
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 26 deletions.
11 changes: 6 additions & 5 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
include securedrop_proxy/*.py
include requirements.txt
include README.md
include LICENSE
include setup.py
include Pipfile
include Pipfile.lock
include qubes/securedrop.Proxy
include README.md
include VERSION
include config-example.yaml
include qubes/securedrop.Proxy
include requirements.txt
include securedrop_proxy/*.py
include setup.py
1 change: 1 addition & 0 deletions securedrop_proxy/VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.1.3
28 changes: 15 additions & 13 deletions securedrop_proxy/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,26 @@
import json
import werkzeug

class Req:
import securedrop_proxy.version as version


class Req:
def __init__(self):
self.method = ''
self.path_query = ''
self.method = ""
self.path_query = ""
self.body = None
self.headers = {}

class Response:

class Response:
def __init__(self, status):
self.status = status
self.body = None
self.headers = {}
self.version = "0.1.2"
self.version = version.version

class Proxy:

class Proxy:
@staticmethod
def _on_done(res):
print(json.dumps(res.__dict__))
Expand Down Expand Up @@ -63,15 +65,15 @@ def prep_request(self):
method = self.req.method

if not self.valid_path(path):
self.simple_error(400, 'Path provided in request did not look valid')
raise ValueError('Path provided was invalid')
self.simple_error(400, "Path provided in request did not look valid")
raise ValueError("Path provided was invalid")

try:
url = furl.furl("{}://{}:{}/{}".format(scheme, host, port, path))
except Exception as e:

self.simple_error(500, 'Proxy error while generating URL to request')
raise ValueError('Error generating URL from provided values')
self.simple_error(500, "Proxy error while generating URL to request")
raise ValueError("Error generating URL from provided values")

url.path.normalize()

Expand Down Expand Up @@ -113,7 +115,7 @@ def handle_non_json_response(self):

def handle_response(self):

ctype = werkzeug.http.parse_options_header(self._presp.headers['content-type'])
ctype = werkzeug.http.parse_options_header(self._presp.headers["content-type"])

if ctype[0] == "application/json":
self.handle_json_response()
Expand All @@ -128,8 +130,8 @@ def proxy(self):

try:
if self.on_save is None:
self.simple_error(400, 'Request callback is not set.')
raise ValueError('Request callback is not set.')
self.simple_error(400, "Request callback is not set.")
raise ValueError("Request callback is not set.")

self.prep_request()
s = requests.Session()
Expand Down
3 changes: 3 additions & 0 deletions securedrop_proxy/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import pkgutil

version = pkgutil.get_data("securedrop_proxy", "VERSION").decode("utf-8")
13 changes: 6 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import pkgutil
import setuptools

with open("README.md", "r") as fh:
long_description = fh.read()

version = pkgutil.get_data("securedrop_proxy", "VERSION").decode("utf-8")

setuptools.setup(
name="securedrop-proxy",
version="0.1.3",
version=version,
author="Freedom of the Press Foundation",
author_email="securedrop@freedom.press",
description="SecureDrop Qubes proxy service",
long_description=long_description,
long_description_content_type="text/markdown",
license="GPLv3+",
install_requires=["requests","furl", "pyyaml", "werkzeug"],
install_requires=["requests", "furl", "pyyaml", "werkzeug"],
python_requires=">=3.5",
url="https://github.com/freedomofpress/securedrop-proxy",
packages=setuptools.find_packages(exclude=["docs", "tests"]),
Expand All @@ -24,9 +27,5 @@
"Intended Audience :: Developers",
"Operating System :: OS Independent",
),
entry_points={
'console_scripts': [
'sd-proxy = securedrop_proxy.entrypoint:start',
],
},
entry_points={"console_scripts": ["sd-proxy = securedrop_proxy.entrypoint:start"]},
)
13 changes: 12 additions & 1 deletion tests/test_proxy.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import json
import subprocess
import vcr
import unittest
import uuid

from securedrop_proxy import proxy
from securedrop_proxy import config
from securedrop_proxy import version


class TestProxyValidConfig(unittest.TestCase):
Expand All @@ -25,6 +25,17 @@ def on_done(self, res):
res.headers['X-Origin-Content-Type'] = res.headers['Content-Type']
res.headers['Content-Type'] = 'application/json'

def test_version(self):
req = proxy.Req()
req.method = 'GET'
req.path_query = ''
req.headers = {'Accept': 'application/json'}

p = proxy.Proxy()
p.proxy()

self.assertEqual(p.res.version, version.version)

def test_400_if_callback_not_set(self):
req = proxy.Req()
req.method = 'GET'
Expand Down

0 comments on commit 6a8972a

Please sign in to comment.