This is a django application to use django as a proxy server between a frontend device/server and a backend server inside a DMZ
Project description
django_proxy_server
===================
This is a django application to use django as a proxy server between a frontend device/server and a backend server inside a militarized zone. Services are exposed using Django REST Framework. To identify itself, django-proxy-server uses the SECRET_KEY variable defined in settings as its API KEY.
Quick start
-----------
Install using pip or easy_install
$ pip install django-proxy-server
$ easy_install django-proxy-server
Add "proxy_server" to your INSTALLED_APPS setting like this:
INSTALLED_APPS = (
...
'proxy_server',
)
Add the following options to the settings.py file to configure:
PROXY_API_KEYS = [
# Add the API KEYS you wish to allow consuming services
# API KEYS are required. Services cannot be consumed without an API KEY
]
# Write the route to the service you wish to use as token validation.
# If you don't wish to have a token validation, skip this setting
PROXY_TOKEN_VALIDATION_SERVICE = 'project.services.token_service'
# The IP or domain address of the backend services to be consumed
BACKEND_HOST = '127.0.0.1'
# The port through which the backend services will be consumed
BACKEND_PORT = '8000'
Usage
-----------
To expose a service using Django, simply decorate a view with
# The option methods is a list of HTTP methods that can be exposed.
# For example: GET, POST, PUT, DELETE
# The option public indicates that the service will be exposed as public,
# thus it doesn't require for the header to include a USER_TOKEN value
@expose_service([ methods ], public=True)
There are two ways of invoking backend services, from a traditional Django view or from an external device that uses Django as a proxy server. The functions to invoke backend services relies on the helper function generate_service_url.
The function generate_service_url allows appending parameters to a URL, as well as encrypting them if the kwarg encrypted is set to True (by default, it is False).
When using traditional Django views, invoke services as follows:
from proxy_server.backend_services import invoke_backend_service
from proxy_server.helpers import generate_service_url
def function(request):
...
response = invoke_backend_service('GET', generate_service_url('/get_user', params={ 'username':'proxy_server_admin' }, encrypted=True), request=request)
...
The invoke_backend_service receives the following parameters:
* method: The method of the service to be invoked
* function_path: The path of the service URL
* json_data: A dictionary with the body content of the service. Default value: empty dict.
* request: The request of the Django view with the information of the user and headers
* response_token: Boolean argument that indicates if a response token is expected. By default, the service expects a token on response.
* public: Boolean argument that indicates if the accessed service is public. By default, the invoked services are not public.
* secure: Boolean argument that indicates if the web service connection must be stablished over HTTPS. By default, the connection is created using HTTP.
When using Django as a proxy server, invoke services as follows:
from proxy_server.decorators import expose_service
from proxy_server.helpers import generate_service_url
from proxy_server.backend_services import invoke_backend_service_as_proxy
import proxy_server
@expose_service(['GET'])
def home(request):
...
response = invoke_backend_service_as_proxy('GET', generate_service_url('/get_user', params={ 'username':'proxy_server_admin' }, encrypted=True), secure=True)
...
The invoke_backend_service_as_proxy receives the following parameters:
* method: The method of the service to be invoked
* function_path: The path of the service URL
* json_data: A dictionary with the body content of the service. Default value: empty dict.
* request: The request of the Django view with the information of the user and headers
* response_token: Boolean argument that indicates if a response token is expected. By default, the service expects a token on response.
* secure: Boolean argument that indicates if the web service connection must be stablished over HTTPS. By default, the connection is created using HTTP.
===================
This is a django application to use django as a proxy server between a frontend device/server and a backend server inside a militarized zone. Services are exposed using Django REST Framework. To identify itself, django-proxy-server uses the SECRET_KEY variable defined in settings as its API KEY.
Quick start
-----------
Install using pip or easy_install
$ pip install django-proxy-server
$ easy_install django-proxy-server
Add "proxy_server" to your INSTALLED_APPS setting like this:
INSTALLED_APPS = (
...
'proxy_server',
)
Add the following options to the settings.py file to configure:
PROXY_API_KEYS = [
# Add the API KEYS you wish to allow consuming services
# API KEYS are required. Services cannot be consumed without an API KEY
]
# Write the route to the service you wish to use as token validation.
# If you don't wish to have a token validation, skip this setting
PROXY_TOKEN_VALIDATION_SERVICE = 'project.services.token_service'
# The IP or domain address of the backend services to be consumed
BACKEND_HOST = '127.0.0.1'
# The port through which the backend services will be consumed
BACKEND_PORT = '8000'
Usage
-----------
To expose a service using Django, simply decorate a view with
# The option methods is a list of HTTP methods that can be exposed.
# For example: GET, POST, PUT, DELETE
# The option public indicates that the service will be exposed as public,
# thus it doesn't require for the header to include a USER_TOKEN value
@expose_service([ methods ], public=True)
There are two ways of invoking backend services, from a traditional Django view or from an external device that uses Django as a proxy server. The functions to invoke backend services relies on the helper function generate_service_url.
The function generate_service_url allows appending parameters to a URL, as well as encrypting them if the kwarg encrypted is set to True (by default, it is False).
When using traditional Django views, invoke services as follows:
from proxy_server.backend_services import invoke_backend_service
from proxy_server.helpers import generate_service_url
def function(request):
...
response = invoke_backend_service('GET', generate_service_url('/get_user', params={ 'username':'proxy_server_admin' }, encrypted=True), request=request)
...
The invoke_backend_service receives the following parameters:
* method: The method of the service to be invoked
* function_path: The path of the service URL
* json_data: A dictionary with the body content of the service. Default value: empty dict.
* request: The request of the Django view with the information of the user and headers
* response_token: Boolean argument that indicates if a response token is expected. By default, the service expects a token on response.
* public: Boolean argument that indicates if the accessed service is public. By default, the invoked services are not public.
* secure: Boolean argument that indicates if the web service connection must be stablished over HTTPS. By default, the connection is created using HTTP.
When using Django as a proxy server, invoke services as follows:
from proxy_server.decorators import expose_service
from proxy_server.helpers import generate_service_url
from proxy_server.backend_services import invoke_backend_service_as_proxy
import proxy_server
@expose_service(['GET'])
def home(request):
...
response = invoke_backend_service_as_proxy('GET', generate_service_url('/get_user', params={ 'username':'proxy_server_admin' }, encrypted=True), secure=True)
...
The invoke_backend_service_as_proxy receives the following parameters:
* method: The method of the service to be invoked
* function_path: The path of the service URL
* json_data: A dictionary with the body content of the service. Default value: empty dict.
* request: The request of the Django view with the information of the user and headers
* response_token: Boolean argument that indicates if a response token is expected. By default, the service expects a token on response.
* secure: Boolean argument that indicates if the web service connection must be stablished over HTTPS. By default, the connection is created using HTTP.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for django-proxy-server-0.1.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd96dca77e8cf66b54b606bad7dfc7b501ad2d4448125024ca1214c4de6236e9 |
|
MD5 | 47ab59cbca743c9ef675a8b6dd905016 |
|
BLAKE2b-256 | b676e1729e700f8c43ac818a28de4ae8b01b14ee50078603716401e2bfdaf037 |
Close
Hashes for django-proxy-server-0.1.5.macosx-10.9-x86_64.exe
Algorithm | Hash digest | |
---|---|---|
SHA256 | f9491779bca94830c9e4025226a607b03390ec8e48dd778916a6d34a42064ee0 |
|
MD5 | f6549740f4a364c9a33cf43224c4a84a |
|
BLAKE2b-256 | cc2d3216d6af4a3b3f4e0851570628529f52ebfaef9cc7b42fdc7b989f7630f0 |