Merge "Added CORS support middleware to Ironic"

This commit is contained in:
Jenkins 2015-09-02 16:06:43 +00:00 committed by Gerrit Code Review
commit b88aace083
5 changed files with 87 additions and 2 deletions

View File

@ -598,6 +598,68 @@
#subprocess_timeout=10 #subprocess_timeout=10
[cors]
#
# Options defined in oslo.middleware.cors
#
# Indicate whether this resource may be shared with the domain
# received in the requests "origin" header. (string value)
#allowed_origin=<None>
# Indicate that the actual request can include user
# credentials (boolean value)
#allow_credentials=true
# Indicate which headers are safe to expose to the API.
# Defaults to HTTP Simple Headers. (list value)
#expose_headers=Content-Type,Cache-Control,Content-Language,Expires,Last-Modified,Pragma
# Maximum cache age of CORS preflight requests. (integer
# value)
#max_age=3600
# Indicate which methods can be used during the actual
# request. (list value)
#allow_methods=GET,POST,PUT,DELETE,OPTIONS
# Indicate which header field names may be used during the
# actual request. (list value)
#allow_headers=Content-Type,Cache-Control,Content-Language,Expires,Last-Modified,Pragma
[cors.subdomain]
#
# Options defined in oslo.middleware.cors
#
# Indicate whether this resource may be shared with the domain
# received in the requests "origin" header. (string value)
#allowed_origin=<None>
# Indicate that the actual request can include user
# credentials (boolean value)
#allow_credentials=true
# Indicate which headers are safe to expose to the API.
# Defaults to HTTP Simple Headers. (list value)
#expose_headers=Content-Type,Cache-Control,Content-Language,Expires,Last-Modified,Pragma
# Maximum cache age of CORS preflight requests. (integer
# value)
#max_age=3600
# Indicate which methods can be used during the actual
# request. (list value)
#allow_methods=GET,POST,PUT,DELETE,OPTIONS
# Indicate which header field names may be used during the
# actual request. (list value)
#allow_headers=Content-Type,Cache-Control,Content-Language,Expires,Last-Modified,Pragma
[database] [database]
# #

View File

@ -16,10 +16,12 @@
# under the License. # under the License.
from oslo_config import cfg from oslo_config import cfg
import oslo_middleware.cors as cors_middleware
import pecan import pecan
from ironic.api import acl from ironic.api import acl
from ironic.api import config from ironic.api import config
from ironic.api.controllers.base import Version
from ironic.api import hooks from ironic.api import hooks
from ironic.api import middleware from ironic.api import middleware
from ironic.common.i18n import _ from ironic.common.i18n import _
@ -73,6 +75,15 @@ def setup_app(pecan_config=None, extra_hooks=None):
wrap_app=middleware.ParsableErrorMiddleware, wrap_app=middleware.ParsableErrorMiddleware,
) )
# Create a CORS wrapper, and attach ironic-specific defaults that must be
# included in all CORS responses.
app = cors_middleware.CORS(app, CONF)
app.set_latent(
allow_headers=[Version.max_string, Version.min_string, Version.string],
allow_methods=['GET', 'PUT', 'POST', 'DELETE', 'PATCH'],
expose_headers=[Version.max_string, Version.min_string, Version.string]
)
if pecan_config.app.enable_acl: if pecan_config.app.enable_acl:
return acl.install(app, cfg.CONF, pecan_config.app.acl_public_routes) return acl.install(app, cfg.CONF, pecan_config.app.acl_public_routes)

View File

@ -27,6 +27,7 @@ oslo.db>=2.4.1 # Apache-2.0
oslo.rootwrap>=2.0.0 # Apache-2.0 oslo.rootwrap>=2.0.0 # Apache-2.0
oslo.i18n>=1.5.0 # Apache-2.0 oslo.i18n>=1.5.0 # Apache-2.0
oslo.log>=1.8.0 # Apache-2.0 oslo.log>=1.8.0 # Apache-2.0
oslo.middleware>=2.8.0 # Apache-2.0
oslo.policy>=0.5.0 # Apache-2.0 oslo.policy>=0.5.0 # Apache-2.0
oslo.serialization>=1.4.0 # Apache-2.0 oslo.serialization>=1.4.0 # Apache-2.0
oslo.service>=0.7.0 # Apache-2.0 oslo.service>=0.7.0 # Apache-2.0

View File

@ -1,2 +1,2 @@
export IRONIC_CONFIG_GENERATOR_EXTRA_LIBRARIES='oslo.db oslo.messaging keystonemiddleware.auth_token oslo.concurrency oslo.policy oslo.log oslo.service.service oslo.service.periodic_task' export IRONIC_CONFIG_GENERATOR_EXTRA_LIBRARIES='oslo.db oslo.messaging oslo.middleware.cors keystonemiddleware.auth_token oslo.concurrency oslo.policy oslo.log oslo.service.service oslo.service.periodic_task'
export IRONIC_CONFIG_GENERATOR_EXTRA_MODULES= export IRONIC_CONFIG_GENERATOR_EXTRA_MODULES=

View File

@ -124,6 +124,14 @@
section: 'DEFAULT', section: 'DEFAULT',
option: 'pecan_debug', value: 'true' option: 'pecan_debug', value: 'true'
} }
- {
section: 'DEFAULT',
option: 'verbose', value: 'true'
}
- {
section: 'DEFAULT',
option: 'debug', value: 'true'
}
- { - {
section: 'oslo_messaging_rabbit', section: 'oslo_messaging_rabbit',
option: 'rabbit_host', value: "{{ip}}" option: 'rabbit_host', value: "{{ip}}"
@ -136,7 +144,10 @@
section: 'oslo_messaging_rabbit', section: 'oslo_messaging_rabbit',
option: 'rabbit_password', value: "ironic" option: 'rabbit_password', value: "ironic"
} }
- { # CORS Domain For Ironic-Webclient's dev server.
section: 'cors',
option: 'allowed_origin', value: "http://localhost:8000"
}
############################################################################# #############################################################################
# Handlers # Handlers