Skip to content

Commit

Permalink
Allow defining additional Tomcat connectors
Browse files Browse the repository at this point in the history
Add a new, optional class parameter
`confluence::tomcat_additional_connectors` whose value is a well-formed,
complex hash as described by the new type aliases
`Confluence::Tomcat_connectors` and `Confluence::Tomcat_attributes`.
Each hash key represents a port number, and the key's value is a hash
that describes the connector's attributes and their values.

Useful for defining additional HTTP ports through which to access
Confluence.  A typical use case is when Jira and Confluence run behind a
reverse proxy and application links between Jira and Confluence must be
set up.  Then it is often better to allow Jira and Confluence to
communicate directly instead of through the reverse proxy, but this
requires a Tomcat connector that is configured for direct access instead
of reverse proxy access (`proxyName`, `proxyPort`, etc). Described here:
https://confluence.atlassian.com/kb/how-to-create-an-unproxied-application-link-719095740.html

Contains spec tests, documentation and examples.

A very similar PR was submitted to puppet-jira in voxpupuli/puppet-jira#316
  • Loading branch information
antaflos committed Jul 28, 2020
1 parent 9d7eedd commit bb1b495
Show file tree
Hide file tree
Showing 8 changed files with 195 additions and 1 deletion.
2 changes: 2 additions & 0 deletions manifests/config.pp
Expand Up @@ -11,6 +11,8 @@
$manage_server_xml = $confluence::manage_server_xml,
$context_path = $confluence::context_path,
$ajp = $confluence::ajp,
# Additional connectors in server.xml
Confluence::Tomcat_connectors $tomcat_additional_connectors = $confluence::tomcat_additional_connectors,
) {

File {
Expand Down
2 changes: 2 additions & 0 deletions manifests/init.pp
Expand Up @@ -44,6 +44,8 @@
$context_path = '',
# Options for the AJP connector
Hash $ajp = {},
# Additional connectors in server.xml
Confluence::Tomcat_connectors $tomcat_additional_connectors = {},
# Command to stop confluence in preparation to updgrade. This is configurable
# incase the confluence service is managed outside of puppet. eg: using the
# puppetlabs-corosync module: 'crm resource stop confluence && sleep 15'
Expand Down
48 changes: 48 additions & 0 deletions spec/classes/confluence_config_spec.rb
Expand Up @@ -127,6 +127,54 @@
end
end

context 'tomcat additional connectors' do
let(:params) do
{
version: '5.5.6',
javahome: '/opt/java',
manage_server_xml: 'template',
tomcat_additional_connectors: {
8081 => {
'URIEncoding' => 'UTF-8',
'connectionTimeout' => '20000',
'protocol' => 'HTTP/1.1',
'proxyName' => 'foo.example.com',
'proxyPort' => '8123',
'secure' => true,
'scheme' => 'https'
},
8082 => {
'URIEncoding' => 'UTF-8',
'connectionTimeout' => '20000',
'protocol' => 'HTTP/1.1',
'proxyName' => 'bar.example.com',
'proxyPort' => '8124',
'scheme' => 'http'
}
}
}
end

it do
is_expected.to contain_file('/opt/confluence/atlassian-confluence-5.5.6/conf/server.xml').
with_content(%r{<Connector port="8081"}).
with_content(%r{connectionTimeout="20000"}).
with_content(%r{protocol="HTTP/1\.1"}).
with_content(%r{proxyName="foo\.example\.com"}).
with_content(%r{proxyPort="8123"}).
with_content(%r{scheme="https"}).
with_content(%r{secure="true"}).
with_content(%r{URIEncoding="UTF-8"}).
with_content(%r{<Connector port="8082"}).
with_content(%r{connectionTimeout="20000"}).
with_content(%r{protocol="HTTP/1\.1"}).
with_content(%r{proxyName="bar\.example\.com"}).
with_content(%r{proxyPort="8124"}).
with_content(%r{scheme="http"}).
with_content(%r{URIEncoding="UTF-8"})
end
end

context 'catalina_opts set to a string' do
let(:params) do
{
Expand Down
51 changes: 51 additions & 0 deletions spec/type_aliases/tomcat_attributes_spec.rb
@@ -0,0 +1,51 @@
require 'spec_helper'

describe 'Confluence::Tomcat_attributes' do
describe 'valid attributes' do
[
{ 'URIEncoding' => 'UTF-8' },
{ 'secure' => true },
{ 'proxyPort' => 8443 },
{
'URIEncoding' => 'UTF-8',
'connectionTimeout' => '20000',
'protocol' => 'HTTP/1.1',
'proxyName' => 'foo.example.com',
'proxyPort' => '8123',
'secure' => true,
'scheme' => 'https'
},
{}
].each do |value|
describe value.inspect do
it { is_expected.to allow_value(value) }
end
end
end

describe 'invalid attributes' do
context 'with garbage inputs' do
[
{ %w[foo blah] => 'bar' },
{ true => 'false' },
{ 'proxyPort' => %w[8443 1234] },
{ 'schema' => { 'https' => 'false' } },
true,
false,
:keyword,
nil,
%w[yes no],
'',
'ネット',
'55555',
'0x123',
'yess',
'nooo'
].each do |value|
describe value.inspect do
it { is_expected.not_to allow_value(value) }
end
end
end
end
end
80 changes: 80 additions & 0 deletions spec/type_aliases/tomcat_connectors_spec.rb
@@ -0,0 +1,80 @@
require 'spec_helper'

describe 'Confluence::Tomcat_connectors' do
describe 'valid connector specifications' do
[
{
8081 => {
'URIEncoding' => 'UTF-8',
'connectionTimeout' => '20000',
'protocol' => 'HTTP/1.1',
'proxyName' => 'foo.example.com',
'proxyPort' => '80',
'secure' => false,
'scheme' => 'http'
},
8443 => {
'URIEncoding' => 'UTF-8',
'connectionTimeout' => '20000',
'protocol' => 'HTTP/1.1',
'proxyName' => 'foo.example.com',
'proxyPort' => '443',
'secure' => true,
'scheme' => 'https'
}
}
].each do |value|
describe value.inspect do
it { is_expected.to allow_value(value) }
end
end
end

describe 'invalid connector specifications' do
context 'with garbage inputs' do
[
{
'8081' => {
'URIEncoding' => 'UTF-8',
'connectionTimeout' => '20000',
'protocol' => 'HTTP/1.1',
'proxyName' => 'foo.example.com',
'proxyPort' => '80',
'secure' => false,
'scheme' => 'http'
}
},
{
1023 => {
'URIEncoding' => 'UTF-8',
'connectionTimeout' => '20000',
'protocol' => 'HTTP/1.1',
'proxyName' => 'foo.example.com',
'proxyPort' => '80',
'secure' => false,
'scheme' => 'http'
}
},
{ %w[foo blah] => 'bar' },
{ true => 'false' },
{ 'proxyPort' => %w[8443 1234] },
{ 'schema' => { 'https' => 'false' } },
true,
false,
:keyword,
nil,
%w[yes no],
'',
'ネット',
'55555',
'0x123',
'yess',
'nooo'
].each do |value|
describe value.inspect do
it { is_expected.not_to allow_value(value) }
end
end
end
end
end
11 changes: 10 additions & 1 deletion templates/server.xml.erb
Expand Up @@ -16,7 +16,7 @@
<% @tomcat_proxy.sort.each do |key,value| -%>
<%= key %>=<%= "\"#{value}\"" %>
<% end -%>
<% end -%>
<% end -%>
/>

<% if @ajp and ! @ajp.empty? -%>
Expand All @@ -25,6 +25,15 @@
<%= key %> = <%= "\"#{value}\"" %>
<% end -%>
/>
<% end -%>
<% if @tomcat_additional_connectors and ! @tomcat_additional_connectors.empty? -%>
<% @tomcat_additional_connectors.sort.map do |port, attrs| -%>
<Connector port="<%= port -%>"
<% attrs.sort.map do |key, value| -%>
<%= key -%>="<%= value -%>"
<% end -%>
/>
<% end -%>
<% end -%>

<Engine name="Standalone" defaultHost="localhost" debug="0">
Expand Down
1 change: 1 addition & 0 deletions types/tomcat_attributes.pp
@@ -0,0 +1 @@
type Confluence::Tomcat_attributes = Hash[String[1], Scalar]
1 change: 1 addition & 0 deletions types/tomcat_connectors.pp
@@ -0,0 +1 @@
type Confluence::Tomcat_connectors = Hash[Stdlib::Port::Unprivileged, Confluence::Tomcat_attributes]

0 comments on commit bb1b495

Please sign in to comment.