From 4aa042d69bfed798b4927b1dede91722c4439685 Mon Sep 17 00:00:00 2001 From: Takashi Kajinami Date: Thu, 1 Jul 2021 18:28:47 +0900 Subject: [PATCH] Add support for [cors] options Change-Id: Ia30208b782787bd528f1c1be4883b53476a8456f --- manifests/cors.pp | 58 +++++++++++++++++++ releasenotes/notes/cors-dc03ea932c4d6521.yaml | 4 ++ spec/classes/zaqar_cors_spec.rb | 53 +++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 manifests/cors.pp create mode 100644 releasenotes/notes/cors-dc03ea932c4d6521.yaml create mode 100644 spec/classes/zaqar_cors_spec.rb diff --git a/manifests/cors.pp b/manifests/cors.pp new file mode 100644 index 0000000..a9bbf2a --- /dev/null +++ b/manifests/cors.pp @@ -0,0 +1,58 @@ +# == Class: zaqar::cors +# +# Configure the zaqar 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 zaqar::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 zaqar::deps + + oslo::cors { 'zaqar_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/releasenotes/notes/cors-dc03ea932c4d6521.yaml b/releasenotes/notes/cors-dc03ea932c4d6521.yaml new file mode 100644 index 0000000..1764115 --- /dev/null +++ b/releasenotes/notes/cors-dc03ea932c4d6521.yaml @@ -0,0 +1,4 @@ +--- +features: + - | + The new ``zaqar::cors`` class has been added. diff --git a/spec/classes/zaqar_cors_spec.rb b/spec/classes/zaqar_cors_spec.rb new file mode 100644 index 0000000..95dc138 --- /dev/null +++ b/spec/classes/zaqar_cors_spec.rb @@ -0,0 +1,53 @@ +require 'spec_helper' + +describe 'zaqar::cors' do + + shared_examples_for 'zaqar::cors' do + it 'configure cors default params' do + is_expected.to contain_oslo__cors('zaqar_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('zaqar_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_behaves_like 'zaqar::cors' + end + end + +end