Permalink
Browse files

Merge phantomsql code inside Phantom

  • Loading branch information...
1 parent e92a6f0 commit 89d13fc0d2fda0df1044a3aa991682fbc9be11d3 @priteau priteau committed Mar 7, 2013
Showing with 53 additions and 30 deletions.
  1. +46 −25 pyhantom/authz/simple_sql_db.py
  2. +2 −1 pyhantom/system/epu/epu_client.py
  3. +0 −1 requirements.txt
  4. +2 −1 sandbox/FG/add_users.py
  5. +2 −1 sandbox/FG/test_add_user.py
  6. +1 −1 setup.py
@@ -1,15 +1,17 @@
+from datetime import datetime
import logging
-import sqlalchemy
-from pyhantom.authz import PHAuthzIface, PhantomUserObject
-from pyhantom.phantom_exceptions import PhantomAWSException, PhantomException
-from phantomsql import PhantomSQL, PhantomSQLSessionMaker
+
+from sqlalchemy import Column
+from sqlalchemy import Integer
from sqlalchemy import String, MetaData, Sequence
from sqlalchemy import Table
-from sqlalchemy import Integer
from sqlalchemy import types
-from sqlalchemy import Column
-from datetime import datetime
-from sqlalchemy.orm import mapper
+from sqlalchemy.orm import mapper, sessionmaker
+from sqlalchemy.pool import NullPool
+import sqlalchemy
+
+from pyhantom.authz import PHAuthzIface, PhantomUserObject
+from pyhantom.phantom_exceptions import PhantomAWSException
from pyhantom.util import log
metadata = MetaData()
@@ -22,6 +24,7 @@
Column('CreatedTime', types.TIMESTAMP(), default=datetime.now()),
)
+
class PhantomUserDBObject(object):
def __init__(self):
pass
@@ -44,11 +47,12 @@ def call(sqlobj, *args,**kwargs):
class SimpleSQLSessionMaker(object):
def __init__(self, dburl):
- self._dburl = dburl
- self._Session = PhantomSQLSessionMaker(dburl)
+ self._engine = sqlalchemy.create_engine(dburl, poolclass=NullPool)
+ metadata.create_all(self._engine)
+ self._Session = sessionmaker(bind=self._engine)
def get_session(self):
- return self._Session.get_session()
+ return self._Session()
class SimpleSQL(PHAuthzIface):
@@ -57,16 +61,16 @@ def __init__(self, sessionmaker):
self._sessionmaker = sessionmaker
def _open_dbobj(self):
- self._phantom_sql = PhantomSQL(self._sessionmaker.get_session())
+ self._session = self._sessionmaker.get_session()
def _close_dbobj(self):
- if not self._phantom_sql:
+ if not self._session:
return
- self._phantom_sql.close()
+ self._session.close()
@reset_db
def get_user_object_by_access_id(self, access_id):
- db_obj = self._phantom_sql.get_user_object_by_access_id(access_id)
+ db_obj = self._lookup_user(access_id)
if not db_obj:
raise PhantomAWSException('InvalidClientTokenId')
@@ -75,7 +79,9 @@ def get_user_object_by_access_id(self, access_id):
@reset_db
def get_user_object_by_display_name(self, display_name):
try:
- db_obj = self._phantom_sql.get_user_object_by_display_name(display_name)
+ q = self._session.query(PhantomUserDBObject)
+ q = q.filter(PhantomUserDBObject.displayname==display_name)
+ db_obj = q.first()
if not db_obj:
raise PhantomAWSException('InvalidClientTokenId')
return PhantomUserObject(db_obj.access_key, db_obj.access_secret, db_obj.displayname)
@@ -85,20 +91,35 @@ def get_user_object_by_display_name(self, display_name):
@reset_db
def add_alter_user(self, displayname, access_key, access_secret):
- self._phantom_sql.add_alter_user(displayname, access_key, access_secret)
+ db_obj = self._lookup_user(access_key)
+ if not db_obj:
+ db_obj = PhantomUserDBObject()
+ db_obj.access_key = access_key
+ db_obj.access_secret = access_secret
+ db_obj.displayname = displayname
+ self._session.add(db_obj)
@reset_db
def remove_user(self, access_key):
- removed = self._phantom_sql.remove_user(access_key)
- if not removed:
+ db_obj = self._lookup_user(access_key)
+ if not db_obj:
raise PhantomAWSException('InvalidClientTokenId')
+ self._session.delete(db_obj)
+ return True
+
+ @reset_db
+ def add_user(self, displayname, access_id, access_secret):
+ self.add_alter_user(displayname, access_id, access_secret)
+ self.commit()
+
+ def _lookup_user(self, access_key):
+ q = self._session.query(PhantomUserDBObject)
+ q = q.filter(PhantomUserDBObject.access_key==access_key)
+ db_obj = q.first()
+ return db_obj
def commit(self):
- self._phantom_sql.commit()
+ self._session.commit()
def close(self):
- self._phantom_sql.close()
-
- @reset_db
- def add_user(self, displayname, access_id, access_secret):
- self._phantom_sql.add_user(displayname, access_id, access_secret)
+ self._session.close()
@@ -8,12 +8,13 @@
from ceiclient.client import DTRSClient, EPUMClient
from pyhantom.util import log, LogEntryDecorator, _get_time, make_time
from dashi import DashiError
-from phantomsql import phantom_get_default_key_name
from pyhantom.system.epu.definitions import tags_to_definition, load_known_definitions
DEFAULT_OPENTSDB_HOST = 'localhost'
DEFAULT_OPENTSDB_PORT = 4242
+def phantom_get_default_key_name():
+ return "phantomkey"
def _breakup_name(name):
s_a = name.split("@", 1)
View
@@ -11,7 +11,6 @@ Fabric==1.3.0
Jinja2==2.6
kombu==2.4.10
MySQL-python==1.2.3
-phantomsql==0.2.1
pycrypto==2.3
PyYAML==3.10
simplejson==2.3.2
@@ -11,9 +11,10 @@
import boto
from boto.ec2.regioninfo import RegionInfo
import ldap
-from phantomsql import phantom_get_default_key_name
import dashi
+def phantom_get_default_key_name():
+ return "phantomkey"
def get_dashi_client(cfg):
ssl = cfg.phantom.system.rabbit_ssl
@@ -13,8 +13,9 @@
from pyhantom.config import build_cfg
import boto
from boto.ec2.regioninfo import RegionInfo
-from phantomsql import phantom_get_default_key_name
+def phantom_get_default_key_name():
+ return "phantomkey"
def get_dashi_client():
View
@@ -23,7 +23,7 @@
keywords = "Nimbus auto scale",
long_description="""Some other time""",
license="Apache2",
- install_requires = ["simplejson == 2.3.2", "boto >= 2.6", "dashi", "ceiclient", "sqlalchemy == 0.7.6", "wsgiref", "webob", "cherrypy >= 3.2", "mysql-python == 1.2.3", "phantomsql"],
+ install_requires = ["simplejson == 2.3.2", "boto >= 2.6", "dashi", "ceiclient", "sqlalchemy == 0.7.6", "wsgiref", "webob", "cherrypy >= 3.2", "mysql-python == 1.2.3"],
entry_points = {
'console_scripts': [
'phantomwsgiref = pyhantom.execs.simpleref:main',

0 comments on commit 89d13fc

Please sign in to comment.