Skip to content
This repository has been archived by the owner on Oct 11, 2022. It is now read-only.

Commit

Permalink
Updated docs
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlaLlama committed Feb 8, 2016
1 parent b6939d1 commit 80772e4
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 30 deletions.
64 changes: 60 additions & 4 deletions docs/http-proxy.rst
Original file line number Diff line number Diff line change
@@ -1,15 +1,71 @@
vumi-http-proxy Package
=======================
vumi_http_proxy Package Docs
============================

Class Documentation

http_proxy Module
^^^^^^^^^^^^^^^^^

.. automodule:: vumi_http_proxy.http_proxy


.. py:module:: vumi_http_proxy.http_proxy
.. autoclass:: CheckProxyRequest
:members:
:undoc-members:
:show-inheritance:

.. autoclass:: Initialize
:members:
:undoc-members:
:show-inheritance:

.. autoclass:: Proxy
:members:
:undoc-members:
:show-inheritance:

.. autoclass:: ProxyFactory
:members:
:undoc-members:
:show-inheritance:

.. autoclass:: CheckProxyRequest
.. autoclass:: StringProducer
:members:
:undoc-members:
:show-inheritance:


queen-of-ni Module
^^^^^^^^^^^^^^^^^^

.. automodule:: vumi_http_proxy.queen_of_ni
:members:

.. autoclass:: cli
:members:
:undoc-members:
:show-inheritance:


servicemaker Module
^^^^^^^^^^^^^^^^^^^

.. automodule:: vumi_http_proxy.servicemaker
:members:

.. autoclass:: Options
:members:
:undoc-members:
:show-inheritance:

.. autoclass:: ProxyWorkerServiceMaker
:members:
:undoc-members:
:show-inheritance:


config_reader Module
^^^^^^^^^^^^^^^^^^^^

.. automodule:: vumi_http_proxy.config_reader
:members:
19 changes: 1 addition & 18 deletions docs/project-outline.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,4 @@ Vumi’s Javascript sandbox allows application developers to access HTTP
resources, we need a proxy that intercepts these outbound HTTP calls and checks
whether the calls to the specified resources are allowed or not. This boils down
to maintaining a blacklist of disallowed HTTP resources and per request checking
against the blacklist.

And now for something completely different::

░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄░░░░░░░░░
░░░░░░░░▄▀░░░░░░░░░░░░▄░░░░░░░▀▄░░░░░░░
░░░░░░░░█░░▄░░░░▄░░░░░░░░░░░░░░█░░░░░░░
░░░░░░░░█░░░░░░░░░░░░▄█▄▄░░▄░░░█░▄▄▄░░░
░▄▄▄▄▄░░█░░░░░░▀░░░░▀█░░▀▄░░░░░█▀▀░██░░
░██▄▀██▄█░░░▄░░░░░░░██░░░░▀▀▀▀▀░░░░██░░
░░▀██▄▀██░░░░░░░░▀░██▀░░░░░░░░░░░░░▀██░
░░░░▀████░▀░░░░▄░░░██░░░▄█░░░░▄░▄█░░██░
░░░░░░░▀█░░░░▄░░░░░██░░░░▄░░░▄░░▄░░░██░
░░░░░░░▄█▄░░░░░░░░░░░▀▄░░▀▀▀▀▀▀▀▀░░▄▀░░
░░░░░░█▀▀█████████▀▀▀▀████████████▀░░░░
░░░░░░████▀░░███▀░░░░░░▀███░░▀██▀░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
against the blacklist.
34 changes: 26 additions & 8 deletions vumi_http_proxy/http_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ def buildProtocol(self, addr):


class CheckProxyRequest(proxy.ProxyRequest):
"""
Receives request, processes request and returns response
"""
def process(self):
""" Attain hostname, return deferred on resolver.getHostByName
"""
host, _, port = self.getAllHeaders()['host'].partition(':')
d = self.channel.resolver.getHostByName(host)
d.addCallback(self.setIP, host)
Expand All @@ -42,6 +47,9 @@ def handleError(self, failure):
return

def setIP(self, ip_addr, host):
"""
Process corresponding ip address to allow or deny.
"""
if not ip_addr:
self.setResponseCode(400)
self.write("<html>ERROR: No IP adresses found for name %r" %
Expand All @@ -61,6 +69,9 @@ def setIP(self, ip_addr, host):
return d

def replaceHostWithIP(self, uri, ip_addr):
"""
Parse request to find host, replace with IP and port (if applicable).
"""
scheme, netloc, path, params, query, fragment = urlparse(uri)
_, _, port = netloc.partition(':')
if port:
Expand All @@ -69,6 +80,9 @@ def replaceHostWithIP(self, uri, ip_addr):

@inlineCallbacks
def sendResponseBack(self, r):
"""
Fetch response and response code, send to client.
"""
self.setResponseCode(r.code)
for key, value in r.headers.getAllRawHeaders():
self.responseHeaders.addRawHeader(key, value)
Expand All @@ -78,6 +92,9 @@ def sendResponseBack(self, r):


class StringProducer(object):
"""
Parse response body.
"""
def __init__(self, body):
self.body = body
self.length = len(body)
Expand All @@ -94,7 +111,9 @@ def stopProducing(self):


class Proxy(proxy.Proxy):

"""
Start proxy with CheckProxyRequest as requestFactory.
"""
requestFactory = CheckProxyRequest

def __init__(self, blacklist, resolver, http_client):
Expand All @@ -109,6 +128,12 @@ class Initialize(object):
This class initialises the proxy based on the configuration specified
"""
def __init__(self, blacklist, dnsservers, ip, port):
self.blacklist = blacklist
self.dnsservers = dnsservers
self.ip = ip
self.port = port

def main(self):
"""
:param blacklist: List of disallowed ip addresses.
:type blacklist: list
Expand All @@ -119,13 +144,6 @@ def __init__(self, blacklist, dnsservers, ip, port):
:param port: Port of server to initialize proxy
:type port: int
"""
self.blacklist = blacklist
self.dnsservers = dnsservers
self.ip = ip
self.port = port

def main(self):

resolver = client.createResolver(self.dnsservers)
http_client = Agent(reactor)
factory = ProxyFactory(self.blacklist, resolver, http_client)
Expand Down

0 comments on commit 80772e4

Please sign in to comment.