summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbsirish <sirish.bitra@gmail.com>2011-04-18 19:26:30 +0530
committerbsirish <sirish.bitra@gmail.com>2011-04-18 19:26:30 +0530
commit38318ba95f4e71ce23e8907cd3f762e0d5fd0867 (patch)
treea4e07db67276450785169ae4fa6bfef37395d155
parent2c5a4508ef10d16ab353cec5087b04979deabc78 (diff)
downloadkeystone-38318ba95f4e71ce23e8907cd3f762e0d5fd0867.tar.gz
keystone-38318ba95f4e71ce23e8907cd3f762e0d5fd0867.tar.xz
keystone-38318ba95f4e71ce23e8907cd3f762e0d5fd0867.zip
Code by Dev Team
-rw-r--r--.project17
-rw-r--r--.pydevproject7
-rw-r--r--README3
-rw-r--r--db/keystone.dbbin4096 -> 5120 bytes
-rw-r--r--echo/echo.py40
-rw-r--r--keystone/identity.py210
6 files changed, 257 insertions, 20 deletions
diff --git a/.project b/.project
new file mode 100644
index 00000000..c5873b16
--- /dev/null
+++ b/.project
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>keystone-git</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.python.pydev.PyDevBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.python.pydev.pythonNature</nature>
+ </natures>
+</projectDescription>
diff --git a/.pydevproject b/.pydevproject
new file mode 100644
index 00000000..a9cca037
--- /dev/null
+++ b/.pydevproject
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<?eclipse-pydev version="1.0"?>
+
+<pydev_project>
+<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
+<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
+</pydev_project>
diff --git a/README b/README
index 9ec45706..c30fa172 100644
--- a/README
+++ b/README
@@ -10,6 +10,7 @@ sudo easy_install PasteDeploy
sudo easy_install simplejson
sudo easy_install -U bottle
sudo easy_install eventlet
+sudo easy_install urllib2
Tables:
@@ -17,6 +18,8 @@ CREATE TABLE tenants(tenant_id INTEGER, tenant_desc varchar(255), tenant_enabled
CREATE TABLE token (token_id varchar(255),expires datetime);
+CREATE TABLE groups (group_id varchar(255),tenant_id varchar(255),group_desc varchar(255));
+
Issues:
bottle not in path on Mac OS X (added exception handling to default path)
diff --git a/db/keystone.db b/db/keystone.db
index e649de46..403b97c9 100644
--- a/db/keystone.db
+++ b/db/keystone.db
Binary files differ
diff --git a/echo/echo.py b/echo/echo.py
index e59deab7..5cb4b2b7 100644
--- a/echo/echo.py
+++ b/echo/echo.py
@@ -21,7 +21,9 @@ try:
except ImportError:
import json
import eventlet
-import urllib2
+import urllib
+from httplib2 import Http
+
class EchoApp:
@@ -42,17 +44,23 @@ class EchoApp:
def toJSON(self):
-
+ self.start('200 OK', [('Content-Type', 'application/json')])
token = str(self.envr.get("HTTP_X_AUTH_TOKEN",""))
if token !='':
- response=self.ValidateToken({'type':'json','token':token})
- r=json.loads('{"auth" : { "token": {"id": "fad94013a5b3b836dbc18", "expires": "2011-04-18 16:17:59"}}}')
-
+ 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))
- self.start('200 OK', [('Content-Type', 'application/json')])
- yield str(self.transform(self.dom))
@@ -80,18 +88,14 @@ class EchoApp:
if params['token']:
- url = "http://localhost:8080/token/"+str(params['token'])
- #print url
- data = '{"test":""}'
- if params['type']=='json':
- headers = { "Accept" : "application/json", "Content-Type": "application/json",'REQUEST_METHOD':'GET' }
- elif type =='xml':
- headers = { "Accept" : "application/xml", "Content-Type": "application/xml" }
-
- req = urllib2.Request(url, data, headers)
- response = urllib2.urlopen(req)
+
+ http=Http()
- return response.read()
+ 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!")
diff --git a/keystone/identity.py b/keystone/identity.py
index 89ddeff6..72c97d0a 100644
--- a/keystone/identity.py
+++ b/keystone/identity.py
@@ -13,6 +13,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+# Not Yet PEP8 standardized
+
import os
import hashlib
try:
@@ -260,7 +262,7 @@ class Tenants:
return 'it did NOT work\n'
- @route('/token/:token_id', method='POST')
+ @route('/token/:token_id', method='GET')
def validate_token(token_id):
'''
Validating token by doing a GET on /token/token_id
@@ -291,10 +293,214 @@ class Tenants:
if count>0:
#return '{ "token": {"id": "'+a[0]+'", "expires": "2010-11-01T03:32:15-05:00"}}'
- return '{"auth" : { "token": {"id": "'+a[0]+'", "expires": "'+a[1]+'"}, "user" :{"groups"{ "group": [{"tenantId" : "1234","name": "Admin"}]}, "username": "jqsmith", "tenantId": "1234",}{"tenantId" : "1234", "name": "Admin"}}}'
+ return '{"auth" : { "token": {"id": "'+a[0]+'", "expires": "'+a[1]+'"}, "user" :{"groups":{ "group": [{"tenantId" : "1234","name": "Admin"}]}, "username": "jqsmith", "tenantId": "1234",}{"tenantId" : "1234", "name": "Admin"}}}'
else:
abort(401, "Token not valid")
return 'it did NOT work\n'
+
+
+
+
+
+ @route('/tenant/:tenantId/groups', method='POST')
+ def create_tenant_group(tenantId):
+ '''
+ Creating tenant by doing a POST on /tenant/:tenantId/groups
+ {"group":
+ {
+ "id" : "Admin",
+ "description" : "A Description of the group..."
+ }
+ }
+
+ '''
+
+ if 'CONTENT_TYPE' in request.environ:
+ content_types = ['text/plain', 'application/json',
+ 'application/xml', 'text/xml']
+ content = request.environ['CONTENT_TYPE'];
+ if content in content_types:
+
+ #try:
+ if content == 'application/json':
+ if tenantId:
+ body = json.loads(request.body.readline())
+
+ group_id = body['group']['id']
+ group_desc = body['group']['description']
+
+ dbpath = os.path.abspath(os.path.join(os.path.dirname(__file__),'../db/keystone.db'))
+ con = sqlite3.connect(dbpath)
+ cur = con.cursor()
+ cur.execute("SELECT * FROM tenants WHERE tenant_id='%s'" % (tenantId))
+ t=cur.fetchone()
+ # Finding Tenants Exists or not
+ if t is not None:
+ # Finding Tenant Exists or not
+ if not t[2]:
+ return abort(403, "Tenant Disabled")
+
+ else:
+ return abort(401, "unauthorized")
+ # Finding group Exists or not
+ cur.execute("SELECT count(*) FROM groups WHERE tenant_id='%s' AND group_id='%s' " % (tenantId,group_id))
+ a=cur.fetchone()
+
+ count=a[0]
+ if count:
+
+
+
+ return abort(409, "Group already exists")
+
+ else:
+ try:
+ cur.execute("INSERT INTO groups ('group_id','tenant_id','group_desc') VALUES ('%s','%s', '%s')" % (group_id.strip(),tenantId,group_desc))
+ con.commit()
+
+ return '{"group":{"tenantId" : "%s","id" : "%s","description" : "%s"}}' % (group_id.strip(),tenantId,group_desc)
+ except Exception,e:
+ return abort(500,"IDM Fault Creation Failed")
+ con.close()
+ else:
+ return abort(400, "Bad Request")
+ elif content == 'application/xml':
+ #TODO: Implement XML support
+ return "whatever, we don't have XML yet"
+
+ #except:
+ # return abort(500, "IDM Fault")
+ return 'it did NOT work\n'
+
+ @route('/tenant/:tenantId/groups', method='GET')
+ def get_tenant_groups(tenantId):
+ '''
+ Getting all Tenant Groups /tenant/tenantId/groups GET
+
+ Response will be like
+
+ {"groups": {
+ "values" : [
+ {
+ "tenantId" : "1234",
+ "id" : "Admin",
+ "description" : "A description ..."
+ },
+ {
+ "tenantId" : "1234",
+ "id" : "Technical",
+ "description" : "Another description ..."
+ }
+ ]
+ }
+ }
+
+ '''
+ if 'CONTENT_TYPE' in request.environ:
+ content_types = ['text/plain', 'application/json',
+ 'application/xml', 'text/xml']
+ content = request.environ['CONTENT_TYPE'];
+ if content in content_types:
+
+ #try:
+ if content == 'application/json':
+ if tenantId:
+
+
+ dbpath = os.path.abspath(os.path.join(os.path.dirname(__file__),'../db/keystone.db'))
+ con = sqlite3.connect(dbpath)
+ cur = con.cursor()
+ # Finding group Exists or not
+ tenant=cur.execute("SELECT * FROM tenants WHERE tenant_id='%s'" % (tenantId))
+ t=cur.fetchone()
+ resp=''
+ count=tenant.rowcount
+
+
+ if count:
+ return t[2]
+ if not t[2]:
+ # checking Tenant Enabled or not
+ return abort(403, "Tenant disabled")
+
+ groups=cur.execute("SELECT * FROM groups WHERE tenant_id='%s'" % (tenantId))
+ if groups.rowcount > 100:
+ return abort(413,"Over Limit")
+ else:
+ resp+='{"groups": { "values" : ['
+ gresp=''
+ for group in groups:
+ if gresp=='':
+ gresp+='{"tenantId" : "%s","id" : "%s","description" : "%s"}' % (group[2],group[0],group[1])
+ else:
+ gresp+=',{"tenantId" : "%s","id" : "%s","description" : "%s"}' % (group[2],group[0],group[1])
+ resp+=gresp+']}}'
+
+ return resp
+
+
+ else:
+ return abort(401, "unauthorized")
+ con.close()
+ else:
+ return abort(400, "Bad Request")
+ elif content == 'application/xml':
+ #TODO: Implement XML support
+ return "whatever, we don't have XML yet"
+ #except:
+ # return abort(500, "IDM Fault")
+ return 'it did NOT work\n'
+
+ @route('/tenant/:tenantId/groups/:groupId', method='GET')
+ def get_tenant_group(tenantId,groupId):
+ '''
+ Getting Tenant Group /tenant/tenantId/groups/groupId
+ '''
+ if 'CONTENT_TYPE' in request.environ:
+ content_types = ['text/plain', 'application/json',
+ 'application/xml', 'text/xml']
+ content = request.environ['CONTENT_TYPE'];
+ if content in content_types:
+
+ try:
+ if content == 'application/json':
+ if tenantId and groupId:
+
+
+ dbpath = os.path.abspath(os.path.join(os.path.dirname(__file__),'../db/keystone.db'))
+ con = sqlite3.connect(dbpath)
+ cur = con.cursor()
+ # Finding group Exists or not
+ tenant=cur.execute("SELECT * FROM tenants WHERE tenant_id='%s'" % (tenantId))
+ t=cur.fetchone()
+ resp=''
+ count=tenant.rowcount
+ if count:
+ if not t[2]:
+ # checking Tenant Enabled or not
+ return abort(403, "Tenant disabled")
+
+ cur.execute("SELECT * FROM groups WHERE tenant_id='%s' AND group_id='%s' " % (tenantId,groupId))
+ group=cur.fetchone
+
+ if not group == None:
+ resp='{"group": { "tenantId" : "%s","id" : "%s","description" : "%s"}}' % (group[2],group[0],group[1])
+ return resp
+ else:
+
+ return abort(404, "Group Not Found")
+ else:
+ return abort(401, "unauthorized")
+ con.close()
+ else:
+ return abort(400, "Bad Request")
+ elif content == 'application/xml':
+ #TODO: Implement XML support
+ return "whatever, we don't have XML yet"
+ except:
+ return abort(500, "IDM Fault")
+ return 'it did NOT work\n'
+
debug(True)
run(host='localhost', port=8080, reloader=True)