[hg] galaxy 3049: Added credentials table to DB and did intital ...
details: http://www.bx.psu.edu/hg/galaxy/rev/4b4259e46607 changeset: 3049:4b4259e46607 user: Enis Afgan <afgane@gmail.com> date: Fri Aug 21 15:15:30 2009 -0400 description: Added credentials table to DB and did intital integration with Cloud tab. diffstat: lib/galaxy/model/__init__.py | 21 ++++++- lib/galaxy/model/mapping.py | 14 ++++ lib/galaxy/model/migrate/versions/0014_credentials_table.py | 30 ++++++++++ lib/galaxy/web/controllers/cloud.py | 43 +++++++++++--- templates/cloud/configure_cloud.mako | 23 +++---- 5 files changed, 109 insertions(+), 22 deletions(-) diffs (228 lines): diff -r 7d19363e6e0d -r 4b4259e46607 lib/galaxy/model/__init__.py --- a/lib/galaxy/model/__init__.py Thu Aug 20 11:27:30 2009 -0400 +++ b/lib/galaxy/model/__init__.py Fri Aug 21 15:15:30 2009 -0400 @@ -35,6 +35,7 @@ self.purged = False # Relationships self.histories = [] + self.credentials = [] def set_password_cleartext( self, cleartext ): """Set 'self.password' to the digest of 'cleartext'.""" @@ -165,6 +166,15 @@ self.user = user self.group = group +class Credential( object ): + """ + Crediential stores user credential data for accessing cloud resources + """ + def __init__(self, name=None, accessKey=None, secretKey=None): + self.name = name or "Unnamed account" + self.accessKey = accesKey + self.secretKey = secretKey + class History( object ): def __init__( self, id=None, name=None, user=None ): self.id = id @@ -930,7 +940,16 @@ def __init__( self, galaxy_session, history ): self.galaxy_session = galaxy_session self.history = history - + +class StoredUserCredentials( object ): + def __init__( self ): + self.id = None + self.user = None + self.name = None + self.accessKey = None + self.secretKey = None + self.credentials = [] + class StoredWorkflow( object ): def __init__( self ): self.id = None diff -r 7d19363e6e0d -r 4b4259e46607 lib/galaxy/model/mapping.py --- a/lib/galaxy/model/mapping.py Thu Aug 20 11:27:30 2009 -0400 +++ b/lib/galaxy/model/mapping.py Fri Aug 21 15:15:30 2009 -0400 @@ -379,6 +379,16 @@ Column( "session_id", Integer, ForeignKey( "galaxy_session.id" ), index=True ), Column( "history_id", Integer, ForeignKey( "history.id" ), index=True ) ) +StoredUserCredentials.table = Table( "stored_user_credentials", metadata, + Column( "id", Integer, primary_key=True ), + Column( "create_time", DateTime, default=now ), + Column( "update_time", DateTime, default=now, onupdate=now ), + Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True, nullable=False ), + Column( "name", TEXT), + Column( "access_key", TEXT), + Column( "secret_key", TEXT) + ) + StoredWorkflow.table = Table( "stored_workflow", metadata, Column( "id", Integer, primary_key=True ), Column( "create_time", DateTime, default=now ), @@ -884,6 +894,10 @@ output_step=relation( WorkflowStep, backref="output_connections", cascade="all", primaryjoin=( WorkflowStepConnection.table.c.output_step_id == WorkflowStep.table.c.id ) ) ) ) +assign_mapper( context, StoredUserCredentials, StoredUserCredentials.table, + properties=dict( user=relation( User) ) + ) + assign_mapper( context, StoredWorkflow, StoredWorkflow.table, properties=dict( user=relation( User ), workflows=relation( Workflow, backref='stored_workflow', diff -r 7d19363e6e0d -r 4b4259e46607 lib/galaxy/model/migrate/versions/0014_credentials_table.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/galaxy/model/migrate/versions/0014_credentials_table.py Fri Aug 21 15:15:30 2009 -0400 @@ -0,0 +1,30 @@ +from sqlalchemy import * +from migrate import * + +import datetime +now = datetime.datetime.utcnow + +# Need our custom types, but don't import anything else from model +from galaxy.model.custom_types import * + +import logging +log = logging.getLogger( __name__ ) + +metadata = MetaData( migrate_engine ) + +Credentials_table = Table( "stored_user_credentials", metadata, + Column( "id", Integer, primary_key=True ), + Column( "create_time", DateTime, default=now ), + Column( "update_time", DateTime, default=now, onupdate=now ), + Column( "user_id", Integer, ForeignKey( "galaxy_user.id" ), index=True, nullable=False ), + Column( "name", TEXT), + Column( "access_key", TEXT), + Column( "secret_key", TEXT) ) + +def upgrade(): + metadata.reflect() + Credentials_table.create() + +def downgrade(): + metadata.reflect() + Credentials_table.drop() diff -r 7d19363e6e0d -r 4b4259e46607 lib/galaxy/web/controllers/cloud.py --- a/lib/galaxy/web/controllers/cloud.py Thu Aug 20 11:27:30 2009 -0400 +++ b/lib/galaxy/web/controllers/cloud.py Fri Aug 21 15:15:30 2009 -0400 @@ -15,6 +15,10 @@ from galaxy.model.mapping import desc from galaxy.model.orm import * +from boto.ec2.connection import EC2Connection +import logging +log = logging.getLogger( __name__ ) + class CloudController( BaseController ): @web.expose @@ -28,20 +32,18 @@ Render cloud main page (management of cloud resources) """ user = trans.get_user() + #awsCredentials = 0 + awsCredentials = trans.sa_session.query ( model.StoredUserCredentials ).all() + log.debug( "in list" ) + log.debug( awsCredentials ) + workflows = trans.sa_session.query( model.StoredWorkflow ) \ .filter_by( user=user, deleted=False ) \ .order_by( desc( model.StoredWorkflow.c.update_time ) ) \ .all() - shared_by_others = trans.sa_session \ - .query( model.StoredWorkflowUserShareAssociation ) \ - .filter_by( user=user ) \ - .join( 'stored_workflow' ) \ - .filter( model.StoredWorkflow.deleted == False ) \ - .order_by( desc( model.StoredWorkflow.update_time ) ) \ - .all() return trans.fill_template( "cloud/configure_cloud.mako", - workflows = workflows, - shared_by_others = shared_by_others ) + awsCredentials = awsCredentials, + workflows = workflows ) @web.expose @web.require_login( "use Galaxy workflows" ) @@ -219,7 +221,30 @@ Add user's AWS credentials stored under name `account_name`. """ user = trans.get_user() + + """ + awsCredentials = trans.sa_session.query ( model.StoredUserCredentials ).all() + log.debug( "in add" ) + log.debug( user ) + log.debug( stored_credentials.name ) + log.debug( awsCredentials ) + """ + if account_name is not None: + # Create new user stored credentials + stored_credentials = model.StoredUserCredentials() + stored_credentials.name = account_name + stored_credentials.user = user + stored_credentials.access_key = "access key" + stored_credentials.secret_key = "secret key" + # Persist + session = trans.sa_session + session.save_or_update( stored_credentials ) + session.flush() + # Display the management page + trans.set_message( "Credential '%s' created" % stored_credentials.name ) + return self.list( trans ) + """ # Create the new stored workflow stored_workflow = model.StoredWorkflow() diff -r 7d19363e6e0d -r 4b4259e46607 templates/cloud/configure_cloud.mako --- a/templates/cloud/configure_cloud.mako Thu Aug 20 11:27:30 2009 -0400 +++ b/templates/cloud/configure_cloud.mako Fri Aug 21 15:15:30 2009 -0400 @@ -25,30 +25,29 @@ ## <th>Last Updated</th> <th></th> </tr> - %for i, workflow in enumerate( workflows ): + %for i, awsCredential in enumerate( awsCredentials ): <tr> <td> - ${workflow.name} + ${awsCredential.name} <a id="wf-${i}-popup" class="popup-arrow" style="display: none;">▼</a> </td> - <td>${len(workflow.latest_workflow.steps)}</td> - ## <td>${str(workflow.update_time)[:19]}</td> + ## Comment <td>${len(workflow.latest_workflow.steps)}</td> + ## Comment <td>${str(workflow.update_time)[:19]}</td> <td> <div popupmenu="wf-${i}-popup"> - <a class="action-button" href="${h.url_for( action='editor', id=trans.security.encode_id(workflow.id) )}" target="_parent">Edit</a> - <a class="action-button" href="${h.url_for( controller='root', action='index', workflow_id=trans.security.encode_id(workflow.id) )}" target="_parent">Run</a> - <a class="action-button" href="${h.url_for( action='clone', id=trans.security.encode_id(workflow.id) )}">Clone</a> - <a class="action-button" href="${h.url_for( action='rename', id=trans.security.encode_id(workflow.id) )}">Rename</a> - <a class="action-button" href="${h.url_for( action='sharing', id=trans.security.encode_id(workflow.id) )}">Sharing</a> - <a class="action-button" confirm="Are you sure you want to delete workflow '${workflow.name}'?" href="${h.url_for( action='delete', id=trans.security.encode_id(workflow.id) )}">Delete</a> + ##<a class="action-button" href="${h.url_for( action='editor', id=trans.security.encode_id(workflow.id) )}" target="_parent">Edit</a> + ##<a class="action-button" href="${h.url_for( controller='root', action='index', workflow_id=trans.security.encode_id(workflow.id) )}" target="_parent">Run</a> + ##<a class="action-button" href="${h.url_for( action='clone', id=trans.security.encode_id(workflow.id) )}">Clone</a> + ##<a class="action-button" href="${h.url_for( action='rename', id=trans.security.encode_id(workflow.id) )}">Rename</a> + ##<a class="action-button" href="${h.url_for( action='sharing', id=trans.security.encode_id(workflow.id) )}">Sharing</a> + ##<a class="action-button" confirm="Are you sure you want to delete workflow '${workflow.name}'?" href="${h.url_for( action='delete', id=trans.security.encode_id(workflow.id) )}">Delete</a> </div> </td> </tr> %endfor </table> %else: - - You have no AWS credentials associated with your Galaxy account: + You have no AWS credentials associated with your Galaxy account: <a class="action-button" href="${h.url_for( action='add' )}"> <img src="${h.url_for('/static/images/silk/add.png')}" /> <span>Add AWS credentials</span>
participants (1)
-
Greg Von Kuster