Example #1
0
def _make_standard_crud_endpoints(schema_registry, sqla_registry,
                                  authenticator, db_engine, sqla_metadata):
    """
    these are the datatypes that have standard schemas, and just need
    standard CRUD endpoints (no specialized behavior)
    """
    standard_eps = NestEndpointSet()

    standard_collections = [
        analysis_networks.COLLECTION_NAME, collections.COLLECTION_NAME,
        gene_prioritizations.COLLECTION_NAME,
        gene_set_characterizations.COLLECTION_NAME,
        public_gene_sets.COLLECTION_NAME, sample_clusterings.COLLECTION_NAME,
        species.COLLECTION_NAME
    ]

    for ep_name in standard_collections:
        sqla_maker = sqla_registry[ep_name]
        schema = schema_registry[ep_name]
        db_client = sqla_maker.get_db_client(db_engine, sqla_metadata)
        eps = tablelike_endpoints.generate_endpoints(schema, db_client,
                                                     authenticator)
        standard_eps.add_endpoint_set(eps)
    return standard_eps
Example #2
0
def generate_endpoints(tablelike_schema, crud_db_client, authenticator):
    endpoint_set = NestEndpointSet()
    transcoder = tablelike_schema
    relative_url_base = tablelike_schema.get_name()
    epc = NestCrudCollectionEndpoint(relative_url_base, crud_db_client,
                                     transcoder, authenticator)
    endpoint_set.add_endpoint(epc)

    epe = NestCrudEntryEndpoint(relative_url_base, crud_db_client, transcoder,
                                authenticator)
    endpoint_set.add_endpoint(epe)
    return endpoint_set
Example #3
0
def get_endpoint_set(project_db_client, authenticator):

    rel_url = projects.COLLECTION_NAME
    api_transcoder = projects.generate_schema()        

    collection_ep = ProjectCollectionEndpoint(rel_url, 
        project_db_client, api_transcoder, authenticator)
    entry_ep = ProjectEntryEndpoint(rel_url, 
        project_db_client, api_transcoder, authenticator) 
    eps = NestEndpointSet()
    eps.add_endpoint(collection_ep)
    eps.add_endpoint(entry_ep)
    return eps
Example #4
0
def get_endpoint_set(jobs_db_client, authenticator):
    rel_url = jobs.COLLECTION_NAME
    api_transcoder = jobs.generate_schema()

    collection_ep = JobsCollectionEndpoint(rel_url, jobs_db_client, \
        api_transcoder, authenticator)
    entry_ep = JobsEntryEndpoint(rel_url, jobs_db_client, \
        api_transcoder, authenticator)

    eps = NestEndpointSet()
    eps.add_endpoint(collection_ep)
    eps.add_endpoint(entry_ep)
    return eps
Example #5
0
def get_endpoint_set(files_db_client, authenticator):

    rel_url = files.COLLECTION_NAME
    files_schema = files.generate_schema()

    collection_ep = FileCollectionEndpoint(rel_url, files_db_client, \
        files_schema, authenticator)
    entry_ep = NestCrudEntryEndpoint(rel_url, files_db_client, \
        files_schema, authenticator)

    eps = NestEndpointSet()
    eps.add_endpoint(collection_ep)
    eps.add_endpoint(entry_ep)
    return eps
Example #6
0
def get_nest_endpoints(db_engine, sqla_metadata, authenticator):

    all_endpoints = NestEndpointSet()

    logging_endpoint = LoggingEndpoint(authenticator)
    all_endpoints.add_endpoint(logging_endpoint)

    sessions_endpoint = SessionsEndpoint(authenticator)
    all_endpoints.add_endpoint(sessions_endpoint)

    db_client_registry = omix_db.get_sqla_makers()
    schema_registry = omix_schemas.get_schemas()

    for schema_name in schema_registry:
        db_cm = db_client_registry[schema_name]
        db_client = db_cm.get_db_client(db_engine, sqla_metadata)
        schema = schema_registry[schema_name]
        eps = tablelike_endpoints.generate_endpoints(schema, db_client,
                                                     authenticator)
        all_endpoints.add_endpoint_set(eps)

    return all_endpoints
Example #7
0
def generate_endpoints(db_engine, sqla_metadata, authenticator):
    endpoint_set = NestEndpointSet()    
    #note that we are still using the standard way to build a 
    #db client for a tablelike schema, but we could also create a 
    #different one here if we wanted the database CRUD ops 
    #to work different
    coll_name = hello_tablelike_sub.COLLECTION_NAME
    db_client_maker = hw_db.get_sqla_makers()[coll_name]
    db_client = db_client_maker.get_db_client(db_engine, sqla_metadata)
    schema = hello_tablelike_sub.generate_schema()
    relative_url_base = schema.get_name()
    transcoder = schema
    epc = SubCollectionEndpoint(relative_url_base, 
        db_client, transcoder, authenticator)
    endpoint_set.add_endpoint(epc)
    
    epe = SubEntryEndpoint(relative_url_base, db_client, 
        transcoder, authenticator)
    endpoint_set.add_endpoint(epe)
    return endpoint_set
Example #8
0
def make_simplest_dto_endpoints(db_engine, sqla_metadata, authenticator):
    """
    authenticator (AuthenticationStrategy)
    """
    api_transcoder = SimplestDTOTranscoder()
    sqla_maker = hw_db._make_simplest_dto_sqla_maker()
    db_client = sqla_maker.get_db_client(db_engine, sqla_metadata)
    nest_name = simplest_dto.COLLECTION_NAME

    endpoint_set = NestEndpointSet()

    collection_ep = NestCrudCollectionEndpoint(nest_name, db_client,
                                               api_transcoder, authenticator)
    endpoint_set.add_endpoint(collection_ep)

    entry_ep = NestCrudEntryEndpoint(nest_name, db_client, api_transcoder,
                                     authenticator)
    endpoint_set.add_endpoint(entry_ep)

    return endpoint_set
Example #9
0
def get_nest_endpoints(db_engine, sqla_metadata, authenticator):

    endpoints = NestEndpointSet()

    db_registry = hw_db.get_sqla_makers()
    for schema in hw_schemas.get_schemas():
        name = schema.get_name()
        if name == hello_tablelike_sub.COLLECTION_NAME:
            eps = hello_tablelike_sub_endpoints.generate_endpoints(
                db_engine, sqla_metadata, authenticator)
        else:
            db_cm = db_registry[name]
            db_client = db_cm.get_db_client(db_engine, sqla_metadata)
            eps = tablelike_endpoints.generate_endpoints(
                schema, db_client, authenticator)
        endpoints.add_endpoint_set(eps)

    #below are all endpoints that are not standard CRUD
    #over tablelikes

    dummy_ep = SimplestEndpoint(authenticator)
    endpoints.add_endpoint(dummy_ep)

    simplest_dto_eps = make_simplest_dto_endpoints(db_engine, sqla_metadata,
                                                   authenticator)
    endpoints.add_endpoint_set(simplest_dto_eps)

    whoami_endpoint = WhoamiEndpoint(authenticator)
    endpoints.add_endpoint(whoami_endpoint)

    logging_endpoint = LoggingEndpoint(authenticator)
    endpoints.add_endpoint(logging_endpoint)

    sessions_endpoint = SessionsEndpoint(authenticator)
    endpoints.add_endpoint(sessions_endpoint)

    return endpoints
Example #10
0
def get_nest_endpoints(db_engine, sqla_metadata, authenticator):
    all_eps = NestEndpointSet()

    schema_registry = knoweng_schemas.get_schemas()
    sqla_registry = knoweng_db.get_sqla_makers()

    ##STANDARD CRUD ENDPOINTS
    standard_eps = _make_standard_crud_endpoints(schema_registry,
                                                 sqla_registry, authenticator,
                                                 db_engine, sqla_metadata)
    all_eps.add_endpoint_set(standard_eps)

    ##CLIENT LOGGING
    logging_endpoint = LoggingEndpoint(authenticator)
    all_eps.add_endpoint(logging_endpoint)

    ####FILES
    files_db_client = sqla_registry[files.COLLECTION_NAME].get_db_client(
        db_engine, sqla_metadata)
    files_endpoints_set = files_endpoints.get_endpoint_set(
        files_db_client, authenticator)
    all_eps.add_endpoint_set(files_endpoints_set)

    ####FILE DOWNLOADS
    files_download_endpoint = FileDownloadsEndpoint(files_db_client,
                                                    authenticator)
    all_eps.add_endpoint(files_download_endpoint)

    ####PROJECTS
    projects_db_client = sqla_registry[projects.COLLECTION_NAME].get_db_client(
        db_engine, sqla_metadata)
    projects_endpoints_set = projects_endpoints.get_endpoint_set(
        projects_db_client, authenticator)
    all_eps.add_endpoint_set(projects_endpoints_set)

    ###JOBS
    jobs_db_client = sqla_registry[jobs.COLLECTION_NAME].get_db_client(
        db_engine, sqla_metadata)
    jobs_endpoints_set = jobs_endpoints.get_endpoint_set(
        jobs_db_client, authenticator)
    all_eps.add_endpoint_set(jobs_endpoints_set)

    ###JOB DOWNLOADS
    jobs_download_endpoint = JobDownloadsEndpoint(jobs_db_client,
                                                  authenticator)
    all_eps.add_endpoint(jobs_download_endpoint)

    ##LOGIN
    sessions_endpoint = SessionsEndpoint(authenticator)
    all_eps.add_endpoint(sessions_endpoint)

    project_env_str = os.getenv('PROJECT_ENV', 'knoweng')
    runlevel_str = os.getenv('NEST_RUNLEVEL', 'development')

    project_env = ProjectEnv(project_env_str)
    runlevel = RunLevel(runlevel_str)

    #FIXME: lock DB to prevent duplication errors
    db_ops_utils.ensure_tables_in_db()
    db_ops_utils.seed_users(project_env, runlevel)
    exit_code = _run_seed_cmd({'project': project_env_str})

    if exit_code != 0:
        print('WARNING: non-zero exit code from seed command:' + exit_code)

    return all_eps