From d89a8fef3b01f3593d3d5abeb108b8eadc228971 Mon Sep 17 00:00:00 2001 From: Giacomo Tagliabue Date: Tue, 17 May 2016 11:16:37 -0400 Subject: [PATCH 1/3] Add optional CORS --- caravel/__init__.py | 4 ++++ caravel/config.py | 4 ++++ setup.py | 1 + 3 files changed, 9 insertions(+) diff --git a/caravel/__init__.py b/caravel/__init__.py index 72999097b8ea6..836d9dcedf987 100644 --- a/caravel/__init__.py +++ b/caravel/__init__.py @@ -12,6 +12,7 @@ from flask.ext.appbuilder import SQLA, AppBuilder, IndexView from flask.ext.appbuilder.baseviews import expose from flask.ext.cache import Cache +from flask.ext.cors import CORS from flask.ext.migrate import Migrate from caravel import version @@ -46,6 +47,9 @@ backupCount=app.config.get('BACKUP_COUNT')) logging.getLogger().addHandler(handler) +if app.config.get('ENABLE_CORS'): + CORS(app, **app.config.get('CORS_OPTIONS')) + class MyIndexView(IndexView): @expose('/') diff --git a/caravel/config.py b/caravel/config.py index e20c4ef976862..93934724a18e5 100644 --- a/caravel/config.py +++ b/caravel/config.py @@ -132,6 +132,10 @@ CACHE_DEFAULT_TIMEOUT = None CACHE_CONFIG = {'CACHE_TYPE': 'null'} +# CORS Options +ENABLE_CORS = False +CORS_OPTIONS = {} + # --------------------------------------------------- # List of viz_types not allowed in your environment diff --git a/setup.py b/setup.py index 61cd097edffa8..53c9821843990 100644 --- a/setup.py +++ b/setup.py @@ -20,6 +20,7 @@ 'cryptography>=1.1.1, <2.0.0', 'flask-appbuilder>=1.6.0, <2.0.0', 'Flask-BabelPkg==0.9.6', + 'Flask-Cors>=2.0.0', 'flask-cache>=0.13.1, <0.14.0', 'flask-migrate>=1.5.1, <2.0.0', 'flask-script>=2.0.5, <3.0.0', From 155d5369e37088125316609eae97950b6ad1e650 Mon Sep 17 00:00:00 2001 From: Giacomo Tagliabue Date: Tue, 24 May 2016 11:04:52 -0600 Subject: [PATCH 2/3] make CORS an extra dependency --- caravel/__init__.py | 2 +- setup.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/caravel/__init__.py b/caravel/__init__.py index 836d9dcedf987..34732c0efbf85 100644 --- a/caravel/__init__.py +++ b/caravel/__init__.py @@ -12,7 +12,6 @@ from flask.ext.appbuilder import SQLA, AppBuilder, IndexView from flask.ext.appbuilder.baseviews import expose from flask.ext.cache import Cache -from flask.ext.cors import CORS from flask.ext.migrate import Migrate from caravel import version @@ -48,6 +47,7 @@ logging.getLogger().addHandler(handler) if app.config.get('ENABLE_CORS'): + from flask.ext.cors import CORS CORS(app, **app.config.get('CORS_OPTIONS')) diff --git a/setup.py b/setup.py index 53c9821843990..a5316998bd933 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,6 @@ 'cryptography>=1.1.1, <2.0.0', 'flask-appbuilder>=1.6.0, <2.0.0', 'Flask-BabelPkg==0.9.6', - 'Flask-Cors>=2.0.0', 'flask-cache>=0.13.1, <0.14.0', 'flask-migrate>=1.5.1, <2.0.0', 'flask-script>=2.0.5, <3.0.0', @@ -40,6 +39,9 @@ 'sqlparse>=0.1.16, <0.2.0', 'werkzeug>=0.11.2, <0.12.0', ], + extras_require={ + 'cors': ['Flask-Cors>=2.0.0'], + }, tests_require=['coverage'], author='Maxime Beauchemin', author_email='maximebeauchemin@gmail.com', From 77b06aec6191e5c4cea7a80965984e9e456df192 Mon Sep 17 00:00:00 2001 From: Giacomo Tagliabue Date: Tue, 24 May 2016 11:05:01 -0600 Subject: [PATCH 3/3] add documentation --- docs/installation.rst | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/docs/installation.rst b/docs/installation.rst index 314e1f0eccc15..0de9a287b983e 100644 --- a/docs/installation.rst +++ b/docs/installation.rst @@ -28,7 +28,7 @@ the required dependencies are installed: :: For **Fedora** and **RHEL-derivatives**, the following command will ensure that the required dependencies are installed: :: - + sudo yum upgrade python-setuptools sudo yum install gcc libffi-devel python-devel python-pip python-wheel openssl-devel @@ -228,6 +228,20 @@ Note that you can run the ``caravel refresh_druid`` command to refresh the metadata from your Druid cluster(s) +CORS +----- + +The extra CORS Dependency must be installed: + + caravel[cors] + + +The following keys in `caravel_config.py` can be specified to configure CORS: + + +* ``ENABLE_CORS``: Must be set to True in order to enable CORS +* ``CORS_OPTIONS``: options passed to Flask-CORS (`documentation `) + Upgrading ---------