From 06ca693df4418bd15d40f75f3d197fbfbee24bc8 Mon Sep 17 00:00:00 2001 From: calebfornari Date: Tue, 31 Dec 2013 17:40:15 -0500 Subject: [PATCH 01/21] Handle cases where IIS has zero existing sites. --- manifests/manage_site.pp | 2 +- spec/defines/manage_site_spec.rb | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/manifests/manage_site.pp b/manifests/manage_site.pp index 0e436e7..c54d1ec 100644 --- a/manifests/manage_site.pp +++ b/manifests/manage_site.pp @@ -17,7 +17,7 @@ $switches = join($createSwitches,' ') exec { "CreateSite-${site_name}" : - command => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; New-WebSite ${switches} \"", + command => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; \$id = (Get-WebSite | foreach {\$_.id} | sort -Descending | select -first 1) + 1; New-WebSite ${switches} -ID \$id \"", path => "${iis::param::powershell::path};${::path}", onlyif => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\${site_name}\\\")) { exit 1 } else { exit 0 }\"", logoutput => true, diff --git a/spec/defines/manage_site_spec.rb b/spec/defines/manage_site_spec.rb index 2e876e6..cec64ba 100644 --- a/spec/defines/manage_site_spec.rb +++ b/spec/defines/manage_site_spec.rb @@ -14,7 +14,7 @@ it { should include_class('iis::param::powershell') } it { should contain_exec('CreateSite-myWebSite').with({ - 'command' => "#{powershell} -Command \"Import-Module WebAdministration; New-WebSite -Name \\\"myWebSite\\\" -Port 80 -IP * -HostHeader \\\"myHost.example.com\\\" -PhysicalPath \\\"C:\\inetpub\\wwwroot\\myWebSite\\\" -ApplicationPool \\\"myAppPool.example.com\\\" -Ssl:$false \"", + 'command' => "#{powershell} -Command \"Import-Module WebAdministration; $id = (Get-WebSite | foreach {$_.id} | sort -Descending | select -first 1) + 1; New-WebSite -Name \\\"myWebSite\\\" -Port 80 -IP * -HostHeader \\\"myHost.example.com\\\" -PhysicalPath \\\"C:\\inetpub\\wwwroot\\myWebSite\\\" -ApplicationPool \\\"myAppPool.example.com\\\" -Ssl:$false -ID $id \"", 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\\")) { exit 1 } else { exit 0 }\"", })} end @@ -33,7 +33,7 @@ it { should include_class('iis::param::powershell') } it { should contain_exec('CreateSite-myWebSite').with({ - 'command' => "#{powershell} -Command \"Import-Module WebAdministration; New-WebSite -Name \\\"myWebSite\\\" -Port 1080 -IP 127.0.0.1 -HostHeader \\\"myHost.example.com\\\" -PhysicalPath \\\"C:\\inetpub\\wwwroot\\path\\\" -ApplicationPool \\\"myAppPool.example.com\\\" -Ssl:$false \"", + 'command' => "#{powershell} -Command \"Import-Module WebAdministration; $id = (Get-WebSite | foreach {$_.id} | sort -Descending | select -first 1) + 1; New-WebSite -Name \\\"myWebSite\\\" -Port 1080 -IP 127.0.0.1 -HostHeader \\\"myHost.example.com\\\" -PhysicalPath \\\"C:\\inetpub\\wwwroot\\path\\\" -ApplicationPool \\\"myAppPool.example.com\\\" -Ssl:$false -ID $id \"", 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\\")) { exit 1 } else { exit 0 }\"", })} end @@ -48,7 +48,7 @@ } } it { should contain_exec('CreateSite-myWebSite').with({ - 'command' => "#{powershell} -Command \"Import-Module WebAdministration; New-WebSite -Name \\\"myWebSite\\\" -Port 80 -IP * -HostHeader \\\"myHost.example.com\\\" -PhysicalPath \\\"C:\\inetpub\\wwwroot\\myWebSite\\\" -ApplicationPool \\\"myAppPool.example.com\\\" -Ssl:$false \"", + 'command' => "#{powershell} -Command \"Import-Module WebAdministration; $id = (Get-WebSite | foreach {$_.id} | sort -Descending | select -first 1) + 1; New-WebSite -Name \\\"myWebSite\\\" -Port 80 -IP * -HostHeader \\\"myHost.example.com\\\" -PhysicalPath \\\"C:\\inetpub\\wwwroot\\myWebSite\\\" -ApplicationPool \\\"myAppPool.example.com\\\" -Ssl:$false -ID $id \"", 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\\")) { exit 1 } else { exit 0 }\"", })} end @@ -63,7 +63,7 @@ } } it { should contain_exec('CreateSite-myWebSite').with({ - 'command' => "#{powershell} -Command \"Import-Module WebAdministration; New-WebSite -Name \\\"myWebSite\\\" -Port 80 -IP * -HostHeader \\\"myHost.example.com\\\" -PhysicalPath \\\"C:\\inetpub\\wwwroot\\myWebSite\\\" -ApplicationPool \\\"myAppPool.example.com\\\" -Ssl:$false \"", + 'command' => "#{powershell} -Command \"Import-Module WebAdministration; $id = (Get-WebSite | foreach {$_.id} | sort -Descending | select -first 1) + 1; New-WebSite -Name \\\"myWebSite\\\" -Port 80 -IP * -HostHeader \\\"myHost.example.com\\\" -PhysicalPath \\\"C:\\inetpub\\wwwroot\\myWebSite\\\" -ApplicationPool \\\"myAppPool.example.com\\\" -Ssl:$false -ID $id \"", 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\\")) { exit 1 } else { exit 0 }\"", })} end From 771b8ca761a8c3d413b51576e46935867777d1d3 Mon Sep 17 00:00:00 2001 From: Caleb Fornari Date: Tue, 31 Dec 2013 18:31:23 -0500 Subject: [PATCH 02/21] Removing extra space as it's breaking the tests. --- spec/defines/manage_site_spec.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/defines/manage_site_spec.rb b/spec/defines/manage_site_spec.rb index cec64ba..6730595 100644 --- a/spec/defines/manage_site_spec.rb +++ b/spec/defines/manage_site_spec.rb @@ -33,7 +33,7 @@ it { should include_class('iis::param::powershell') } it { should contain_exec('CreateSite-myWebSite').with({ - 'command' => "#{powershell} -Command \"Import-Module WebAdministration; $id = (Get-WebSite | foreach {$_.id} | sort -Descending | select -first 1) + 1; New-WebSite -Name \\\"myWebSite\\\" -Port 1080 -IP 127.0.0.1 -HostHeader \\\"myHost.example.com\\\" -PhysicalPath \\\"C:\\inetpub\\wwwroot\\path\\\" -ApplicationPool \\\"myAppPool.example.com\\\" -Ssl:$false -ID $id \"", + 'command' => "#{powershell} -Command \"Import-Module WebAdministration; $id = (Get-WebSite | foreach {$_.id} | sort -Descending | select -first 1) + 1; New-WebSite -Name \\\"myWebSite\\\" -Port 1080 -IP 127.0.0.1 -HostHeader \\\"myHost.example.com\\\" -PhysicalPath \\\"C:\\inetpub\\wwwroot\\path\\\" -ApplicationPool \\\"myAppPool.example.com\\\" -Ssl:$false -ID $id \"", 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\\")) { exit 1 } else { exit 0 }\"", })} end @@ -97,4 +97,4 @@ 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if(!(Test-Path \\\"IIS:\\Sites\\myWebSite\\\")) { exit 1 } else { exit 0 }\"", })} end -end \ No newline at end of file +end From 285c6d759dcc353b953cf45be029ab4c338103a0 Mon Sep 17 00:00:00 2001 From: Drew Wilson Date: Fri, 7 Feb 2014 09:48:23 +0000 Subject: [PATCH 03/21] update website physicalPath and ApplicationPool for existing websites --- manifests/manage_site.pp | 23 ++++++++++++++++-- spec/defines/manage_site_spec.rb | 40 ++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/manifests/manage_site.pp b/manifests/manage_site.pp index 0e436e7..153d138 100644 --- a/manifests/manage_site.pp +++ b/manifests/manage_site.pp @@ -7,7 +7,10 @@ if ($ensure in ['present','installed']) { iis::createpath { "${site_name}-${site_path}": site_path => $site_path - } + } + + $cmdSiteExists = "Test-Path \\\"IIS:\\Sites\\${site_name}\\\"" + $createSwitches = ["-Name \\\"${site_name}\\\"", "-Port ${port} -IP ${ip_address}", "-HostHeader \\\"${host_header}\\\"", @@ -19,10 +22,26 @@ exec { "CreateSite-${site_name}" : command => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; New-WebSite ${switches} \"", path => "${iis::param::powershell::path};${::path}", - onlyif => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\${site_name}\\\")) { exit 1 } else { exit 0 }\"", + onlyif => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; if((${$cmdSiteExists})) { exit 1 } else { exit 0 }\"", logoutput => true, require => [ Iis::Createpath["${site_name}-${site_path}"], Iis::Manage_app_pool[$app_pool] ], } + + exec { "UpdateSite-PhysicalPath-${site_name}": + command => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; Set-ItemProperty \\\"IIS:\\Sites\\${site_name}\\\" -Name physicalPath -Value \\\"${site_path}\\\"\"", + onlyif => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; if((${$cmdSiteExists}) -eq \$false) { exit 1 } if ((Get-ItemProperty \\\"IIS:\\Sites\\${site_name}\\\" physicalPath) -eq \\\"${site_path}\\\") { exit 1 } else { exit 0 }\"", + path => "${iis::param::powershell::path};${::path}", + logoutput => true, + before => Exec["CreateSite-${site_name}"], + } + + exec { "UpdateSite-ApplicationPool-${site_name}": + command => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; Set-ItemProperty \\\"IIS:\\Sites\\${site_name}\\\" -Name applicationPool -Value \\\"${app_pool}\\\"\"", + onlyif => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; if((${$cmdSiteExists}) -eq \$false) { exit 1 } if((Get-ItemProperty \\\"IIS:\\Sites\\${site_name}\\\" applicationPool) -eq \\\"${app_pool}\\\") { exit 1 } else { exit 0 }\"", + path => "${iis::param::powershell::path};${::path}", + logoutput => true, + before => Exec["CreateSite-${site_name}"], + } } else { exec { "DeleteSite-${site_name}" : command => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; Remove-WebSite -Name \\\"${site_name}\\\"\"", diff --git a/spec/defines/manage_site_spec.rb b/spec/defines/manage_site_spec.rb index 2e876e6..0aa09aa 100644 --- a/spec/defines/manage_site_spec.rb +++ b/spec/defines/manage_site_spec.rb @@ -17,6 +17,16 @@ 'command' => "#{powershell} -Command \"Import-Module WebAdministration; New-WebSite -Name \\\"myWebSite\\\" -Port 80 -IP * -HostHeader \\\"myHost.example.com\\\" -PhysicalPath \\\"C:\\inetpub\\wwwroot\\myWebSite\\\" -ApplicationPool \\\"myAppPool.example.com\\\" -Ssl:$false \"", 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\\")) { exit 1 } else { exit 0 }\"", })} + + it { should contain_exec('UpdateSite-PhysicalPath-myWebSite').with({ + 'command' => "#{powershell} -Command \"Import-Module WebAdministration; Set-ItemProperty \\\"IIS:\\Sites\\myWebSite\\\" -Name physicalPath -Value \\\"C:\\inetpub\\wwwroot\\myWebSite\\\"\"", + 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\\") -eq \$false) { exit 1 } if ((Get-ItemProperty \\\"IIS:\\Sites\\myWebSite\\\" physicalPath) -eq \\\"C:\\inetpub\\wwwroot\\myWebSite\\\") { exit 1 } else { exit 0 }\"", + })} + + it { should contain_exec('UpdateSite-ApplicationPool-myWebSite').with({ + 'command' => "#{powershell} -Command \"Import-Module WebAdministration; Set-ItemProperty \\\"IIS:\\Sites\\myWebSite\\\" -Name applicationPool -Value \\\"myAppPool.example.com\\\"\"", + 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\\") -eq \$false) { exit 1 } if((Get-ItemProperty \\\"IIS:\\Sites\\myWebSite\\\" applicationPool) -eq \\\"myAppPool.example.com\\\") { exit 1 } else { exit 0 }\"", + })} end describe 'when managing the iis site passing in all parameters' do @@ -36,6 +46,16 @@ 'command' => "#{powershell} -Command \"Import-Module WebAdministration; New-WebSite -Name \\\"myWebSite\\\" -Port 1080 -IP 127.0.0.1 -HostHeader \\\"myHost.example.com\\\" -PhysicalPath \\\"C:\\inetpub\\wwwroot\\path\\\" -ApplicationPool \\\"myAppPool.example.com\\\" -Ssl:$false \"", 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\\")) { exit 1 } else { exit 0 }\"", })} + + it { should contain_exec('UpdateSite-PhysicalPath-myWebSite').with({ + 'command' => "#{powershell} -Command \"Import-Module WebAdministration; Set-ItemProperty \\\"IIS:\\Sites\\myWebSite\\\" -Name physicalPath -Value \\\"C:\\inetpub\\wwwroot\\path\\\"\"", + 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\\") -eq \$false) { exit 1 } if ((Get-ItemProperty \\\"IIS:\\Sites\\myWebSite\\\" physicalPath) -eq \\\"C:\\inetpub\\wwwroot\\path\\\") { exit 1 } else { exit 0 }\"", + })} + + it { should contain_exec('UpdateSite-ApplicationPool-myWebSite').with({ + 'command' => "#{powershell} -Command \"Import-Module WebAdministration; Set-ItemProperty \\\"IIS:\\Sites\\myWebSite\\\" -Name applicationPool -Value \\\"myAppPool.example.com\\\"\"", + 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\\") -eq \$false) { exit 1 } if((Get-ItemProperty \\\"IIS:\\Sites\\myWebSite\\\" applicationPool) -eq \\\"myAppPool.example.com\\\") { exit 1 } else { exit 0 }\"", + })} end describe 'when managing the iis site and setting ensure to present' do @@ -51,6 +71,16 @@ 'command' => "#{powershell} -Command \"Import-Module WebAdministration; New-WebSite -Name \\\"myWebSite\\\" -Port 80 -IP * -HostHeader \\\"myHost.example.com\\\" -PhysicalPath \\\"C:\\inetpub\\wwwroot\\myWebSite\\\" -ApplicationPool \\\"myAppPool.example.com\\\" -Ssl:$false \"", 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\\")) { exit 1 } else { exit 0 }\"", })} + + it { should contain_exec('UpdateSite-PhysicalPath-myWebSite').with({ + 'command' => "#{powershell} -Command \"Import-Module WebAdministration; Set-ItemProperty \\\"IIS:\\Sites\\myWebSite\\\" -Name physicalPath -Value \\\"C:\\inetpub\\wwwroot\\myWebSite\\\"\"", + 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\\") -eq \$false) { exit 1 } if ((Get-ItemProperty \\\"IIS:\\Sites\\myWebSite\\\" physicalPath) -eq \\\"C:\\inetpub\\wwwroot\\myWebSite\\\") { exit 1 } else { exit 0 }\"", + })} + + it { should contain_exec('UpdateSite-ApplicationPool-myWebSite').with({ + 'command' => "#{powershell} -Command \"Import-Module WebAdministration; Set-ItemProperty \\\"IIS:\\Sites\\myWebSite\\\" -Name applicationPool -Value \\\"myAppPool.example.com\\\"\"", + 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\\") -eq \$false) { exit 1 } if((Get-ItemProperty \\\"IIS:\\Sites\\myWebSite\\\" applicationPool) -eq \\\"myAppPool.example.com\\\") { exit 1 } else { exit 0 }\"", + })} end describe 'when managing the iis site and setting ensure to installed' do @@ -66,6 +96,16 @@ 'command' => "#{powershell} -Command \"Import-Module WebAdministration; New-WebSite -Name \\\"myWebSite\\\" -Port 80 -IP * -HostHeader \\\"myHost.example.com\\\" -PhysicalPath \\\"C:\\inetpub\\wwwroot\\myWebSite\\\" -ApplicationPool \\\"myAppPool.example.com\\\" -Ssl:$false \"", 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\\")) { exit 1 } else { exit 0 }\"", })} + + it { should contain_exec('UpdateSite-PhysicalPath-myWebSite').with({ + 'command' => "#{powershell} -Command \"Import-Module WebAdministration; Set-ItemProperty \\\"IIS:\\Sites\\myWebSite\\\" -Name physicalPath -Value \\\"C:\\inetpub\\wwwroot\\myWebSite\\\"\"", + 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\\") -eq \$false) { exit 1 } if ((Get-ItemProperty \\\"IIS:\\Sites\\myWebSite\\\" physicalPath) -eq \\\"C:\\inetpub\\wwwroot\\myWebSite\\\") { exit 1 } else { exit 0 }\"", + })} + + it { should contain_exec('UpdateSite-ApplicationPool-myWebSite').with({ + 'command' => "#{powershell} -Command \"Import-Module WebAdministration; Set-ItemProperty \\\"IIS:\\Sites\\myWebSite\\\" -Name applicationPool -Value \\\"myAppPool.example.com\\\"\"", + 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Test-Path \\\"IIS:\\Sites\\myWebSite\\\") -eq \$false) { exit 1 } if((Get-ItemProperty \\\"IIS:\\Sites\\myWebSite\\\" applicationPool) -eq \\\"myAppPool.example.com\\\") { exit 1 } else { exit 0 }\"", + })} end describe 'when managing the iis site and setting ensure to absent' do From 8f86745499f05983d892a74ebc167d6783b2ac4d Mon Sep 17 00:00:00 2001 From: Paul Stack Date: Wed, 19 Feb 2014 00:07:36 +0000 Subject: [PATCH 04/21] Update Modulefile --- Modulefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modulefile b/Modulefile index 397315b..de32a16 100644 --- a/Modulefile +++ b/Modulefile @@ -1,5 +1,5 @@ name 'opentable/iis' -version '0.0.1' +version '0.0.2' author 'opentable' license 'MIT' summary 'Module that will manage IIS for windows server 2008 and above. It will help maintain application pools, sites and virtual applications' From 077e9595f739561839b4a17ff912da6abbaad469 Mon Sep 17 00:00:00 2001 From: stack72 Date: Mon, 14 Apr 2014 09:38:47 +0100 Subject: [PATCH 05/21] Added .ruby-version file - this will mean we default to ruby 2.0.0 --- .ruby-version | 1 + 1 file changed, 1 insertion(+) create mode 100644 .ruby-version diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..abf2cce --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +ruby-2.0.0-p247 From 2d1e6597bbe932bdc35ad9629a3167ad5f331118 Mon Sep 17 00:00:00 2001 From: stack72 Date: Mon, 14 Apr 2014 11:05:14 +0100 Subject: [PATCH 06/21] Updating the powershell and the specs to use certificate thumbprint rather than certificate name --- manifests/manage_binding.pp | 8 ++++---- spec/defines/manage_binding_spec.rb | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/manifests/manage_binding.pp b/manifests/manage_binding.pp index 9951520..24a1334 100644 --- a/manifests/manage_binding.pp +++ b/manifests/manage_binding.pp @@ -1,4 +1,4 @@ -define iis::manage_binding($site_name, $protocol, $port, $host_header = '', $ip_address = '*', $certificate_name = '', $ensure = 'present') { +define iis::manage_binding($site_name, $protocol, $port, $host_header = '', $ip_address = '*', $certificate_thumbprint = '', $ensure = 'present') { include 'iis::param::powershell' if ! ($protocol in [ 'http', 'https', 'net.tcp', 'net.pipe', 'netmsmq', 'msmq.formatname' ]) { @@ -23,15 +23,15 @@ } if ($protocol == 'https') { - validate_re($certificate_name, ['^(.)+$'], 'certificate_name required for https bindings') + validate_re($certificate_thumbprint, ['^(.)+$'], 'certificate_thumbprint required for https bindings') if ($ip_address == '*' or $ip_address == '0.0.0.0') { fail('https bindings require a valid ip_address') } exec { "Attach-Certificate-${title}": path => "${iis::param::powershell::path};${::path}", - command => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; New-Item \\\"IIS:\\SslBindings\\${ip_address}!${port}\\\" -Value (Get-ChildItem cert:\\ -Recurse | Where-Object {\$_.FriendlyName.Equals(\\\"${certificate_name}\\\")} | Select-Object -First 1)\"", - onlyif => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; if((Get-ChildItem cert:\\ -Recurse | Where-Object {\$_.FriendlyName.Equals(\\\"${certificate_name}\\\")} | Select-Object -First 1) -and ((Test-Path \\\"IIS:\\SslBindings\\${ip_address}!${port}\\\") -eq \$false)) { exit 0 } else { exit 1 }\"", + command => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; New-Item \\\"IIS:\\SslBindings\\${ip_address}!${port}\\\" -Value (Get-ChildItem cert:\\ -Recurse | Where-Object {\$_.Thumbprint.Equals(\\\"${certificate_thumbprint}\\\")} | Select-Object -First 1)\"", + onlyif => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; if((Get-ChildItem cert:\\ -Recurse | Where-Object {\$_.Thumbprint.Equals(\\\"${certificate_thumbprint}\\\")} | Select-Object -First 1) -and ((Test-Path \\\"IIS:\\SslBindings\\${ip_address}!${port}\\\") -eq \$false)) { exit 0 } else { exit 1 }\"", require => Exec["CreateBinding-${title}"], logoutput => true, } diff --git a/spec/defines/manage_binding_spec.rb b/spec/defines/manage_binding_spec.rb index c06d5ea..5682e8c 100644 --- a/spec/defines/manage_binding_spec.rb +++ b/spec/defines/manage_binding_spec.rb @@ -82,14 +82,14 @@ :ip_address => '127.0.0.1', } } - it { expect { should contain_exec('Attach-Certificate-myWebSite-port-443')}.to raise_error(Puppet::Error, /certificate_name required for https bindings/) } + it { expect { should contain_exec('Attach-Certificate-myWebSite-port-443')}.to raise_error(Puppet::Error, /certificate_thumbprint required for https bindings/) } end describe 'when protocol is https and ip address *' do let(:title) { 'myWebSite-port-443' } let(:params) { { :site_name => 'myWebSite', - :certificate_name => 'myCertificate', + :certificate_thumbprint => 'myCertificate', :protocol => 'https', :port => '443', :ip_address => '*', @@ -102,7 +102,7 @@ let(:title) { 'myWebSite-port-443' } let(:params) { { :site_name => 'myWebSite', - :certificate_name => 'myCertificate', + :certificate_thumbprint => 'myCertificate', :protocol => 'https', :port => '443', :ip_address => '0.0.0.0', @@ -115,15 +115,15 @@ let(:title) { 'myWebSite-port-443' } let(:params) { { :site_name => 'myWebSite', - :certificate_name => 'myCertificate', + :certificate_thumbprint => 'myCertificate', :protocol => 'https', :port => '443', :ip_address => '127.0.0.1', } } it { should contain_exec('Attach-Certificate-myWebSite-port-443').with({ - 'command' => "#{powershell} -Command \"Import-Module WebAdministration; New-Item \\\"IIS:\\SslBindings\\127.0.0.1!443\\\" -Value (Get-ChildItem cert:\\ -Recurse | Where-Object {\$_.FriendlyName.Equals(\\\"myCertificate\\\")} | Select-Object -First 1)\"", - 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Get-ChildItem cert:\\ -Recurse | Where-Object {\$_.FriendlyName.Equals(\\\"myCertificate\\\")} | Select-Object -First 1) -and ((Test-Path \\\"IIS:\\SslBindings\\127.0.0.1!443\\\") -eq \$false)) { exit 0 } else { exit 1 }\"", + 'command' => "#{powershell} -Command \"Import-Module WebAdministration; New-Item \\\"IIS:\\SslBindings\\127.0.0.1!443\\\" -Value (Get-ChildItem cert:\\ -Recurse | Where-Object {\$_.Thumbprint.Equals(\\\"myCertificate\\\")} | Select-Object -First 1)\"", + 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Get-ChildItem cert:\\ -Recurse | Where-Object {\$_.Thumbprint.Equals(\\\"myCertificate\\\")} | Select-Object -First 1) -and ((Test-Path \\\"IIS:\\SslBindings\\127.0.0.1!443\\\") -eq \$false)) { exit 0 } else { exit 1 }\"", })} end From 6b178a57f6ab740200f7367dbe73df4d561633b8 Mon Sep 17 00:00:00 2001 From: stack72 Date: Mon, 14 Apr 2014 17:30:39 +0100 Subject: [PATCH 07/21] Updating the Modulefile to 1.0.0 as this is a breaking change. We are now using certificate_thumbprint rather than certificate_name --- Modulefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modulefile b/Modulefile index de32a16..26ae738 100644 --- a/Modulefile +++ b/Modulefile @@ -1,5 +1,5 @@ name 'opentable/iis' -version '0.0.2' +version '1.0.0' author 'opentable' license 'MIT' summary 'Module that will manage IIS for windows server 2008 and above. It will help maintain application pools, sites and virtual applications' From 1e2d40d981e3d32864a5e143c52c81434d58f5eb Mon Sep 17 00:00:00 2001 From: stack72 Date: Wed, 16 Apr 2014 09:10:33 +0100 Subject: [PATCH 08/21] Fixing the linting error of the => lining up --- spec/defines/manage_binding_spec.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/spec/defines/manage_binding_spec.rb b/spec/defines/manage_binding_spec.rb index 5682e8c..6ba891b 100644 --- a/spec/defines/manage_binding_spec.rb +++ b/spec/defines/manage_binding_spec.rb @@ -88,11 +88,11 @@ describe 'when protocol is https and ip address *' do let(:title) { 'myWebSite-port-443' } let(:params) { { - :site_name => 'myWebSite', + :site_name => 'myWebSite', :certificate_thumbprint => 'myCertificate', - :protocol => 'https', - :port => '443', - :ip_address => '*', + :protocol => 'https', + :port => '443', + :ip_address => '*', } } it { expect { should contain_exec('Attach-Certificate-myWebSite-port-443')}.to raise_error(Puppet::Error, /https bindings require a valid ip_address/) } @@ -114,11 +114,11 @@ describe 'when protocol is https and all required parameters exist' do let(:title) { 'myWebSite-port-443' } let(:params) { { - :site_name => 'myWebSite', + :site_name => 'myWebSite', :certificate_thumbprint => 'myCertificate', - :protocol => 'https', - :port => '443', - :ip_address => '127.0.0.1', + :protocol => 'https', + :port => '443', + :ip_address => '127.0.0.1', } } it { should contain_exec('Attach-Certificate-myWebSite-port-443').with({ From 2b6c61ebc4a56b56c1e016199c7e14af1f152e53 Mon Sep 17 00:00:00 2001 From: stack72 Date: Wed, 16 Apr 2014 09:13:40 +0100 Subject: [PATCH 09/21] Drew found more linting errors - hes a stickler for the rules --- spec/defines/manage_binding_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/defines/manage_binding_spec.rb b/spec/defines/manage_binding_spec.rb index 6ba891b..45970ed 100644 --- a/spec/defines/manage_binding_spec.rb +++ b/spec/defines/manage_binding_spec.rb @@ -101,11 +101,11 @@ describe 'when protocol is https and ip address 0.0.0.0' do let(:title) { 'myWebSite-port-443' } let(:params) { { - :site_name => 'myWebSite', + :site_name => 'myWebSite', :certificate_thumbprint => 'myCertificate', - :protocol => 'https', - :port => '443', - :ip_address => '0.0.0.0', + :protocol => 'https', + :port => '443', + :ip_address => '0.0.0.0', } } it { expect { should contain_exec('Attach-Certificate-myWebSite-port-443')}.to raise_error(Puppet::Error, /https bindings require a valid ip_address/) } From 2ed763dd0c2586a366413e72c875269dbc8296b2 Mon Sep 17 00:00:00 2001 From: stack72 Date: Tue, 22 Apr 2014 10:48:46 +0100 Subject: [PATCH 10/21] Adding the work to inspect the certificate attached to the current binding and then change it if necessary --- Modulefile | 1 + manifests/manage_binding.pp | 20 +++++++++++++++---- templates/create-certificate-binding.ps1.erb | 15 ++++++++++++++ templates/inspect-certificate-binding.ps1.erb | 17 ++++++++++++++++ 4 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 templates/create-certificate-binding.ps1.erb create mode 100644 templates/inspect-certificate-binding.ps1.erb diff --git a/Modulefile b/Modulefile index 26ae738..8c1b268 100644 --- a/Modulefile +++ b/Modulefile @@ -5,3 +5,4 @@ license 'MIT' summary 'Module that will manage IIS for windows server 2008 and above. It will help maintain application pools, sites and virtual applications' project_page 'https://github.com/opentable/puppet-iis' dependency 'puppetlabs/stdlib', '>=3.0.0' +dependency 'joshcooper/powershell', '>=0.0.6' diff --git a/manifests/manage_binding.pp b/manifests/manage_binding.pp index 24a1334..c48fb64 100644 --- a/manifests/manage_binding.pp +++ b/manifests/manage_binding.pp @@ -28,11 +28,23 @@ fail('https bindings require a valid ip_address') } + file { "inspect-${title}-certificate.ps1": + ensure => present, + path => "C:\\temp\\inspect-${name}.ps1", + content => template('iis/inspect-certificate-binding.ps1'), + } + + file { "create-${title}-certificate.ps1": + ensure => present, + path => "C:\\temp\\create-${name}.ps1", + content => template('iis/create-certificate-binding.ps1'), + } + exec { "Attach-Certificate-${title}": - path => "${iis::param::powershell::path};${::path}", - command => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; New-Item \\\"IIS:\\SslBindings\\${ip_address}!${port}\\\" -Value (Get-ChildItem cert:\\ -Recurse | Where-Object {\$_.Thumbprint.Equals(\\\"${certificate_thumbprint}\\\")} | Select-Object -First 1)\"", - onlyif => "${iis::param::powershell::command} -Command \"Import-Module WebAdministration; if((Get-ChildItem cert:\\ -Recurse | Where-Object {\$_.Thumbprint.Equals(\\\"${certificate_thumbprint}\\\")} | Select-Object -First 1) -and ((Test-Path \\\"IIS:\\SslBindings\\${ip_address}!${port}\\\") -eq \$false)) { exit 0 } else { exit 1 }\"", - require => Exec["CreateBinding-${title}"], + command => "C:\\temp\\create-${name}.ps1", + onlfif => "C:\\temp\\inspect-${name}.ps1", + require => [File["inspect-${title}-certificate.ps1"], File["create-${title}-certificate.ps1"]], + provider => powershell, logoutput => true, } } diff --git a/templates/create-certificate-binding.ps1.erb b/templates/create-certificate-binding.ps1.erb new file mode 100644 index 0000000..28ac89e --- /dev/null +++ b/templates/create-certificate-binding.ps1.erb @@ -0,0 +1,15 @@ +Import-Module WebAdministration + +$site = Get-Website | Where-Object { $_.Name -eq "<%= site_name %>" } +$certsAttachedToSite = Get-ChildItem IIS:\SSLBindings | ? { $site | Select-Object { $_ -contains $_.Sites.Value }} | % { $_.Thumbprint } +$certificate = Get-ChildItem CERT:\LocalMachine\My | ? { $certsAttachedToSite -contains $_.Thumbprint} | Where-Object { $_.Thumbprint -eq "<%= certificate_thumbprint %>" } + +if((Test-Path IIS:\SslBindings\$ip!$port) -eq $false) { + Get-Item Cert:\LocalMachine\My\<%= certificate_thumbprint %> | New-Item <%= ip_address %>!443 +} +elseif (($certificate -ne $null) -and ($certificate.Thumbprint -ne "") { + Get-Item Cert:\LocalMachine\My\<%= certificate_thumbprint %> | Set-Item <%= ip_address %>!<%= port %> +} +else { + exit 0 +} \ No newline at end of file diff --git a/templates/inspect-certificate-binding.ps1.erb b/templates/inspect-certificate-binding.ps1.erb new file mode 100644 index 0000000..607bd1c --- /dev/null +++ b/templates/inspect-certificate-binding.ps1.erb @@ -0,0 +1,17 @@ +Import-Module WebAdministration + +if((Test-Path IIS:\SslBindings\<%= ip_address %>!<%= port %>) -eq $true) { + $site = Get-Website | Where-Object { $_.Name -eq "<%= site_name %>" } + $certsAttachedToSite = Get-ChildItem IIS:\SSLBindings | ? { $site | Select-Object { $_ -contains $_.Sites.Value }} | % { $_.Thumbprint } + $certificate = Get-ChildItem CERT:\LocalMachine\My | ? { $certsAttachedToSite -contains $_.Thumbprint} | Where-Object { $_.Thumbprint -eq "<%= certificate_thumbprint %>" } + if ($certificate -ne $null ){ + exit 1 + } + else { + exit 0 + } +} +else { + exit 1 +} + From 49272cdf6dc895a6a8b551fb21bbcc0a02602180 Mon Sep 17 00:00:00 2001 From: stack72 Date: Tue, 22 Apr 2014 12:45:35 +0100 Subject: [PATCH 11/21] Fixing the addition of the certificate to make it idempotent and clean up after itself and not leave extra IIS bindings in there --- templates/create-certificate-binding.ps1.erb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/templates/create-certificate-binding.ps1.erb b/templates/create-certificate-binding.ps1.erb index 28ac89e..64dc764 100644 --- a/templates/create-certificate-binding.ps1.erb +++ b/templates/create-certificate-binding.ps1.erb @@ -5,10 +5,17 @@ $certsAttachedToSite = Get-ChildItem IIS:\SSLBindings | ? { $site | Select-Objec $certificate = Get-ChildItem CERT:\LocalMachine\My | ? { $certsAttachedToSite -contains $_.Thumbprint} | Where-Object { $_.Thumbprint -eq "<%= certificate_thumbprint %>" } if((Test-Path IIS:\SslBindings\$ip!$port) -eq $false) { + push-location IIS:\SslBindings Get-Item Cert:\LocalMachine\My\<%= certificate_thumbprint %> | New-Item <%= ip_address %>!443 } -elseif (($certificate -ne $null) -and ($certificate.Thumbprint -ne "") { +elseif (((Test-Path IIS:\SslBindings\$ip!$port) -eq $true) -and (($certificate -ne $null) -or ($certificate.Thumbprint -ne <%= certificate_thumbprint %>))) { + push-location IIS:\SslBindings Get-Item Cert:\LocalMachine\My\<%= certificate_thumbprint %> | Set-Item <%= ip_address %>!<%= port %> + foreach ($cert in $certificates) { + if(($cert -ne $null) -and ($cert.Thumbprint -ne "<%= certificate_thumbprint %>")) { + Get-Item Cert:\LocalMachine\My\$cert.Thumbprint | Remove-Item <%= ip_address %>!<%= port %> + } + } } else { exit 0 From fea37ef7e99b04d1c1178ee04015e6a0039eb2df Mon Sep 17 00:00:00 2001 From: stack72 Date: Tue, 22 Apr 2014 12:47:57 +0100 Subject: [PATCH 12/21] Adding the correct template name for the manage_binding manifest --- manifests/manage_binding.pp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manifests/manage_binding.pp b/manifests/manage_binding.pp index c48fb64..9baeba0 100644 --- a/manifests/manage_binding.pp +++ b/manifests/manage_binding.pp @@ -31,13 +31,13 @@ file { "inspect-${title}-certificate.ps1": ensure => present, path => "C:\\temp\\inspect-${name}.ps1", - content => template('iis/inspect-certificate-binding.ps1'), + content => template('iis/inspect-certificate-binding.ps1.erb'), } file { "create-${title}-certificate.ps1": ensure => present, path => "C:\\temp\\create-${name}.ps1", - content => template('iis/create-certificate-binding.ps1'), + content => template('iis/create-certificate-binding.ps1.erb'), } exec { "Attach-Certificate-${title}": From da0a08c6aa3de22beb033555f1fce22b10ebe00b Mon Sep 17 00:00:00 2001 From: stack72 Date: Tue, 22 Apr 2014 13:16:09 +0100 Subject: [PATCH 13/21] Fixing the onlyif statement as well as the erb template for creating the certificate binding --- manifests/manage_binding.pp | 2 +- templates/create-certificate-binding.ps1.erb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/manifests/manage_binding.pp b/manifests/manage_binding.pp index 9baeba0..ffb2bc8 100644 --- a/manifests/manage_binding.pp +++ b/manifests/manage_binding.pp @@ -42,7 +42,7 @@ exec { "Attach-Certificate-${title}": command => "C:\\temp\\create-${name}.ps1", - onlfif => "C:\\temp\\inspect-${name}.ps1", + onlyif => "C:\\temp\\inspect-${name}.ps1", require => [File["inspect-${title}-certificate.ps1"], File["create-${title}-certificate.ps1"]], provider => powershell, logoutput => true, diff --git a/templates/create-certificate-binding.ps1.erb b/templates/create-certificate-binding.ps1.erb index 64dc764..551e177 100644 --- a/templates/create-certificate-binding.ps1.erb +++ b/templates/create-certificate-binding.ps1.erb @@ -4,11 +4,11 @@ $site = Get-Website | Where-Object { $_.Name -eq "<%= site_name %>" } $certsAttachedToSite = Get-ChildItem IIS:\SSLBindings | ? { $site | Select-Object { $_ -contains $_.Sites.Value }} | % { $_.Thumbprint } $certificate = Get-ChildItem CERT:\LocalMachine\My | ? { $certsAttachedToSite -contains $_.Thumbprint} | Where-Object { $_.Thumbprint -eq "<%= certificate_thumbprint %>" } -if((Test-Path IIS:\SslBindings\$ip!$port) -eq $false) { +if((Test-Path IIS:\SslBindings\<%= ip_address %>!<%= port %>) -eq $false) { push-location IIS:\SslBindings - Get-Item Cert:\LocalMachine\My\<%= certificate_thumbprint %> | New-Item <%= ip_address %>!443 + Get-Item Cert:\LocalMachine\My\<%= certificate_thumbprint %> | New-Item <%= ip_address %>!<%= port %> } -elseif (((Test-Path IIS:\SslBindings\$ip!$port) -eq $true) -and (($certificate -ne $null) -or ($certificate.Thumbprint -ne <%= certificate_thumbprint %>))) { +elseif (((Test-Path IIS:\SslBindings\<%= ip_address %>!<%= port %>) -eq $true) -and (($certificate -ne $null) -or ($certificate.Thumbprint -ne "<%= certificate_thumbprint %>"))) { push-location IIS:\SslBindings Get-Item Cert:\LocalMachine\My\<%= certificate_thumbprint %> | Set-Item <%= ip_address %>!<%= port %> foreach ($cert in $certificates) { From c81ffd44e99daca3154ad6c82d0cc9568eda1a50 Mon Sep 17 00:00:00 2001 From: stack72 Date: Tue, 22 Apr 2014 13:54:14 +0100 Subject: [PATCH 14/21] Fixing the specs to reflect that the Attach certificate is now using the powershell provider as well as using erb templates --- Modulefile | 2 +- spec/defines/manage_binding_spec.rb | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Modulefile b/Modulefile index 8c1b268..8ffea32 100644 --- a/Modulefile +++ b/Modulefile @@ -1,5 +1,5 @@ name 'opentable/iis' -version '1.0.0' +version '1.1.0' author 'opentable' license 'MIT' summary 'Module that will manage IIS for windows server 2008 and above. It will help maintain application pools, sites and virtual applications' diff --git a/spec/defines/manage_binding_spec.rb b/spec/defines/manage_binding_spec.rb index 45970ed..863fa6b 100644 --- a/spec/defines/manage_binding_spec.rb +++ b/spec/defines/manage_binding_spec.rb @@ -122,9 +122,10 @@ } } it { should contain_exec('Attach-Certificate-myWebSite-port-443').with({ - 'command' => "#{powershell} -Command \"Import-Module WebAdministration; New-Item \\\"IIS:\\SslBindings\\127.0.0.1!443\\\" -Value (Get-ChildItem cert:\\ -Recurse | Where-Object {\$_.Thumbprint.Equals(\\\"myCertificate\\\")} | Select-Object -First 1)\"", - 'onlyif' => "#{powershell} -Command \"Import-Module WebAdministration; if((Get-ChildItem cert:\\ -Recurse | Where-Object {\$_.Thumbprint.Equals(\\\"myCertificate\\\")} | Select-Object -First 1) -and ((Test-Path \\\"IIS:\\SslBindings\\127.0.0.1!443\\\") -eq \$false)) { exit 0 } else { exit 1 }\"", - })} + 'command' => "C:\\temp\\create-myWebSite-port-443.ps1", + 'onlyif' => "C:\\temp\\inspect-myWebSite-port-443.ps1", + 'provider' => "powershell" + })} end describe 'when managing an iis site binding and setting ensure to present' do From dd52a86db7f96d15c9e161e56962ca97af2f96ff Mon Sep 17 00:00:00 2001 From: stack72 Date: Tue, 22 Apr 2014 13:58:25 +0100 Subject: [PATCH 15/21] Adding more support to the puppet matrix --- .travis.yml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 61bca8a..cd68223 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,14 @@ --- language: ruby rvm: +- 1.8.7 - 1.9.3 +- 2.0.0 script: bundle exec rake spec env: - matrix: - - PUPPET_VERSION=3.1.0 + - PUPPET_VERSION="~> 2.7.0" + - PUPPET_VERSION="~> 3.1.0" + - PUPPET_VERSION="~> 3.2.0" + - PUPPET_VERSION="~> 3.3.0" + - PUPPET_VERSION="~> 3.4.0" + - PUPPET_VERSION="~> 3.5.0" From dca178dda6b5eeac86af937d0766d484aabcf8bf Mon Sep 17 00:00:00 2001 From: liamjbennett Date: Thu, 5 Jun 2014 11:33:21 +0100 Subject: [PATCH 16/21] updating Gemfile, Rakefile, fixing lint and fixing tests --- .gitignore | 9 +++- Gemfile | 29 ++++++++----- Rakefile | 43 +++++++++++++++++-- manifests/createpath.pp | 1 + manifests/init.pp | 1 + manifests/manage_app_pool.pp | 1 + manifests/manage_binding.pp | 1 + manifests/manage_site.pp | 1 + manifests/manage_site_state.pp | 1 + manifests/manage_virtual_application.pp | 1 + manifests/param/powershell.pp | 1 + spec/defines/manage_app_pool_spec.rb | 4 +- spec/defines/manage_binding_spec.rb | 2 +- spec/defines/manage_site_spec.rb | 4 +- spec/defines/manage_site_state_spec.rb | 8 ++-- .../manage_virtual_application_spec.rb | 2 +- 16 files changed, 83 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index cee1221..6c3818b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,8 @@ +.*.sw? +pkg +spec/fixtures +.rspec_system +.vagrant *.iml -Gemfile.lock -/.idea/* +.idea/ +.bundle/ diff --git a/Gemfile b/Gemfile index 2d92eea..411fcfb 100644 --- a/Gemfile +++ b/Gemfile @@ -1,14 +1,21 @@ -# A sample Gemfile source "http://rubygems.org" -gem 'puppet-lint' -gem 'test-unit' -gem 'rake' -gem 'rspec', '2.13.0' -gem 'rspec-core', '2.13.1' -gem 'rspec-expectations', '2.13.0' -gem 'rspec-mocks', '2.13.1' -gem 'puppet', '3.2.1' -gem 'rspec-puppet', '0.1.6' -gem 'puppetlabs_spec_helper', '0.4.1' +group :test do + gem "rake" + gem "puppet", ENV['PUPPET_VERSION'] || '~> 3.4.0' + gem "puppet-lint" + gem "rspec-puppet", :git => 'https://github.com/rodjek/rspec-puppet.git' + gem "puppet-syntax" + gem "puppetlabs_spec_helper" + gem "rspec", "2.99.0" +end +group :development do + gem "travis" + gem "travis-lint" + gem "beaker" + gem "beaker-rspec" + gem "vagrant-wrapper" + gem "puppet-blacksmith" + gem "guard-rake" +end diff --git a/Rakefile b/Rakefile index 19363d5..b67d40d 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,42 @@ -require 'rubygems' require 'puppetlabs_spec_helper/rake_tasks' -require 'puppet-lint' +require 'puppet-lint/tasks/puppet-lint' +require 'puppet-syntax/tasks/puppet-syntax' + +# These two gems aren't always present, for instance +# on Travis with --without development +begin + require 'puppet_blacksmith/rake_tasks' +rescue LoadError +end + PuppetLint.configuration.send("disable_80chars") -PuppetLint.configuration.send("disable_documentation") +PuppetLint.configuration.log_format = "%{path}:%{linenumber}:%{check}:%{KIND}:%{message}" +PuppetLint.configuration.fail_on_warnings = true + +# Forsake support for Puppet 2.6.2 for the benefit of cleaner code. +# http://puppet-lint.com/checks/class_parameter_defaults/ +PuppetLint.configuration.send('disable_class_parameter_defaults') +# http://puppet-lint.com/checks/class_inherits_from_params_class/ +PuppetLint.configuration.send('disable_class_inherits_from_params_class') +# http://puppet-lint.com/checks/quoted_booleans/ +PuppetLint.configuration.send('disable_quoted_booleans') + +exclude_paths = [ + "pkg/**/*", + "vendor/**/*", + "spec/**/*", +] +PuppetLint.configuration.ignore_paths = exclude_paths +PuppetSyntax.exclude_paths = exclude_paths + +desc "Run acceptance tests" +RSpec::Core::RakeTask.new(:acceptance) do |t| + t.pattern = 'spec/acceptance' +end + +desc "Run syntax, lint, and spec tests." +task :test => [ + :syntax, + :lint, + :spec, +] diff --git a/manifests/createpath.pp b/manifests/createpath.pp index 2e5f5c4..751f83e 100644 --- a/manifests/createpath.pp +++ b/manifests/createpath.pp @@ -1,3 +1,4 @@ +# define iis::createpath($site_path = undef) { include 'iis::param::powershell' diff --git a/manifests/init.pp b/manifests/init.pp index 0dd2d92..35547cc 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -1,3 +1,4 @@ +# class iis { iis::manage_app_pool {'www.internalapi.co.uk': enable_32_bit => true, diff --git a/manifests/manage_app_pool.pp b/manifests/manage_app_pool.pp index 3e7d9a3..c1fc89e 100644 --- a/manifests/manage_app_pool.pp +++ b/manifests/manage_app_pool.pp @@ -1,3 +1,4 @@ +# define iis::manage_app_pool($app_pool_name = $title, $enable_32_bit = false, $managed_runtime_version = 'v4.0', $managed_pipeline_mode = 'Integrated', $ensure = 'present') { validate_bool($enable_32_bit) diff --git a/manifests/manage_binding.pp b/manifests/manage_binding.pp index ffb2bc8..11412dd 100644 --- a/manifests/manage_binding.pp +++ b/manifests/manage_binding.pp @@ -1,3 +1,4 @@ +# define iis::manage_binding($site_name, $protocol, $port, $host_header = '', $ip_address = '*', $certificate_thumbprint = '', $ensure = 'present') { include 'iis::param::powershell' diff --git a/manifests/manage_site.pp b/manifests/manage_site.pp index ae227a7..f1ca29a 100644 --- a/manifests/manage_site.pp +++ b/manifests/manage_site.pp @@ -1,3 +1,4 @@ +# define iis::manage_site($site_path, $app_pool, $host_header = '', $site_name = $title, $port = '80', $ip_address = '*', $ensure = 'present', $ssl = 'false') { include 'iis::param::powershell' diff --git a/manifests/manage_site_state.pp b/manifests/manage_site_state.pp index 8b13085..a4da2a0 100644 --- a/manifests/manage_site_state.pp +++ b/manifests/manage_site_state.pp @@ -1,3 +1,4 @@ +# define iis::manage_site_state($site_name, $ensure = 'running') { include 'iis::param::powershell' diff --git a/manifests/manage_virtual_application.pp b/manifests/manage_virtual_application.pp index 1f1ee6c..da7e50e 100644 --- a/manifests/manage_virtual_application.pp +++ b/manifests/manage_virtual_application.pp @@ -1,3 +1,4 @@ +# define iis::manage_virtual_application($site_name, $site_path, $app_pool, $virtual_application_name = $title, $ensure = 'present') { include 'iis::param::powershell' diff --git a/manifests/param/powershell.pp b/manifests/param/powershell.pp index 2950643..685c19f 100644 --- a/manifests/param/powershell.pp +++ b/manifests/param/powershell.pp @@ -1,3 +1,4 @@ +# class iis::param::powershell { $executable = 'powershell.exe' $exec_policy = '-ExecutionPolicy RemoteSigned' diff --git a/spec/defines/manage_app_pool_spec.rb b/spec/defines/manage_app_pool_spec.rb index 8bc6fb3..0f8432d 100644 --- a/spec/defines/manage_app_pool_spec.rb +++ b/spec/defines/manage_app_pool_spec.rb @@ -7,7 +7,7 @@ let(:title) { 'myAppPool.example.com' } let(:params) { { :enable_32_bit => true, :managed_runtime_version => 'v4.0' } } - it { should include_class('iis::param::powershell') } + it { should contain_class('iis::param::powershell') } it { should contain_exec('Create-myAppPool.example.com').with( { :command => "#{powershell} -Command \"Import-Module WebAdministration; New-Item \\\"IIS:\\AppPools\\myAppPool.example.com\\\"\"", @@ -30,7 +30,7 @@ describe 'when managing the iis application pool without passing parameters' do let(:title) { 'myAppPool.example.com' } - it { should include_class('iis::param::powershell') } + it { should contain_class('iis::param::powershell') } it { should contain_exec('Create-myAppPool.example.com').with( { :command => "#{powershell} -Command \"Import-Module WebAdministration; New-Item \\\"IIS:\\AppPools\\myAppPool.example.com\\\"\"", diff --git a/spec/defines/manage_binding_spec.rb b/spec/defines/manage_binding_spec.rb index 863fa6b..80a84b9 100644 --- a/spec/defines/manage_binding_spec.rb +++ b/spec/defines/manage_binding_spec.rb @@ -12,7 +12,7 @@ :port => '80', } } - it { should include_class('iis::param::powershell') } + it { should contain_class('iis::param::powershell') } it { should contain_exec('CreateBinding-myWebSite-port-80').with({ 'command' => "#{powershell} -Command \"Import-Module WebAdministration; New-WebBinding -Name \\\"myWebSite\\\" -Port 80 -Protocol \\\"http\\\" -HostHeader \\\"myHost.example.com\\\" -IPAddress \\\"*\\\"\"", diff --git a/spec/defines/manage_site_spec.rb b/spec/defines/manage_site_spec.rb index e58ecfc..1eb7168 100644 --- a/spec/defines/manage_site_spec.rb +++ b/spec/defines/manage_site_spec.rb @@ -11,7 +11,7 @@ :site_path => 'C:\inetpub\wwwroot\myWebSite', } } - it { should include_class('iis::param::powershell') } + it { should contain_class('iis::param::powershell') } it { should contain_exec('CreateSite-myWebSite').with({ 'command' => "#{powershell} -Command \"Import-Module WebAdministration; $id = (Get-WebSite | foreach {$_.id} | sort -Descending | select -first 1) + 1; New-WebSite -Name \\\"myWebSite\\\" -Port 80 -IP * -HostHeader \\\"myHost.example.com\\\" -PhysicalPath \\\"C:\\inetpub\\wwwroot\\myWebSite\\\" -ApplicationPool \\\"myAppPool.example.com\\\" -Ssl:$false -ID $id \"", @@ -40,7 +40,7 @@ :ensure => 'present', }} - it { should include_class('iis::param::powershell') } + it { should contain_class('iis::param::powershell') } it { should contain_exec('CreateSite-myWebSite').with({ 'command' => "#{powershell} -Command \"Import-Module WebAdministration; $id = (Get-WebSite | foreach {$_.id} | sort -Descending | select -first 1) + 1; New-WebSite -Name \\\"myWebSite\\\" -Port 1080 -IP 127.0.0.1 -HostHeader \\\"myHost.example.com\\\" -PhysicalPath \\\"C:\\inetpub\\wwwroot\\path\\\" -ApplicationPool \\\"myAppPool.example.com\\\" -Ssl:$false -ID $id \"", diff --git a/spec/defines/manage_site_state_spec.rb b/spec/defines/manage_site_state_spec.rb index c4070f1..01bc8ca 100644 --- a/spec/defines/manage_site_state_spec.rb +++ b/spec/defines/manage_site_state_spec.rb @@ -10,7 +10,7 @@ :ensure => 'running', } } - it { should include_class('iis::param::powershell') } + it { should contain_class('iis::param::powershell') } it { should contain_exec('StartSite-DefaultWebsite').with({ 'command' => "#{powershell} -Command \"Import-Module WebAdministration; Start-Website -Name \\\"DefaultWebsite\\\"\"", @@ -25,7 +25,7 @@ :ensure => 'true', } } - it { should include_class('iis::param::powershell') } + it { should contain_class('iis::param::powershell') } it { should contain_exec('StartSite-DefaultWebsite').with({ 'command' => "#{powershell} -Command \"Import-Module WebAdministration; Start-Website -Name \\\"DefaultWebsite\\\"\"", @@ -40,7 +40,7 @@ :ensure => 'stopped', } } - it { should include_class('iis::param::powershell') } + it { should contain_class('iis::param::powershell') } it { should contain_exec('StopSite-DefaultWebsite').with({ 'command' => "#{powershell} -Command \"Import-Module WebAdministration; Stop-Website -Name \\\"DefaultWebsite\\\"\"", @@ -55,7 +55,7 @@ :ensure => 'false', } } - it { should include_class('iis::param::powershell') } + it { should contain_class('iis::param::powershell') } it { should contain_exec('StopSite-DefaultWebsite').with({ 'command' => "#{powershell} -Command \"Import-Module WebAdministration; Stop-Website -Name \\\"DefaultWebsite\\\"\"", diff --git a/spec/defines/manage_virtual_application_spec.rb b/spec/defines/manage_virtual_application_spec.rb index e8a8548..6fd3508 100644 --- a/spec/defines/manage_virtual_application_spec.rb +++ b/spec/defines/manage_virtual_application_spec.rb @@ -11,7 +11,7 @@ :app_pool => 'myAppPool.example.com', }} - it { should include_class('iis::param::powershell') } + it { should contain_class('iis::param::powershell') } it { should contain_exec('CreateVirtualApplication-myWebSite-mySite').with({ 'command' => "#{powershell} -Command \"Import-Module WebAdministration; New-WebApplication -Name mySite -Site myWebSite -PhysicalPath C:\\inetpub\\wwwroot\\myHost -ApplicationPool myAppPool.example.com\"", From 47575be2500d3bcfbfbc0309993edcade430b8e3 Mon Sep 17 00:00:00 2001 From: liamjbennett Date: Thu, 5 Jun 2014 11:44:10 +0100 Subject: [PATCH 17/21] updating fixtures to https --- .fixtures.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.fixtures.yml b/.fixtures.yml index 0a7b8c9..89bb423 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -1,5 +1,5 @@ fixtures: repositories: - stdlib: git://github.com/puppetlabs/puppetlabs-stdlib.git + stdlib: https://github.com/puppetlabs/puppetlabs-stdlib symlinks: iis: "#{source_dir}" From 823521ade69fabbf968585e465f152ffaf96407a Mon Sep 17 00:00:00 2001 From: liamjbennett Date: Thu, 5 Jun 2014 12:45:00 +0100 Subject: [PATCH 18/21] adding more travis configurations --- .travis.yml | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index cd68223..66786a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,14 +1,25 @@ ---- language: ruby +bundler_args: --without development +before_install: rm Gemfile.lock || true rvm: -- 1.8.7 -- 1.9.3 -- 2.0.0 -script: bundle exec rake spec + - 1.8.7 + - 1.9.3 + - 2.0.0 +script: bundle exec rake test env: - - PUPPET_VERSION="~> 2.7.0" - - PUPPET_VERSION="~> 3.1.0" - - PUPPET_VERSION="~> 3.2.0" - - PUPPET_VERSION="~> 3.3.0" - - PUPPET_VERSION="~> 3.4.0" - - PUPPET_VERSION="~> 3.5.0" + - PUPPET_VERSION="2.7.25" + - PUPPET_VERSION="3.3.0" + - PUPPET_VERSION="3.1.0" + - PUPPET_VERSION="3.2.1" + - PUPPET_VERSION="3.3.0" + - PUPPET_VERSION="3.4.0" + - PUPPET_VERSION="3.5.1" + - PUPPET_VERSION="3.6.0" +matrix: + exclude: + - rvm: 2.0.0 + env: PUPPET_VERSION="2.7.25" + - rvm: 2.0.0 + env: PUPPET_VERSION="3.0.0" + - rvm: 2.0.0 + env: PUPPET_VERSION="3.1.0" From b8e4de1367b6344791204a634b0788821ec81444 Mon Sep 17 00:00:00 2001 From: liamjbennett Date: Thu, 12 Jun 2014 10:31:30 +0100 Subject: [PATCH 19/21] pinning spec_helper to sepcific version --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 411fcfb..1bdd28b 100644 --- a/Gemfile +++ b/Gemfile @@ -6,7 +6,7 @@ group :test do gem "puppet-lint" gem "rspec-puppet", :git => 'https://github.com/rodjek/rspec-puppet.git' gem "puppet-syntax" - gem "puppetlabs_spec_helper" + gem "puppetlabs_spec_helper", "0.4.1" gem "rspec", "2.99.0" end From f4b4b34ec36e1e317b873012ee5800c8fd43a857 Mon Sep 17 00:00:00 2001 From: stack72 Date: Thu, 19 Jun 2014 08:22:30 -0700 Subject: [PATCH 20/21] Fixing the template for the inspection of the certificate binding to now be needing to be false to make sure that the certificate is then added --- templates/inspect-certificate-binding.ps1.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/inspect-certificate-binding.ps1.erb b/templates/inspect-certificate-binding.ps1.erb index 607bd1c..e7b1418 100644 --- a/templates/inspect-certificate-binding.ps1.erb +++ b/templates/inspect-certificate-binding.ps1.erb @@ -1,6 +1,6 @@ Import-Module WebAdministration -if((Test-Path IIS:\SslBindings\<%= ip_address %>!<%= port %>) -eq $true) { +if((Test-Path IIS:\SslBindings\<%= ip_address %>!<%= port %>) -eq $false) { $site = Get-Website | Where-Object { $_.Name -eq "<%= site_name %>" } $certsAttachedToSite = Get-ChildItem IIS:\SSLBindings | ? { $site | Select-Object { $_ -contains $_.Sites.Value }} | % { $_.Thumbprint } $certificate = Get-ChildItem CERT:\LocalMachine\My | ? { $certsAttachedToSite -contains $_.Thumbprint} | Where-Object { $_.Thumbprint -eq "<%= certificate_thumbprint %>" } From 1404b80c0559b9e5a39de5eba852fb009c9c30de Mon Sep 17 00:00:00 2001 From: stack72 Date: Thu, 19 Jun 2014 08:28:13 -0700 Subject: [PATCH 21/21] bumping the modulefile version for a small error with inspect certificate --- Modulefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modulefile b/Modulefile index 8ffea32..858efb6 100644 --- a/Modulefile +++ b/Modulefile @@ -1,5 +1,5 @@ name 'opentable/iis' -version '1.1.0' +version '1.1.1' author 'opentable' license 'MIT' summary 'Module that will manage IIS for windows server 2008 and above. It will help maintain application pools, sites and virtual applications'