From 6bb28b0d44a444f766b5cfb446e07c3407a99aab Mon Sep 17 00:00:00 2001 From: Khaled Hussein Date: Mon, 18 Apr 2011 18:39:38 +0000 Subject: Setup PasteDeploy and configured PAPIAuth. --- echo/echo/__init__.py | 0 echo/echo/echo.ini | 23 ++++++++++++++++++----- echo/echo/echo.py | 48 ++++++++++++++++++++---------------------------- echo/setup.py | 41 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 79 insertions(+), 33 deletions(-) create mode 100644 echo/echo/__init__.py create mode 100644 echo/setup.py (limited to 'echo') diff --git a/echo/echo/__init__.py b/echo/echo/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/echo/echo/echo.ini b/echo/echo/echo.ini index 3446aa8d..0d38c6e7 100644 --- a/echo/echo/echo.ini +++ b/echo/echo/echo.ini @@ -1,7 +1,20 @@ - -[composite:main] -use = egg:Paste#urlmap -/ = echo +[DEFAULT] [app:echo] -use egg:echo +use = egg:echo +#use = egg:Paste#urlmap +#/ = echo + +[pipeline:main] +pipeline = papiauth echo + +[filter:papiauth] +use = egg:keystone#papiauth +ip = 127.0.0.1 +port = 1234 +pass = dTpw + +[server:main] +use = egg:Paste#http +host = 0.0.0.0 +port = 8090 diff --git a/echo/echo/echo.py b/echo/echo/echo.py index 5cb4b2b7..efe24445 100644 --- a/echo/echo/echo.py +++ b/echo/echo/echo.py @@ -25,7 +25,6 @@ import urllib from httplib2 import Http - class EchoApp: def __init__(self, environ, start_response): @@ -37,35 +36,25 @@ class EchoApp: def __iter__(self): accept = self.envr.get("HTTP_ACCEPT","application/json") if accept == "application/xml": - return self.toXML() else: return self.toJSON() def toJSON(self): - self.start('200 OK', [('Content-Type', 'application/json')]) token = str(self.envr.get("HTTP_X_AUTH_TOKEN","")) if token !='': - res=self.ValidateToken({'type':'json','token':token}) - if int(res['response']['status'])==200 : - yield str(res['content']) else: pass # Need to Do Something Here else: - yield str(self.transform(self.dom)) - - - def toXML(self): - self.start('200 OK', [('Content-Type', 'application/xml')]) yield etree.tostring (self.dom) @@ -74,7 +63,8 @@ class EchoApp: method=environ["REQUEST_METHOD"], pathInfo=environ["PATH_INFO"], queryString=environ.get('QUERY_STRING', "")) - content = etree.Element("{http://docs.openstack.org/echo/api/v1.0}content") + content = etree.Element( + "{http://docs.openstack.org/echo/api/v1.0}content") content.set ("type", environ["CONTENT_TYPE"]) content.text = "" inReq = environ["wsgi.input"] @@ -83,22 +73,24 @@ class EchoApp: echo.append (content) return echo - - def ValidateToken(self,params): - - - if params['token']: - - http=Http() - - url = "http://localhost:8080/token/"+str(params['token']) - body = {} - headers = {"Accept" : "application/json", "Content-Type": "application/json"} - response, content = http.request(url, 'GET', headers=headers, body=urllib.urlencode(body)) - return {'response':response,'content':content} - else: - return abort(401, "No Token Found!") + + #def ValidateToken(self,params): + # if params['token']: + # http=Http() + # url = "http://localhost:8080/token/"+str(params['token']) + # body = {} + # headers = { + # "Accept" : "application/json", + # "Content-Type": "application/json"} + # response, content = http.request(url, 'GET', headers=headers, + # body=urllib.urlencode(body)) + # return {'response':response,'content':content} + # else: + # return abort(401, "No Token Found!") -wsgi.server(eventlet.listen(('127.0.0.1', 8090)), EchoApp) +def app_factory (global_conf, **local_conf): + return EchoApp + +#wsgi.server(eventlet.listen(('127.0.0.1', 8090)), EchoApp) #wsgi.server(eventlet.listen(('', 8090)), loadapp("config:echo.ini", relative_to=".")) diff --git a/echo/setup.py b/echo/setup.py new file mode 100644 index 00000000..4aaca425 --- /dev/null +++ b/echo/setup.py @@ -0,0 +1,41 @@ +#!/usr/bin/python +# Copyright (c) 2010-2011 OpenStack, LLC. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or +# implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +from setuptools import setup, find_packages + +version = '1.0' + +setup( + name='echo', + version=version, + description="", + license='Apache License (2.0)', + classifiers=[ "Programming Language :: Python", ], + keywords='', + author='OpenStack, LLC.', + author_email='none of your beeswax@somehost.com', + url='http://lionfacelemonface.wordpress.com', + include_package_data=True, + packages=find_packages(exclude=['test', 'bin']), + zip_safe=False, + install_requires=['setuptools', 'keystone'], + entry_points={ + 'paste.app_factory': ['main=echo.echo:app_factory'], + 'paste.filter_factory': [ + 'papiauth=keystone.middleware.papiauth:filter_factory', + ], + }, + ) -- cgit