Skip to content

Commit

Permalink
Merge pull request #1063 from igalic/expires
Browse files Browse the repository at this point in the history
add parameters to configure expires globally
  • Loading branch information
cmurphy committed Mar 26, 2015
2 parents 3f88b47 + 07f7240 commit 2e6c08b
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 1 deletion.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* [Class: apache::mod::php](#class-apachemodphp)
* [Class: apache::mod::ssl](#class-apachemodssl)
* [Class: apache::mod::status](#class-apachemodstatus)
* [Class: apache::mod::expires](#class-apachemodexpires)
* [Class: apache::mod::wsgi](#class-apachemodwsgi)
* [Class: apache::mod::fcgid](#class-apachemodfcgid)
* [Class: apache::mod::negotiation](#class-apachemodnegotiation)
Expand Down Expand Up @@ -819,6 +820,32 @@ Installs Apache mod_status and uses the status.conf.erb template. These are the
}
```

####Class: `apache::mod::expires`

Installs Apache mod_expires and uses the expires.conf.erb template. These are the defaults:

```puppet
class { 'apache::mod::expires':
expires_active = true,
expires_default = undef,
expires_by_type = undef,
){
}
```

`expires_by_type` is an array of Hashes, describing a set of types and their expire times:

```puppet
class { 'apache::mod::expires':
expires_by_type = [
{ 'text/json' => 'access plus 1 month' },
{ 'text/html' => 'access plus 1 year' },
]
}
```

####Class: `apache::mod::wsgi`

Enables Python support in the WSGI module. To use, simply `include 'apache::mod::wsgi'`.
Expand Down
19 changes: 18 additions & 1 deletion manifests/mod/expires.pp
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
class apache::mod::expires {
class apache::mod::expires (
$expires_active = true,
$expires_default = undef,
$expires_by_type = undef,
) {
::apache::mod { 'expires': }

# Template uses
# $expries_active
# $expries_default
# $expries_by_type
file { 'expires.conf':
ensure => file,
path => "${::apache::mod_dir}/expires.conf",
content => template('apache/mod/expires.conf.erb'),
require => Exec["mkdir ${::apache::mod_dir}"],
before => File[$::apache::mod_dir],
notify => Class['apache::service'],
}
}
84 changes: 84 additions & 0 deletions spec/classes/mod/expires_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
require 'spec_helper'

describe 'apache::mod::expires', :type => :class do
let :pre_condition do
'include apache'
end
context "with expires active", :compile do
let :facts do
{
:id => 'root',
:kernel => 'Linux',
:lsbdistcodename => 'squeeze',
:osfamily => 'Debian',
:operatingsystem => 'Debian',
:operatingsystemrelease => '6',
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
:concat_basedir => '/dne',
:is_pe => false,
}
end
it { is_expected.to contain_apache__mod("expires") }
it { is_expected.to contain_file("expires.conf").with(:content => /ExpiresActive On\n/) }
end
context "with expires default", :compile do
let :pre_condition do
'class { apache: default_mods => false }'
end
let :facts do
{
:id => 'root',
:kernel => 'Linux',
:osfamily => 'RedHat',
:operatingsystem => 'RedHat',
:operatingsystemrelease => '7',
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
:concat_basedir => '/dne',
:is_pe => false,
}
end
let :params do
{
'expires_default' => 'access plus 1 month'
}
end
it { is_expected.to contain_apache__mod("expires") }
it { is_expected.to contain_file("expires.conf").with_content(
"ExpiresActive On\n" \
"ExpiresDefault \"access plus 1 month\"\n"
)
}
end
context "with expires by type", :compile do
let :pre_condition do
'class { apache: default_mods => false }'
end
let :facts do
{
:id => 'root',
:kernel => 'Linux',
:osfamily => 'RedHat',
:operatingsystem => 'RedHat',
:operatingsystemrelease => '7',
:path => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
:concat_basedir => '/dne',
:is_pe => false,
}
end
let :params do
{
'expires_by_type' => [
{ 'text/json' => 'mod plus 1 day' },
{ 'text/html' => 'access plus 1 year' },
]
}
end
it { is_expected.to contain_apache__mod("expires") }
it { is_expected.to contain_file("expires.conf").with_content(
"ExpiresActive On\n" \
"ExpiresByType text/json \"mod plus 1 day\"\n" \
"ExpiresByType text/html \"access plus 1 year\"\n"
)
}
end
end
11 changes: 11 additions & 0 deletions templates/mod/expires.conf.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ExpiresActive <%= scope.function_bool2httpd([@expires_active]) %>
<%- if ! @expires_default.nil? and ! @expires_default.empty? -%>
ExpiresDefault "<%= @expires_default %>"
<%- end -%>
<%- if ! @expires_by_type.nil? and ! @expires_by_type.empty? -%>
<%- [@expires_by_type].flatten.each do |line| -%>
<%- line.map do |type, seconds| -%>
ExpiresByType <%= type %> "<%= seconds -%>"
<%- end -%>
<%- end -%>
<%- end -%>

0 comments on commit 2e6c08b

Please sign in to comment.