From c5a5729063673df66223eba9a4c3d706f4ce03c1 Mon Sep 17 00:00:00 2001 From: Dan Trainor Date: Tue, 6 Jun 2017 11:13:44 -0400 Subject: [PATCH] Add CORS support to ironic::inspector Extend ironic::inspector by adding CORS support Change-Id: I8c3a6c5e1e7d4521134ea68d36aee5aa9b7f1679 Partial-Bug: 1695202 --- manifests/inspector/cors.pp | 58 +++++++++++++++++++ ...-to-ironic-inspector-24e958a5b3226d5e.yaml | 4 ++ spec/classes/ironic_inspector_cors_spec.rb | 52 +++++++++++++++++ 3 files changed, 114 insertions(+) create mode 100644 manifests/inspector/cors.pp create mode 100644 manifests/releasenotes/notes/add-cors-support-to-ironic-inspector-24e958a5b3226d5e.yaml create mode 100644 spec/classes/ironic_inspector_cors_spec.rb diff --git a/manifests/inspector/cors.pp b/manifests/inspector/cors.pp new file mode 100644 index 00000000..b20c13bd --- /dev/null +++ b/manifests/inspector/cors.pp @@ -0,0 +1,58 @@ +# == Class: ironic::inspector::cors +# +# Configure the ironic inspector 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 ironic::inspector::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 ::ironic::deps + + oslo::cors { 'ironic_inspector_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, + } +} diff --git a/manifests/releasenotes/notes/add-cors-support-to-ironic-inspector-24e958a5b3226d5e.yaml b/manifests/releasenotes/notes/add-cors-support-to-ironic-inspector-24e958a5b3226d5e.yaml new file mode 100644 index 00000000..65e9a09a --- /dev/null +++ b/manifests/releasenotes/notes/add-cors-support-to-ironic-inspector-24e958a5b3226d5e.yaml @@ -0,0 +1,4 @@ +--- +features: + - | + Added CORS support to the ironic::inspector class diff --git a/spec/classes/ironic_inspector_cors_spec.rb b/spec/classes/ironic_inspector_cors_spec.rb new file mode 100644 index 00000000..18d8ccae --- /dev/null +++ b/spec/classes/ironic_inspector_cors_spec.rb @@ -0,0 +1,52 @@ +require 'spec_helper' + +describe 'ironic::inspector::cors' do + + shared_examples_for 'ironic inspector cors' do + + it 'configure cors default params' do + is_expected.to contain_oslo__cors('ironic_inspector_config').with( + :allowed_origin => '', + :allow_credentials => '', + :expose_headers => '', + :max_age => '', + :allow_methods => '', + :allow_headers => '') + 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_oslo__cors('ironic_inspector_config').with( + :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 + 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 'ironic inspector cors' + end + end + +end