Ejemplo n.º 1
0
 def __init__(self, args):
     self._key = args.key
     # TODO this is an experimental addition which is useful for
     # testing. We should think about this and document it if we
     # this it's a useful feature. There is an argument for pushing
     # the backend instantiation into the client, and letting the
     # client be a factory, instantiating the correct Client class
     # depending on the prefix.
     filePrefix = "file://"
     if args.baseUrl.startswith(filePrefix):
         dataDir = args.baseUrl[len(filePrefix):]
         theBackend = backend.FileSystemBackend(dataDir)
         self._client = client.LocalClient(theBackend)
     else:
         self._client = client.HttpClient(args.baseUrl,
                                          verbosityToLogLevel(args.verbose),
                                          self._key)
Ejemplo n.º 2
0
 def setUp(self):
     self._dataDir = os.path.join("tests", "data")
     self._variantsDir = os.path.join(self._dataDir, "variants")
     self._vcfs = {}
     self._variants = []
     self._referenceNames = set()
     self._chromFileMap = {}
     for relativePath in os.listdir(self._variantsDir):
         pathToFiles = os.path.join(self._variantsDir, relativePath)
         self._vcfs[relativePath] = []
         for vcfFile in glob.glob(os.path.join(pathToFiles, "*.vcf.gz")):
             self._chromFileMap[relativePath] = {}
             self._vcfs[relativePath].append(vcfFile)
             vcf = pysam.VariantFile(filename=vcfFile)
             for chrom in vcf.index:
                 self._chromFileMap[relativePath][chrom] = vcf
     self._backend = backend.FileSystemBackend(self._dataDir)
Ejemplo n.º 3
0
def configure(configFile=None, baseConfig="ProductionConfig", extraConfig={}):
    """
    TODO Document this critical function! What does it do? What does
    it assume?
    """
    configStr = 'ga4gh.serverconfig:{0}'.format(baseConfig)
    app.config.from_object(configStr)
    if os.environ.get('GA4GH_CONFIGURATION') is not None:
        app.config.from_envvar('GA4GH_CONFIGURATION')
    if configFile is not None:
        app.config.from_pyfile(configFile)
    app.config.update(extraConfig.items())
    # Setup CORS
    cors.CORS(app, allow_headers='Content-Type')
    app.serverStatus = ServerStatus()
    # Allocate the backend
    # TODO is this a good way to determine what type of backend we should
    # instantiate? We should think carefully about this. The approach of
    # using the special strings __SIMULATED__ and __EMPTY__ seems OK for
    # now, but is certainly not ideal.
    dataSource = app.config["DATA_SOURCE"]
    if dataSource == "__SIMULATED__":
        randomSeed = app.config["SIMULATED_BACKEND_RANDOM_SEED"]
        numCalls = app.config["SIMULATED_BACKEND_NUM_CALLS"]
        variantDensity = app.config["SIMULATED_BACKEND_VARIANT_DENSITY"]
        numVariantSets = app.config["SIMULATED_BACKEND_NUM_VARIANT_SETS"]
        theBackend = backend.SimulatedBackend(randomSeed, numCalls,
                                              variantDensity, numVariantSets)
    elif dataSource == "__EMPTY__":
        theBackend = backend.EmptyBackend()
    else:
        theBackend = backend.FileSystemBackend(dataSource)
    theBackend.setRequestValidation(app.config["REQUEST_VALIDATION"])
    theBackend.setResponseValidation(app.config["RESPONSE_VALIDATION"])
    theBackend.setDefaultPageSize(app.config["DEFAULT_PAGE_SIZE"])
    theBackend.setMaxResponseLength(app.config["MAX_RESPONSE_LENGTH"])
    app.backend = theBackend
Ejemplo n.º 4
0
 def setUp(self):
     self._backend = backend.FileSystemBackend("tests/data")
     self._client = client.LocalClient(self._backend)
Ejemplo n.º 5
0
def configure(configFile=None,
              baseConfig="ProductionConfig",
              port=8000,
              extraConfig={}):
    """
    TODO Document this critical function! What does it do? What does
    it assume?
    """
    configStr = 'ga4gh.serverconfig:{0}'.format(baseConfig)
    app.config.from_object(configStr)
    if os.environ.get('GA4GH_CONFIGURATION') is not None:
        app.config.from_envvar('GA4GH_CONFIGURATION')
    if configFile is not None:
        app.config.from_pyfile(configFile)
    app.config.update(extraConfig.items())
    # Setup file handle cache max size
    datamodel.fileHandleCache.setMaxCacheSize(
        app.config["FILE_HANDLE_CACHE_MAX_SIZE"])
    # Setup CORS
    cors.CORS(app, allow_headers='Content-Type')
    app.serverStatus = ServerStatus()
    # Allocate the backend
    # TODO is this a good way to determine what type of backend we should
    # instantiate? We should think carefully about this. The approach of
    # using the special strings __SIMULATED__ and __EMPTY__ seems OK for
    # now, but is certainly not ideal.
    dataSource = app.config["DATA_SOURCE"]
    if dataSource == "__SIMULATED__":
        randomSeed = app.config["SIMULATED_BACKEND_RANDOM_SEED"]
        numCalls = app.config["SIMULATED_BACKEND_NUM_CALLS"]
        variantDensity = app.config["SIMULATED_BACKEND_VARIANT_DENSITY"]
        numVariantSets = app.config["SIMULATED_BACKEND_NUM_VARIANT_SETS"]
        numReferenceSets = app.config["SIMULATED_BACKEND_NUM_REFERENCE_SETS"]
        numReferencesPerReferenceSet = app.config[
            "SIMULATED_BACKEND_NUM_REFERENCES_PER_REFERENCE_SET"]
        numAlignments = app.config[
            "SIMULATED_BACKEND_NUM_ALIGNMENTS_PER_READ_GROUP"]
        theBackend = backend.SimulatedBackend(randomSeed, numCalls,
                                              variantDensity, numVariantSets,
                                              numReferenceSets,
                                              numReferencesPerReferenceSet,
                                              numAlignments)
    elif dataSource == "__EMPTY__":
        theBackend = backend.EmptyBackend()
    else:
        theBackend = backend.FileSystemBackend(dataSource)
    theBackend.setRequestValidation(app.config["REQUEST_VALIDATION"])
    theBackend.setResponseValidation(app.config["RESPONSE_VALIDATION"])
    theBackend.setDefaultPageSize(app.config["DEFAULT_PAGE_SIZE"])
    theBackend.setMaxResponseLength(app.config["MAX_RESPONSE_LENGTH"])
    app.backend = theBackend
    app.secret_key = os.urandom(SECRET_KEY_LENGTH)
    app.oidcClient = None
    app.tokenMap = None
    app.myPort = port
    if "OIDC_PROVIDER" in app.config:
        # The oic client. If we're testing, we don't want to verify
        # SSL certificates
        app.oidcClient = oic.oic.Client(
            verify_ssl=('TESTING' not in app.config))
        app.tokenMap = {}
        try:
            app.oidcClient.provider_config(app.config['OIDC_PROVIDER'])
        except requests.exceptions.ConnectionError:
            configResponse = message.ProviderConfigurationResponse(
                issuer=app.config['OIDC_PROVIDER'],
                authorization_endpoint=app.config['OIDC_AUTHZ_ENDPOINT'],
                token_endpoint=app.config['OIDC_TOKEN_ENDPOINT'],
                revocation_endpoint=app.config['OIDC_TOKEN_REV_ENDPOINT'])
            app.oidcClient.handle_provider_config(configResponse,
                                                  app.config['OIDC_PROVIDER'])

        # The redirect URI comes from the configuration.
        # If we are testing, then we allow the automatic creation of a
        # redirect uri if none is configured
        redirectUri = app.config.get('OIDC_REDIRECT_URI')
        if redirectUri is None and 'TESTING' in app.config:
            redirectUri = 'https://{0}:{1}/oauth2callback'.format(
                socket.gethostname(), app.myPort)
        app.oidcClient.redirect_uris = [redirectUri]
        if redirectUri is []:
            raise exceptions.ConfigurationException(
                'OIDC configuration requires a redirect uri')

        # We only support dynamic registration while testing.
        if ('registration_endpoint' in app.oidcClient.provider_info
                and 'TESTING' in app.config):
            app.oidcClient.register(
                app.oidcClient.provider_info["registration_endpoint"],
                redirect_uris=[redirectUri])
        else:
            response = message.RegistrationResponse(
                client_id=app.config['OIDC_CLIENT_ID'],
                client_secret=app.config['OIDC_CLIENT_SECRET'],
                redirect_uris=[redirectUri],
                verify_ssl=False)
            app.oidcClient.store_registration_info(response)
Ejemplo n.º 6
0
 def setUp(self):
     self._dataDir = "tests/data"
     self._dataUrl = "file://{}".format(self._dataDir)
     self._backend = backend.FileSystemBackend(self._dataDir)
     self._client = client.LocalClient(self._backend)
Ejemplo n.º 7
0
 def setUp(self):
     self._dataDir = os.path.join("tests", "data")
     self._backend = backend.FileSystemBackend(self._dataDir)