Expose headers option of apache::vhost

The headers option in apache::vhost is required in some case, for
example when adding the X-XSS-Protection header. This change allows
customizing the option for the api vhost.

This change also adds support for request_headers so that both request
headers and response headers can customized.

Change-Id: I4ff7ea57f9c1b29b2209506969497b773cef02ec
This commit is contained in:
Takashi Kajinami 2022-06-29 12:32:10 +09:00
parent 357eaf6147
commit d4db053e91
3 changed files with 27 additions and 4 deletions

View File

@ -86,6 +86,14 @@
# { python-path => '/my/python/virtualenv' } # { python-path => '/my/python/virtualenv' }
# Defaults to {} # Defaults to {}
# #
# [*headers*]
# (optional) Headers for the vhost.
# Defaults to undef
#
# [*request_headers*]
# (optional) Modifies collected request headers in various ways.
# Defaults to undef
#
# == Dependencies # == Dependencies
# #
# requires Class['apache'] & Class['cloudkitty'] # requires Class['apache'] & Class['cloudkitty']
@ -117,6 +125,8 @@ class cloudkitty::wsgi::apache (
$access_log_format = false, $access_log_format = false,
$error_log_file = undef, $error_log_file = undef,
$custom_wsgi_process_options = {}, $custom_wsgi_process_options = {},
$headers = undef,
$request_headers = undef,
) { ) {
include cloudkitty::deps include cloudkitty::deps
@ -148,6 +158,8 @@ class cloudkitty::wsgi::apache (
wsgi_script_dir => $::cloudkitty::params::cloudkitty_wsgi_script_path, wsgi_script_dir => $::cloudkitty::params::cloudkitty_wsgi_script_path,
wsgi_script_file => 'app', wsgi_script_file => 'app',
wsgi_script_source => $::cloudkitty::params::cloudkitty_wsgi_script_source, wsgi_script_source => $::cloudkitty::params::cloudkitty_wsgi_script_source,
headers => $headers,
request_headers => $request_headers,
custom_wsgi_process_options => $custom_wsgi_process_options, custom_wsgi_process_options => $custom_wsgi_process_options,
access_log_file => $access_log_file, access_log_file => $access_log_file,
access_log_format => $access_log_format, access_log_format => $access_log_format,

View File

@ -0,0 +1,5 @@
---
features:
- |
The ``cloudkitty::wsgi::apache`` class now supports customizing
request/response headers added by apache.

View File

@ -19,13 +19,15 @@ describe 'cloudkitty::wsgi::apache' do
:wsgi_script_dir => platform_params[:wsgi_script_path], :wsgi_script_dir => platform_params[:wsgi_script_path],
:wsgi_script_file => 'app', :wsgi_script_file => 'app',
:wsgi_script_source => '/usr/bin/cloudkitty-api', :wsgi_script_source => '/usr/bin/cloudkitty-api',
:headers => nil,
:request_headers => nil,
:custom_wsgi_process_options => {}, :custom_wsgi_process_options => {},
:access_log_file => false, :access_log_file => false,
:access_log_format => false, :access_log_format => false,
)} )}
end end
context 'when overriding parameters using different ports' do context 'when overriding parameters' do
let :params do let :params do
{ {
:servername => 'dummy.host', :servername => 'dummy.host',
@ -34,12 +36,14 @@ describe 'cloudkitty::wsgi::apache' do
:ssl => true, :ssl => true,
:wsgi_process_display_name => 'cloudkitty', :wsgi_process_display_name => 'cloudkitty',
:workers => 37, :workers => 37,
:access_log_file => '/var/log/httpd/access_log',
:access_log_format => 'some format',
:error_log_file => '/var/log/httpd/error_log',
:custom_wsgi_process_options => { :custom_wsgi_process_options => {
'python_path' => '/my/python/admin/path', 'python_path' => '/my/python/admin/path',
}, },
:access_log_file => '/var/log/httpd/access_log', :headers => ['set X-XSS-Protection "1; mode=block"'],
:access_log_format => 'some format', :request_headers => ['set Content-Type "application/json"'],
:error_log_file => '/var/log/httpd/error_log'
} }
end end
it { is_expected.to contain_class('cloudkitty::params') } it { is_expected.to contain_class('cloudkitty::params') }
@ -59,6 +63,8 @@ describe 'cloudkitty::wsgi::apache' do
:wsgi_script_dir => platform_params[:wsgi_script_path], :wsgi_script_dir => platform_params[:wsgi_script_path],
:wsgi_script_file => 'app', :wsgi_script_file => 'app',
:wsgi_script_source => '/usr/bin/cloudkitty-api', :wsgi_script_source => '/usr/bin/cloudkitty-api',
:headers => ['set X-XSS-Protection "1; mode=block"'],
:request_headers => ['set Content-Type "application/json"'],
:custom_wsgi_process_options => { :custom_wsgi_process_options => {
'python_path' => '/my/python/admin/path', 'python_path' => '/my/python/admin/path',
}, },