def test_maximum_length_handling_ascii():
    # Test that id secrets can be up to 56 characters long.
    longest_id_secret = "m" * security.MAXIMUM_ID_SECRET_LENGTH
    helper = security.SecurityHelper(id_secret=longest_id_secret)
    helper.encode_id(1)

    # Test that security helper will catch if the id secret is too long.
    threw_exception = False
    longer_id_secret = "m" * (security.MAXIMUM_ID_SECRET_LENGTH + 1)
    try:
        security.SecurityHelper(id_secret=longer_id_secret)
    except Exception:
        threw_exception = True

    assert threw_exception

    # Test that different kinds produce different keys even when id secret
    # is very long.
    e11 = helper.encode_id(1, kind="moo")
    e12 = helper.encode_id(1, kind="moo2")

    assert e11 != e12

    # Test that long kinds are rejected because it uses up "too much" randomness
    # from id_secret values. This isn't a strict requirement up but lets just enforce
    # the best practice.
    assertion_error_raised = False
    try:
        helper.encode_id(1, kind="this is a really long kind")
    except AssertionError:
        assertion_error_raised = True

    assert assertion_error_raised
示例#2
0
 def setUp(self):
     # Security helper
     self.security = security.SecurityHelper(
         id_secret='changethisinproductiontoo')
     self.history_id = os.environ.get('GALAXY_TEST_HISTORY_ID', None)
     self.host = os.environ.get('GALAXY_TEST_HOST')
     self.port = os.environ.get('GALAXY_TEST_PORT')
     default_url = "http://%s:%s" % (self.host, self.port)
     self.url = os.environ.get('GALAXY_TEST_EXTERNAL', default_url)
     self.test_data_resolver = TestDataResolver()
     tool_shed_test_file = os.environ.get('GALAXY_TOOL_SHED_TEST_FILE',
                                          None)
     if tool_shed_test_file:
         f = open(tool_shed_test_file, 'r')
         text = f.read()
         f.close()
         self.shed_tools_dict = loads(text)
     else:
         self.shed_tools_dict = {}
     self.keepOutdir = os.environ.get('GALAXY_TEST_SAVE', '')
     if self.keepOutdir > '':
         try:
             os.makedirs(self.keepOutdir)
         except Exception:
             pass
示例#3
0
 def __init__(self, **kwargs):
     print >> sys.stderr, "python path is: " + ", ".join(sys.path)
     self.name = "reports"
     # Read config file and check for errors
     self.config = config.Configuration(**kwargs)
     self.config.check()
     config.configure_logging(self.config)
     # Determine the database url
     if self.config.database_connection:
         db_url = self.config.database_connection
     else:
         db_url = "sqlite:///%s?isolation_level=IMMEDIATE" % self.config.database
     # Setup the database engine and ORM
     self.model = galaxy.model.mapping.init(
         self.config.file_path,
         db_url,
         self.config.database_engine_options,
         create_tables=True)
     if not self.config.database_connection:
         self.targets_mysql = False
     else:
         self.targets_mysql = 'mysql' in self.config.database_connection
     # Security helper
     self.security = security.SecurityHelper(
         id_secret=self.config.id_secret)
     # used for cachebusting -- refactor this into a *SINGLE* UniverseApplication base.
     self.server_starttime = int(time.time())
示例#4
0
    def __init__(self, root=None, **kwargs):
        Bunch.__init__(self, **kwargs)
        root = root or '/tmp'
        self.security = security.SecurityHelper(id_secret='bler')
        self.use_remote_user = kwargs.get('use_remote_user', False)
        self.file_path = '/tmp'
        self.jobs_directory = '/tmp'
        self.new_file_path = '/tmp'
        self.tool_data_path = '/tmp'

        self.object_store_config_file = ''
        self.object_store = 'disk'
        self.object_store_check_old_style = False

        self.user_activation_on = False
        self.new_user_dataset_access_role_default_private = False

        self.expose_dataset_path = True
        self.allow_user_dataset_purge = True
        self.enable_old_display_applications = True

        self.umask = 0o77

        # Follow two required by GenomeBuilds
        self.len_file_path = os.path.join('tool-data', 'shared', 'ucsc', 'chrom')
        self.builds_file_path = os.path.join('tool-data', 'shared', 'ucsc', 'builds.txt.sample')

        self.migrated_tools_config = "/tmp/migrated_tools_conf.xml"
        self.preserve_python_environment = "always"

        # set by MockDir
        self.root = root
示例#5
0
 def __init__(self, **kwd):
     print >> sys.stderr, "python path is: " + ", ".join(sys.path)
     self.name = "tool_shed"
     # Read the tool_shed.ini configuration file and check for errors.
     self.config = config.Configuration(**kwd)
     self.config.check()
     config.configure_logging(self.config)
     # Initialize the  Galaxy datatypes registry.
     self.datatypes_registry = galaxy.datatypes.registry.Registry()
     self.datatypes_registry.load_datatypes(self.config.root,
                                            self.config.datatypes_config)
     # Initialize the Tool Shed repository_types registry.
     self.repository_types_registry = tool_shed.repository_types.registry.Registry(
     )
     # Initialize the RepositoryGridFilterManager.
     self.repository_grid_filter_manager = RepositoryGridFilterManager()
     # Determine the Tool Shed database connection string.
     if self.config.database_connection:
         db_url = self.config.database_connection
     else:
         db_url = "sqlite:///%s?isolation_level=IMMEDIATE" % self.config.database
     # Initialize the Tool Shed database and check for appropriate schema version.
     from galaxy.webapps.tool_shed.model.migrate.check import create_or_verify_database
     create_or_verify_database(db_url, self.config.database_engine_options)
     # Set up the Tool Shed database engine and ORM.
     from galaxy.webapps.tool_shed.model import mapping
     self.model = mapping.init(self.config.file_path, db_url,
                               self.config.database_engine_options)
     # Initialize the Tool Shed security helper.
     self.security = security.SecurityHelper(
         id_secret=self.config.id_secret)
     # initialize the Tool Shed tag handler.
     self.tag_handler = CommunityTagManager(self)
     # Initialize the Tool Shed tool data tables.  Never pass a configuration file here
     # because the Tool Shed should always have an empty dictionary!
     self.tool_data_tables = galaxy.tools.data.ToolDataTableManager(
         self.config.tool_data_path)
     self.genome_builds = GenomeBuilds(self)
     # Citation manager needed to load tools.
     from galaxy.managers.citations import CitationsManager
     self.citations_manager = CitationsManager(self)
     # The Tool Shed makes no use of a Galaxy toolbox, but this attribute is still required.
     self.toolbox = tools.ToolBox([], self.config.tool_path, self)
     # Initialize the Tool Shed security agent.
     self.security_agent = self.model.security_agent
     # The Tool Shed makes no use of a quota, but this attribute is still required.
     self.quota_agent = galaxy.quota.NoQuotaAgent(self.model)
     # TODO: Add OpenID support
     self.openid_providers = OpenIDProviders()
     # Initialize the baseline Tool Shed statistics component.
     self.shed_counter = self.model.shed_counter
     # Let the Tool Shed's HgwebConfigManager know where the hgweb.config file is located.
     self.hgweb_config_manager = self.model.hgweb_config_manager
     self.hgweb_config_manager.hgweb_config_dir = self.config.hgweb_config_dir
     # Initialize the repository registry.
     self.repository_registry = tool_shed.repository_registry.Registry(self)
     #  used for cachebusting -- refactor this into a *SINGLE* UniverseApplication base.
     self.server_starttime = int(time.time())
     print >> sys.stderr, "Tool shed hgweb.config file is: ", self.hgweb_config_manager.hgweb_config
示例#6
0
 def setUp(self):
     # Security helper
     self.security = security.SecurityHelper(
         id_secret='changethisinproductiontoo')
     self.history_id = os.environ.get('GALAXY_TEST_HISTORY_ID', None)
     self.host, self.port, self.url = target_url_parts()
     self.test_data_resolver = TestDataResolver()
     self.keepOutdir = setup_keep_outdir()
示例#7
0
 def __init__( self, **kwargs ):
     print >> sys.stderr, "python path is: " + ", ".join( sys.path )
     # Read config file and check for errors
     self.config = config.Configuration( **kwargs )
     self.config.check()
     config.configure_logging( self.config )
     # Set up sequencer actions registry
     self.sequencer_actions_registry = galaxy.webapps.demo_sequencer.registry.Registry( self.config.root, self.config.sequencer_actions_config )
     # Security helper
     self.security = security.SecurityHelper( id_secret=self.config.id_secret )
示例#8
0
 def __init__(self, config):
     self.config = config
     if not self.config.database_connection:
         self.config.database_connection = \
             "sqlite:///%s?isolation_level=IMMEDIATE" % str(config.database)
     # Setup the database engine and ORM
     self.model = mapping.init(self.config.file_path,
                               self.config.database_connection,
                               engine_options={},
                               create_tables=False)
     self.security = security.SecurityHelper(id_secret=self.config.id_secret)
def test_maximum_length_handling_nonascii():
    longest_id_secret = "◎◎◎◎◎◎◎◎◎◎◎◎◎◎◎◎◎◎"
    helper = security.SecurityHelper(id_secret=longest_id_secret)
    helper.encode_id(1)

    # Test that security helper will catch if the id secret is too long.
    threw_exception = False
    longer_id_secret = "◎◎◎◎◎◎◎◎◎◎◎◎◎◎◎◎◎◎◎"
    try:
        security.SecurityHelper(id_secret=longer_id_secret)
    except Exception:
        threw_exception = True

    assert threw_exception

    # Test that different kinds produce different keys even when id secret
    # is very long.
    e11 = helper.encode_id(1, kind="moo")
    e12 = helper.encode_id(1, kind="moo2")

    assert e11 != e12
 def __init__(self, config):
     self.config = config
     if not self.config.database_connection:
         self.config.database_connection = "sqlite:///%s?isolation_level=IMMEDIATE" % str(config.database)
     print 'Using database connection: ', self.config.database_connection
     # Setup the database engine and ORM
     self.model = mapping.init(self.config.file_path,
                               self.config.database_connection,
                               engine_options={},
                               create_tables=False)
     self.security = security.SecurityHelper(id_secret=self.config.id_secret)
     self.hgweb_config_manager = self.model.hgweb_config_manager
     self.hgweb_config_manager.hgweb_config_dir = self.config.hgweb_config_dir
     print 'Using hgweb.config file: ', self.hgweb_config_manager.hgweb_config
示例#11
0
    def __init__(self, **kwargs):
        Bunch.__init__(self, **kwargs)
        self.security = security.SecurityHelper(id_secret='bler')
        self.file_path = '/tmp'
        self.job_working_directory = '/tmp'
        self.new_file_path = '/tmp'

        self.object_store_config_file = ''
        self.object_store = 'disk'
        self.object_store_check_old_style = False

        self.user_activation_on = False
        self.new_user_dataset_access_role_default_private = False

        self.allow_user_dataset_purge = True
示例#12
0
 def __init__( self, **kwargs ):
     print >> sys.stderr, "python path is: " + ", ".join( sys.path )
     # Read config file and check for errors
     self.config = config.Configuration( **kwargs )
     self.config.check()
     config.configure_logging( self.config )
     # Determine the database url
     if self.config.database_connection:
         db_url = self.config.database_connection
     else:
         db_url = "sqlite://%s?isolation_level=IMMEDIATE" % self.config.database
     # Setup the database engine and ORM
     self.model = galaxy.model.mapping.init( self.config.file_path,
                                             db_url,
                                             self.config.database_engine_options,
                                             create_tables = True )
     # Security helper
     self.security = security.SecurityHelper( id_secret=self.config.id_secret )
示例#13
0
 def __init__(self, **kwargs):
     print >> sys.stderr, "python path is: " + ", ".join(sys.path)
     self.name = "community"
     # Read config file and check for errors
     self.config = config.Configuration(**kwargs)
     self.config.check()
     config.configure_logging(self.config)
     # Set up datatypes registry
     self.datatypes_registry = galaxy.datatypes.registry.Registry()
     self.datatypes_registry.load_datatypes(self.config.root,
                                            self.config.datatypes_config)
     # Determine the database url
     if self.config.database_connection:
         db_url = self.config.database_connection
     else:
         db_url = "sqlite:///%s?isolation_level=IMMEDIATE" % self.config.database
     # Initialize database / check for appropriate schema version
     from galaxy.webapps.community.model.migrate.check import create_or_verify_database
     create_or_verify_database(db_url, self.config.database_engine_options)
     # Setup the database engine and ORM
     from galaxy.webapps.community.model import mapping
     self.model = mapping.init(self.config.file_path, db_url,
                               self.config.database_engine_options)
     # Security helper
     self.security = security.SecurityHelper(
         id_secret=self.config.id_secret)
     # Tag handler
     self.tag_handler = CommunityTagHandler()
     # Tool data tables - never pass a config file here because the tool shed should always have an empty dictionary!
     self.tool_data_tables = galaxy.tools.data.ToolDataTableManager(
         self.config.tool_data_path)
     # The tool shed has no toolbox, but this attribute is still required.
     self.toolbox = tools.ToolBox([], self.config.tool_path, self)
     # Load security policy
     self.security_agent = self.model.security_agent
     self.quota_agent = galaxy.quota.NoQuotaAgent(self.model)
     # TODO: Add OpenID support
     self.openid_providers = OpenIDProviders()
     self.shed_counter = self.model.shed_counter
     # Let the HgwebConfigManager know where the hgweb.config file is located.
     self.hgweb_config_manager = self.model.hgweb_config_manager
     self.hgweb_config_manager.hgweb_config_dir = self.config.hgweb_config_dir
     print >> sys.stderr, "Tool shed hgweb.config file is: ", self.hgweb_config_manager.hgweb_config
示例#14
0
    def __init__( self, root=None, **kwargs ):
        Bunch.__init__( self, **kwargs )
        self.security = security.SecurityHelper( id_secret='bler' )
        self.file_path = '/tmp'
        self.job_working_directory = '/tmp'
        self.new_file_path = '/tmp'

        self.object_store_config_file = ''
        self.object_store = 'disk'
        self.object_store_check_old_style = False

        self.user_activation_on = False
        self.new_user_dataset_access_role_default_private = False

        self.expose_dataset_path = True
        self.allow_user_dataset_purge = True
        self.enable_old_display_applications = True

        # set by MockDir
        self.root = root
示例#15
0
 def setUp(self):
     # Security helper
     id_secret = os.environ.get('GALAXY_INSTALL_TEST_SECRET',
                                'changethisinproductiontoo')
     self.security = security.SecurityHelper(id_secret=id_secret)
     self.history_id = None
     self.test_tmp_dir = os.environ.get('GALAXY_INSTALL_TEST_TMP_DIR', None)
     self.host = os.environ.get('GALAXY_INSTALL_TEST_HOST')
     self.port = os.environ.get('GALAXY_INSTALL_TEST_PORT')
     self.url = "http://%s:%s" % (self.host, self.port)
     self.shed_tool_data_table_conf = os.environ.get(
         'GALAXY_INSTALL_TEST_SHED_TOOL_DATA_TABLE_CONF')
     self.file_dir = os.environ.get('GALAXY_INSTALL_TEST_FILE_DIR', None)
     self.tool_data_path = os.environ.get(
         'GALAXY_INSTALL_TEST_TOOL_DATA_PATH')
     self.shed_tool_conf = os.environ.get(
         'GALAXY_INSTALL_TEST_SHED_TOOL_CONF')
     # TODO: Figure out a way to alter these attributes during tests.
     self.galaxy_tool_dependency_dir = os.environ.get(
         'GALAXY_INSTALL_TEST_TOOL_DEPENDENCY_DIR')
     self.shed_tools_dict = {}
示例#16
0
 def __init__( self, **kwargs ):
     print >> sys.stderr, "python path is: " + ", ".join( sys.path )
     # Read config file and check for errors
     self.config = config.Configuration( **kwargs )
     self.config.check()
     config.configure_logging( self.config )
     # Set up datatypes registry
     self.datatypes_registry = galaxy.datatypes.registry.Registry()
     # TODO: Handle datatypes included in repositories - the following will only load datatypes_conf.xml.
     self.datatypes_registry.load_datatypes( self.config.root, self.config.datatypes_config )
     # Determine the database url
     if self.config.database_connection:
         db_url = self.config.database_connection
     else:
         db_url = "sqlite://%s?isolation_level=IMMEDIATE" % self.config.database
     # Initialize database / check for appropriate schema version
     from galaxy.webapps.community.model.migrate.check import create_or_verify_database
     create_or_verify_database( db_url, self.config.database_engine_options )
     # Setup the database engine and ORM
     from galaxy.webapps.community.model import mapping
     self.model = mapping.init( self.config.file_path,
                                db_url,
                                self.config.database_engine_options )
     # Security helper
     self.security = security.SecurityHelper( id_secret=self.config.id_secret )
     # Tag handler
     self.tag_handler = CommunityTagHandler()
     # Tool data tables
     self.tool_data_tables = galaxy.tools.data.ToolDataTableManager( self.config.tool_data_table_config_path )
     # The tool shed has no toolbox, but this attribute is still required.
     self.toolbox = None
     # Load security policy
     self.security_agent = self.model.security_agent
     self.quota_agent = galaxy.quota.NoQuotaAgent( self.model )
     # TODO: Add OpenID support
     self.openid_providers = OpenIDProviders()
     self.shed_counter = self.model.shed_counter
示例#17
0
 def _configure_security(self):
     from galaxy.web import security
     self.security = security.SecurityHelper(
         id_secret=self.config.id_secret)
示例#18
0
 def __init__( self, **kwargs ):
     print >> sys.stderr, "python path is: " + ", ".join( sys.path )
     self.new_installation = False
     # Read config file and check for errors
     self.config = config.Configuration( **kwargs )
     self.config.check()
     config.configure_logging( self.config )
     # Determine the database url
     if self.config.database_connection:
         db_url = self.config.database_connection
     else:
         db_url = "sqlite:///%s?isolation_level=IMMEDIATE" % self.config.database
     # Initialize database / check for appropriate schema version.  # If this
     # is a new installation, we'll restrict the tool migration messaging.
     from galaxy.model.migrate.check import create_or_verify_database
     create_or_verify_database( db_url, kwargs.get( 'global_conf', {} ).get( '__file__', None ), self.config.database_engine_options, app=self )
     # Alert the Galaxy admin to tools that have been moved from the distribution to the tool shed.
     from galaxy.tool_shed.migrate.check import verify_tools
     verify_tools( self, db_url, kwargs.get( 'global_conf', {} ).get( '__file__', None ), self.config.database_engine_options )
     # Object store manager
     self.object_store = build_object_store_from_config(self.config)
     # Setup the database engine and ORM
     from galaxy.model import mapping
     self.model = mapping.init( self.config.file_path,
                                db_url,
                                self.config.database_engine_options,
                                database_query_profiling_proxy = self.config.database_query_profiling_proxy,
                                object_store = self.object_store )
     # Set up the tool sheds registry
     if os.path.isfile( self.config.tool_sheds_config ):
         self.tool_shed_registry = galaxy.tool_shed.tool_shed_registry.Registry( self.config.root, self.config.tool_sheds_config )
     else:
         self.tool_shed_registry = None
     # Manage installed tool shed repositories.
     self.installed_repository_manager = galaxy.tool_shed.InstalledRepositoryManager( self )
     # Create an empty datatypes registry.
     self.datatypes_registry = galaxy.datatypes.registry.Registry()
     # Load proprietary datatypes defined in datatypes_conf.xml files in all installed tool shed repositories.  We
     # load proprietary datatypes before datatypes in the distribution because Galaxy's default sniffers include some
     # generic sniffers (eg text,xml) which catch anything, so it's impossible for proprietary sniffers to be used.
     # However, if there is a conflict (2 datatypes with the same extension) between a proprietary datatype and a datatype
     # in the Galaxy distribution, the datatype in the Galaxy distribution will take precedence.  If there is a conflict
     # between 2 proprietary datatypes, the datatype from the repository that was installed earliest will take precedence.
     # This will also load proprietary datatype converters and display applications.
     self.installed_repository_manager.load_proprietary_datatypes()
     # Load the data types in the Galaxy distribution, which are defined in self.config.datatypes_config.
     self.datatypes_registry.load_datatypes( self.config.root, self.config.datatypes_config )
     galaxy.model.set_datatypes_registry( self.datatypes_registry )
     # Security helper
     self.security = security.SecurityHelper( id_secret=self.config.id_secret )
     # Tag handler
     self.tag_handler = GalaxyTagHandler()
     # Tool data tables
     self.tool_data_tables = galaxy.tools.data.ToolDataTableManager( self.config.tool_data_table_config_path )
     # Initialize the tools, making sure the list of tool configs includes the reserved migrated_tools_conf.xml file.
     tool_configs = self.config.tool_configs
     if self.config.migrated_tools_config not in tool_configs:
         tool_configs.append( self.config.migrated_tools_config )
     self.toolbox = tools.ToolBox( tool_configs, self.config.tool_path, self )
     # Search support for tools
     self.toolbox_search = galaxy.tools.search.ToolBoxSearch( self.toolbox )
     # If enabled, poll respective tool sheds to see if updates are available for any installed tool shed repositories.
     if self.config.get_bool( 'enable_tool_shed_check', False ):
         from tool_shed import update_manager
         self.update_manager = update_manager.UpdateManager( self )
     # Load datatype display applications defined in local datatypes_conf.xml
     self.datatypes_registry.load_display_applications()
     # Load datatype converters defined in local datatypes_conf.xml
     self.datatypes_registry.load_datatype_converters( self.toolbox )
     # Load external metadata tool
     self.datatypes_registry.load_external_metadata_tool( self.toolbox )
     # Load history import/export tools.
     load_history_imp_exp_tools( self.toolbox )
     # Load genome indexer tool.
     load_genome_index_tools( self.toolbox )
     # Load security policy.
     self.security_agent = self.model.security_agent
     self.host_security_agent = galaxy.security.HostAgent( model=self.security_agent.model, permitted_actions=self.security_agent.permitted_actions )
     # Load quota management.
     if self.config.enable_quotas:
         self.quota_agent = galaxy.quota.QuotaAgent( self.model )
     else:
         self.quota_agent = galaxy.quota.NoQuotaAgent( self.model )
     # Heartbeat and memdump for thread / heap profiling
     self.heartbeat = None
     self.memdump = None
     self.memory_usage = None
     # Container for OpenID authentication routines
     if self.config.enable_openid:
         from galaxy.web.framework import openid_manager
         self.openid_manager = openid_manager.OpenIDManager( self.config.openid_consumer_cache_path )
         self.openid_providers = OpenIDProviders.from_file( self.config.openid_config )
     else:
         self.openid_providers = OpenIDProviders()
     # Start the heartbeat process if configured and available
     if self.config.use_heartbeat:
         from galaxy.util import heartbeat
         if heartbeat.Heartbeat:
             self.heartbeat = heartbeat.Heartbeat( fname=self.config.heartbeat_log )
             self.heartbeat.start()
     # Enable the memdump signal catcher if configured and available
     if self.config.use_memdump:
         from galaxy.util import memdump
         if memdump.Memdump:
             self.memdump = memdump.Memdump()
     # Transfer manager client
     if self.config.get_bool( 'enable_beta_job_managers', False ):
         from jobs import transfer_manager
         self.transfer_manager = transfer_manager.TransferManager( self )
     # Start the job manager
     from jobs import manager
     self.job_manager = manager.JobManager( self )
     # FIXME: These are exposed directly for backward compatibility
     self.job_queue = self.job_manager.job_queue
     self.job_stop_queue = self.job_manager.job_stop_queue
     # Initialize the external service types
     self.external_service_types = external_service_types.ExternalServiceTypesCollection( self.config.external_service_type_config_file, self.config.external_service_type_path, self )
示例#19
0
 def __init__(self, tools_migration_config):
     install_dependencies = 'install_dependencies' in sys.argv
     galaxy_config_file = 'universe_wsgi.ini'
     self.name = 'galaxy'
     if '-c' in sys.argv:
         pos = sys.argv.index('-c')
         sys.argv.pop(pos)
         galaxy_config_file = sys.argv.pop(pos)
     if not os.path.exists(galaxy_config_file):
         print "Galaxy config file does not exist (hint: use '-c config.ini' for non-standard locations): %s" % galaxy_config_file
         sys.exit(1)
     config_parser = ConfigParser.ConfigParser({'here': os.getcwd()})
     config_parser.read(galaxy_config_file)
     galaxy_config_dict = {}
     for key, value in config_parser.items("app:main"):
         galaxy_config_dict[key] = value
     self.config = galaxy.config.Configuration(**galaxy_config_dict)
     if not self.config.database_connection:
         self.config.database_connection = "sqlite:///%s?isolation_level=IMMEDIATE" % self.config.database
     self.config.update_integrated_tool_panel = True
     self.object_store = build_object_store_from_config(self.config)
     # Security helper
     self.security = security.SecurityHelper(
         id_secret=self.config.id_secret)
     # Setup the database engine and ORM
     self.model = galaxy.model.mapping.init(self.config.file_path,
                                            self.config.database_connection,
                                            engine_options={},
                                            create_tables=False,
                                            object_store=self.object_store)
     # Create an empty datatypes registry.
     self.datatypes_registry = galaxy.datatypes.registry.Registry()
     # Load the data types in the Galaxy distribution, which are defined in self.config.datatypes_config.
     self.datatypes_registry.load_datatypes(self.config.root,
                                            self.config.datatypes_config)
     # Initialize tool data tables using the config defined by self.config.tool_data_table_config_path.
     self.tool_data_tables = ToolDataTableManager(
         tool_data_path=self.config.tool_data_path,
         config_filename=self.config.tool_data_table_config_path)
     # Load additional entries defined by self.config.shed_tool_data_table_config into tool data tables.
     self.tool_data_tables.load_from_config_file(
         config_filename=self.config.shed_tool_data_table_config,
         tool_data_path=self.tool_data_tables.tool_data_path,
         from_shed_config=True)
     # Initialize the tools, making sure the list of tool configs includes the reserved migrated_tools_conf.xml file.
     tool_configs = self.config.tool_configs
     if self.config.migrated_tools_config not in tool_configs:
         tool_configs.append(self.config.migrated_tools_config)
     self.toolbox = tools.ToolBox(tool_configs, self.config.tool_path, self)
     # Search support for tools
     self.toolbox_search = galaxy.tools.search.ToolBoxSearch(self.toolbox)
     # Set up the tool sheds registry.
     if os.path.isfile(self.config.tool_sheds_config):
         self.tool_shed_registry = tool_shed.tool_shed_registry.Registry(
             self.config.root, self.config.tool_sheds_config)
     else:
         self.tool_shed_registry = None
     # Get the latest tool migration script number to send to the Install manager.
     latest_migration_script_number = int(
         tools_migration_config.split('_')[0])
     # The value of migrated_tools_config is migrated_tools_conf.xml, and is reserved for containing only those tools that have been
     # eliminated from the distribution and moved to the tool shed.  A side-effect of instantiating the InstallManager is the automatic
     # installation of all appropriate tool shed repositories.
     self.install_manager = install_manager.InstallManager(
         app=self,
         latest_migration_script_number=latest_migration_script_number,
         tool_shed_install_config=os.path.join(self.config.root, 'scripts',
                                               'migrate_tools',
                                               tools_migration_config),
         migrated_tools_config=self.config.migrated_tools_config,
         install_dependencies=install_dependencies)
示例#20
0
 def __init__(self, **kwargs):
     self.name = kwargs.get('name', 'galaxy')
     self.security = security.SecurityHelper(id_secret='bler')
示例#21
0
 def __init__( self, **kwargs ):
     print >> sys.stderr, "python path is: " + ", ".join( sys.path )
     # Read config file and check for errors
     self.config = config.Configuration( **kwargs )
     self.config.check()
     config.configure_logging( self.config )
     # Set up datatypes registry
     self.datatypes_registry = galaxy.datatypes.registry.Registry( self.config.root, self.config.datatypes_config )
     galaxy.model.set_datatypes_registry( self.datatypes_registry )
     # Determine the database url
     if self.config.database_connection:
         db_url = self.config.database_connection
     else:
         db_url = "sqlite:///%s?isolation_level=IMMEDIATE" % self.config.database
     # Initialize database / check for appropriate schema version
     from galaxy.model.migrate.check import create_or_verify_database
     create_or_verify_database( db_url, self.config.database_engine_options )
     # Setup the database engine and ORM
     from galaxy.model import mapping
     self.model = mapping.init( self.config.file_path,
                                db_url,
                                self.config.database_engine_options )
     # Security helper
     self.security = security.SecurityHelper( id_secret=self.config.id_secret )
     # Initialize the tools
     self.toolbox = tools.ToolBox( self.config.tool_config, self.config.tool_path, self )
     # Load datatype converters
     self.datatypes_registry.load_datatype_converters( self.toolbox )
     #load external metadata tool
     self.datatypes_registry.load_external_metadata_tool( self.toolbox )
     # Load datatype indexers
     self.datatypes_registry.load_datatype_indexers( self.toolbox )
     #Load security policy
     self.security_agent = self.model.security_agent
     self.host_security_agent = galaxy.security.HostAgent( model=self.security_agent.model, permitted_actions=self.security_agent.permitted_actions )
     # Heartbeat and memdump for thread / heap profiling
     self.heartbeat = None
     self.memdump = None
     self.memory_usage = None
     # Start the heartbeat process if configured and available
     if self.config.use_heartbeat:
         from galaxy.util import heartbeat
         if heartbeat.Heartbeat:
             self.heartbeat = heartbeat.Heartbeat()
             self.heartbeat.start()
     # Enable the memdump signal catcher if configured and available
     if self.config.use_memdump:
         from galaxy.util import memdump
         if memdump.Memdump:
             self.memdump = memdump.Memdump()
     # Enable memory_usage logging if configured
     if self.config.log_memory_usage:
         from galaxy.util import memory_usage
         self.memory_usage = memory_usage
     # Start the job queue
     self.job_manager = jobs.JobManager( self )
     # FIXME: These are exposed directly for backward compatibility
     self.job_queue = self.job_manager.job_queue
     self.job_stop_queue = self.job_manager.job_stop_queue
     # Start the cloud manager
     self.cloud_manager = cloud.CloudManager( self )
示例#22
0
 def __init__(self, **kwargs):
     self.name = kwargs.get('name', 'galaxy')
     self.security = security.SecurityHelper(
         id_secret='6e46ed6483a833c100e68cc3f1d0dd76')
示例#23
0
except:
    parser.print_help()
    sys.exit( 1 )

options.config = os.path.abspath( options.config )
sys.path.insert( 1, os.path.join( os.path.dirname( __file__ ), os.pardir, 'lib' ) )

config = ConfigParser( dict( file_path='database/files',
                             id_secret='USING THE DEFAULT IS NOT SECURE!',
                             database_connection='sqlite:///database/universe.sqlite?isolation_level=IMMEDIATE' ) )
config.read( options.config )

from galaxy.web import security
from galaxy.model import mapping

helper = security.SecurityHelper( id_secret=config.get( 'app:main', 'id_secret' ) )
model = mapping.init( config.get( 'app:main', 'file_path' ), config.get( 'app:main', 'database_connection' ), create_tables=False )

if options.encode_id:
    print 'Encoded "%s": %s' % ( options.encode_id, helper.encode_id( options.encode_id ) )

if options.decode_id:
    print 'Decoded "%s": %s' % ( options.decode_id, helper.decode_id( options.decode_id ) )

if options.hda_id:
    try:
        hda_id = int( options.hda_id )
    except:
        hda_id = int( helper.decode_id( options.hda_id ) )
    hda = model.context.current.query( model.HistoryDatasetAssociation ).get( hda_id )
    print 'HDA "%s" is Dataset "%s" at: %s' % ( hda.id, hda.dataset.id, hda.file_name )
# -*- coding: utf-8 -*-

from galaxy.web import security

test_helper_1 = security.SecurityHelper(id_secret="secu1")
test_helper_2 = security.SecurityHelper(id_secret="secu2")


def test_maximum_length_handling_ascii():
    # Test that id secrets can be up to 56 characters long.
    longest_id_secret = "m" * security.MAXIMUM_ID_SECRET_LENGTH
    helper = security.SecurityHelper(id_secret=longest_id_secret)
    helper.encode_id(1)

    # Test that security helper will catch if the id secret is too long.
    threw_exception = False
    longer_id_secret = "m" * (security.MAXIMUM_ID_SECRET_LENGTH + 1)
    try:
        security.SecurityHelper(id_secret=longer_id_secret)
    except Exception:
        threw_exception = True

    assert threw_exception

    # Test that different kinds produce different keys even when id secret
    # is very long.
    e11 = helper.encode_id(1, kind="moo")
    e12 = helper.encode_id(1, kind="moo2")

    assert e11 != e12
示例#25
0
parser = argparse.ArgumentParser()
populate_config_args(parser)
parser.add_argument('-e', '--encode-id', dest='encode_id', help='Encode an ID')
parser.add_argument('-d', '--decode-id', dest='decode_id', help='Decode an ID')
parser.add_argument('--hda',
                    dest='hda_id',
                    help='Display HistoryDatasetAssociation info')
parser.add_argument('--ldda',
                    dest='ldda_id',
                    help='Display LibraryDatasetDatasetAssociation info')
args = parser.parse_args()

app_properties = app_properties_from_args(args)
config = galaxy.config.Configuration(**app_properties)
helper = security.SecurityHelper(id_secret=app_properties.get('id_secret'))
model = galaxy.config.init_models_from_config(config)

if args.encode_id:
    print('Encoded "%s": %s' %
          (args.encode_id, helper.encode_id(args.encode_id)))

if args.decode_id:
    print('Decoded "%s": %s' %
          (args.decode_id, helper.decode_id(args.decode_id)))

if args.hda_id:
    try:
        hda_id = int(args.hda_id)
    except Exception:
        hda_id = int(helper.decode_id(args.hda_id))