def test_getConfig_localConfig_returnFilledLocalConfig(self):
        os.environ[VCAP_SERVICES] = json.dumps({
            'user-provided': [
                {
                    'credentials': {'tokenKey': 'http://uaa.example.com/token_key'},
                    'tags': [],
                    'name': 'sso',
                    'label': 'user-provided'
                }
            ]
        })
        config = DCConfig()

        self.assertEqual(5000, config.app_port)
        self.assertEqual('DEBUG', config.log_level)

        self.assertEqual('localhost', config.elastic.elastic_hostname)
        self.assertEqual(9200, config.elastic.elastic_port)

        self.assertEqual(
            'http://localhost:8091/rest/tables',
            config.services_url.dataset_publisher_url)
        self.assertEqual(
            'http://localhost:9998/rest/orgs/permissions',
            config.services_url.user_management_uri)

        clean_fake_env()
Example #2
0
def get_app():
    """
    To be used by the WSGI server.
    """
    config = DCConfig()
    _configure_logging(config)
    _prepare_environment(config)
    return _create_app(config)
Example #3
0
    def setUp(self):
        setup_fake_env()
        self._config = DCConfig()

        self.app = data_catalog.app._create_app(self._config)
        self.app.config['TESTING'] = True
        self.client = self.app.test_client()

        self.mocked_authenticate = disable_authentication(self.client)
Example #4
0
    def setUp(self):
        setup_fake_env()
        self._config = DCConfig()

        from data_catalog import app
        app.app.config['TESTING'] = True
        self.app = app.app
        self.client = self.app.test_client()

        self._disable_authentication()
    def test_getConfig_alternativeDownloaderSetup_downloaderUrlSet(self):
        def set_alternative_downloader_conf():
            vcap_services = json.loads(os.environ[VCAP_SERVICES])
            del vcap_services['downloader']
            os.environ[VCAP_SERVICES] = json.dumps(vcap_services)

        with fake_env():
            set_alternative_downloader_conf()
            config = DCConfig()
            self.assertEquals(
                'http://downloader-broker.apps.example.com/rest/filestore/{}/',
                config.services_url.downloader_url_pattern)
    def test_getConfig_withCloudEnv_returnCloudConfig(self):
        with fake_env():
            config = DCConfig()
            self.assertEqual(5555, config.app_port)
            self.assertEqual('INFO', config.log_level)

            self.assertEqual('10.10.2.7', config.elastic.elastic_hostname)
            self.assertEqual(49237, config.elastic.elastic_port)

            self.assertEqual('http://uaa.run.example.com/token_key',
                             config.services_url.uaa_token_uri)
            self.assertEqual('http://hive.apps.example.com/rest/tables',
                             config.services_url.dataset_publisher_url)
            self.assertEqual(
                'http://user-management.apps.example.com/rest/orgs/permissions',
                config.services_url.user_management_uri)
Example #7
0
 def _get_token_verification_key(self):
     uaa_public_key = requests.get(
         DCConfig().services_url.uaa_token_uri).json()
     self._uaa_public_key, self._uaa_sign_algorithm = _PublicKeyParser(
     ).parse(uaa_public_key)
Example #8
0
 def __init__(self):
     self._log = logging.getLogger(type(self).__name__)
     self._config = DCConfig()
Example #9
0
 def __init__(self):
     self._config = DCConfig()
     self._log = logging.getLogger(type(self).__name__)
     self._elastic_search = Elasticsearch(
         '{}:{}'.format(self._config.elastic.elastic_hostname,
                        self._config.elastic.elastic_port))
Example #10
0
 def __init__(self):
     super(DataCatalogResource, self).__init__()
     self._config = DCConfig()
     self._log = logging.getLogger(type(self).__name__)
Example #11
0
        if hasattr(e, 'data'):
            message = e.data.get('message')
        if message is None:
            message = getattr(e, 'description', 'Internal Server Error')

        self._log.exception("Exception with timestamp (%d) occured: %s", timestamp, e)

        response = {
            'message'   : message,
            'status'    : code,
            'timestamp' : timestamp
        }
        return self.make_response(response, code)


_CONFIG = DCConfig()

app = Flask(__name__)
# our RESTful API wrapped with Swagger documentation
api = swagger.docs(
    ExceptionHandlingApi(app),
    apiVersion=VERSION,
    description='Data Catalog - enables search, retrieval and storage of metadata '
                'describing data sets. ')

api.add_resource(DataSetSearchResource, _CONFIG.app_base_path)
api.add_resource(MetadataEntryResource, _CONFIG.app_base_path + '/<entry_id>')
api.add_resource(DataSetCountResource, _CONFIG.app_base_path + '/count')
api.add_resource(ElasticSearchAdminResource, _CONFIG.app_base_path + '/admin/elastic')

ignore_for_auth = ['/api/spec']
def dc_app(fake_env_vars):
    config = DCConfig()
    app = data_catalog.app._create_app(config)
    app.config['TESTING'] = True
    return app
 def test_getConfig_noVcapServices_raiseError(self):
     with self.assertRaises(NoConfigEnvError):
         DCConfig()