Add CORS settings

Allow configuring CORS settings.

Change-Id: Ic6835c1a2020fd8d1017ef9ed5c9965a74287130
This commit is contained in:
Martin André 2016-08-11 15:50:13 +02:00 committed by Emilien Macchi
parent cab4e005ae
commit b846cf783d
3 changed files with 110 additions and 0 deletions

58
manifests/cors.pp Normal file
View File

@ -0,0 +1,58 @@
# == Class: keystone::cors
#
# Configure the keystone cors
#
# === Parameters
#
# [*allowed_origin*]
# (Optional) Indicate whether this resource may be shared with the domain
# received in the requests "origin" header.
# (string value)
# Defaults to $::os_service_default.
#
# [*allow_credentials*]
# (Optional) Indicate that the actual request can include user credentials.
# (boolean value)
# Defaults to $::os_service_default.
#
# [*expose_headers*]
# (Optional) Indicate which headers are safe to expose to the API.
# (list value)
# Defaults to $::os_service_default.
#
# [*max_age*]
# (Optional) Maximum cache age of CORS preflight requests.
# (integer value)
# Defaults to $::os_service_default.
#
# [*allow_methods*]
# (Optional) Indicate which methods can be used during the actual request.
# (list value)
# Defaults to $::os_service_default.
#
# [*allow_headers*]
# (Optional) Indicate which header field names may be used during the actual
# request.
# (list value)
# Defaults to $::os_service_default.
#
class keystone::cors (
$allowed_origin = $::os_service_default,
$allow_credentials = $::os_service_default,
$expose_headers = $::os_service_default,
$max_age = $::os_service_default,
$allow_methods = $::os_service_default,
$allow_headers = $::os_service_default,
) {
include ::keystone::deps
oslo::cors { 'keystone_config':
allowed_origin => $allowed_origin,
allow_credentials => $allow_credentials,
expose_headers => $expose_headers,
max_age => $max_age,
allow_methods => $allow_methods,
allow_headers => $allow_headers,
}
}

View File

@ -0,0 +1,3 @@
---
features:
- allows configuring cors settings.

View File

@ -0,0 +1,49 @@
require 'spec_helper'
describe 'keystone::cors' do
shared_examples_for 'keystone cors' do
it 'configure cors default params' do
is_expected.to contain_keystone_config('cors/allowed_origin').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('cors/allow_credentials').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('cors/expose_headers').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('cors/max_age').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('cors/allow_methods').with_value('<SERVICE DEFAULT>')
is_expected.to contain_keystone_config('cors/allow_headers').with_value('<SERVICE DEFAULT>')
end
context 'with specific parameters' do
let :params do
{ :allowed_origin => '*',
:allow_credentials => true,
:expose_headers => 'Content-Language,Expires',
:max_age => 3600,
:allow_methods => 'GET,POST,PUT,DELETE,OPTIONS',
:allow_headers => 'Content-Type,Cache-Control',
}
end
it 'configure cors params' do
is_expected.to contain_keystone_config('cors/allowed_origin').with_value('*')
is_expected.to contain_keystone_config('cors/allow_credentials').with_value(true)
is_expected.to contain_keystone_config('cors/expose_headers').with_value('Content-Language,Expires')
is_expected.to contain_keystone_config('cors/max_age').with_value(3600)
is_expected.to contain_keystone_config('cors/allow_methods').with_value('GET,POST,PUT,DELETE,OPTIONS')
is_expected.to contain_keystone_config('cors/allow_headers').with_value('Content-Type,Cache-Control')
end
end
end
on_supported_os({
:supported_os => OSDefaults.get_supported_os
}).each do |os,facts|
context "on #{os}" do
let (:facts) do
facts.merge!(OSDefaults.get_facts())
end
it_configures 'keystone cors'
end
end
end