Enable CORS by default

This simplify the deployment and configuration of Gnocchi.

Depends-On: I18eb78d4206c20efc934fe8709881c2bd6972983
Change-Id: I5fc6fca8f54e34f6c932f0e32878b17ab607780b
This commit is contained in:
Julien Danjou 2016-03-09 12:48:24 +01:00
parent 2d7151e14b
commit e275febca9
5 changed files with 10 additions and 28 deletions

View File

@ -272,14 +272,11 @@ function configure_gnocchi {
fi
if [ "$GNOCCHI_USE_KEYSTONE" == "True" ] ; then
iniset $GNOCCHI_PASTE_CONF pipeline:main pipeline gnocchi+auth
if is_service_enabled gnocchi-grafana; then
iniset $GNOCCHI_PASTE_CONF pipeline:main pipeline "cors gnocchi+auth"
iniset $KEYSTONE_CONF cors allowed_origin ${GRAFANA_URL}
iniset $GNOCCHI_CONF cors allowed_origin ${GRAFANA_URL}
iniset $GNOCCHI_CONF cors allow_methods GET,POST,PUT,DELETE,OPTIONS,HEAD,PATCH
iniset $GNOCCHI_CONF cors allow_headers Content-Type,Cache-Control,Content-Language,Expires,Last-Modified,Pragma,X-Auth-Token,X-Subject-Token
else
iniset $GNOCCHI_PASTE_CONF pipeline:main pipeline gnocchi+auth
fi
else
iniset $GNOCCHI_PASTE_CONF pipeline:main pipeline gnocchi+noauth

View File

@ -65,14 +65,6 @@ edit the `api-paste.ini` file to add the Keystone authentication middleware::
[pipeline:main]
pipeline = gnocchi+auth
Also, if you're planning on using `CORS`_ (e.g. to use `Grafana`_), you an also
add the CORS middleware in the server pipeline::
[pipeline:gnocchiv1+auth]
pipeline = keystone_authtoken cors gnocchiv1
With or without Keystone support.
.. _`Paste Deployment`: http://pythonpaste.org/deploy/
.. _`OpenStack Keystone`: http://launchpad.net/keystone
.. _`CORS`: https://en.wikipedia.org/wiki/Cross-origin_resource_sharing

View File

@ -29,26 +29,16 @@ In order to use Gnocchi with Grafana in proxy mode, you just need to:
In order to use Gnocchi with Grafana in direct mode, you need to do a few more
steps:
1. Enable the `CORS`_ middleware. This can be done easily by modifying the
Gnocchi `api-paste.ini` configuration file and adding `cors` into the main
pipeline::
[pieline:main]
pipeline = cors keystone_authtoken gnocchi
This will authorize your browser to make requests to Gnocchi on behalf of
Grafana.
2. Configure the CORS middleware in `gnocchi.conf` to allow request from
1. Configure the CORS middleware in `gnocchi.conf` to allow request from
Grafana::
[cors]
allowed_origin = http://example.com/grafana
allow_headers = Content-Type,Cache-Control,Content-Language,Expires,Last-Modified,Pragma,X-Auth-Token
3. Configure the CORS middleware in Keystone in the same fashion.
2. Configure the CORS middleware in Keystone in the same fashion.
4. Configure a new datasource in Grafana with the Keystone URL, a user, a
3. Configure a new datasource in Grafana with the Keystone URL, a user, a
project and a password. Your browser will query Keystone for a token, and
then query Gnocchi based on what Grafana needs.

View File

@ -5,15 +5,18 @@ pipeline = gnocchi+noauth
[composite:gnocchi+noauth]
use = egg:Paste#urlmap
/ = gnocchiversions
/v1 = gnocchiv1
/v1 = gnocchiv1+noauth
[composite:gnocchi+auth]
use = egg:Paste#urlmap
/ = gnocchiversions
/v1 = gnocchiv1+auth
[pipeline:gnocchiv1+noauth]
pipeline = cors gnocchiv1
[pipeline:gnocchiv1+auth]
pipeline = keystone_authtoken gnocchiv1
pipeline = keystone_authtoken cors gnocchiv1
[app:gnocchiversions]
paste.app_factory = gnocchi.rest.app:app_factory

View File

@ -5,7 +5,7 @@ oslo.log>=1.0.0
oslo.policy>=0.3.0
oslo.serialization>=1.4.0
oslo.utils>=3.3.0
oslo.middleware
oslo.middleware>=3.11.0
pandas>=0.17.0
pecan>=0.9
pytimeparse>=1.1.5