Skip to content

Commit

Permalink
[sous-chefsGH-476] Allow specifying install method for internal windo…
Browse files Browse the repository at this point in the history
…ws_feature resources

install resource refactored to do the feature name translation if required
by just adding the helper method in the action_class.

Also refactored the install resource to enable and start the W3WVC service
since every other recipe in the cookbook used to call the default recipe
that did that anyway

starting the W3WVC is optional and defaults to false, so that the
current behaviour of that resource that doesn't change for down stream users

This makes a much cleaner implemenation, no helper module monkey patched
into recipe, no extra resources and to all users of the cookbook there are
no breaking changes just new options if desired.

Added a unit test for all the mod recipes just to check they converge,
I think this just gives some confidence things are breaking

Spec tests for the install resource
  • Loading branch information
dave-q committed Apr 15, 2021
1 parent d998ce0 commit 33b0e6e
Show file tree
Hide file tree
Showing 39 changed files with 806 additions and 159 deletions.
42 changes: 0 additions & 42 deletions libraries/windowsfeature_helper.rb

This file was deleted.

8 changes: 2 additions & 6 deletions recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@
iis_install 'install IIS' do
additional_components node['iis']['components']
source node['iis']['source']
install_method node['iis']['windows_feature_install_method']&.to_sym
end

service 'iis' do
service_name 'W3SVC'
action [:enable, :start]
install_method node['iis']['windows_feature_install_method']
start_iis true
end
10 changes: 5 additions & 5 deletions recipes/mod_application_initialization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
# limitations under the License.
#

include_recipe 'iis'
install_method = node['iis']['windows_feature_install_method']&.to_sym

windows_feature transform_feature_name(install_method, 'IIS-ApplicationInit') do
install_method install_method
iis_install 'install IIS, ApplicationInit' do
additional_components 'IIS-ApplicationInit'
source node['iis']['source']
install_method node['iis']['windows_feature_install_method']
start_iis true
end
13 changes: 5 additions & 8 deletions recipes/mod_aspnet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,11 @@
# limitations under the License.
#

include_recipe 'iis'
include_recipe 'iis::mod_isapi'

install_method = node['iis']['windows_feature_install_method']&.to_sym

windows_feature transform_feature_name(install_method, %w(IIS-NetFxExtensibility IIS-ASPNET)) do
action :install
all !IISCookbook::Helper.older_than_windows2012?
source node['iis']['source'] unless node['iis']['source'].nil?
install_method install_method
iis_install 'install IIS, ASPNET' do
additional_components %w(IIS-NetFxExtensibility IIS-ASPNET)
source node['iis']['source']
install_method node['iis']['windows_feature_install_method']
start_iis true
end
10 changes: 5 additions & 5 deletions recipes/mod_aspnet45.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
# limitations under the License.
#

include_recipe 'iis'
include_recipe 'iis::mod_isapi'

install_method = node['iis']['windows_feature_install_method']&.to_sym

windows_feature transform_feature_name(install_method, %w(NetFx4Extended-ASPNET45 IIS-NetFxExtensibility45 IIS-ASPNET45)) do
install_method install_method
iis_install 'install IIS, ASPNET45' do
additional_components %w(NetFx4Extended-ASPNET45 IIS-NetFxExtensibility45 IIS-ASPNET45)
source node['iis']['source']
install_method node['iis']['windows_feature_install_method']
start_iis true
end
9 changes: 5 additions & 4 deletions recipes/mod_auth_basic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@

include_recipe 'iis'

install_method = node['iis']['windows_feature_install_method']&.to_sym

windows_feature transform_feature_name(install_method, 'IIS-BasicAuthentication') do
install_method install_method
iis_install 'install IIS, BasicAuth' do
additional_components 'IIS-BasicAuthentication'
source node['iis']['source']
install_method node['iis']['windows_feature_install_method']
start_iis true
end

iis_section 'unlocks basic authentication control in web.config' do
Expand Down
9 changes: 5 additions & 4 deletions recipes/mod_auth_digest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@

include_recipe 'iis'

install_method = node['iis']['windows_feature_install_method']&.to_sym

windows_feature transform_feature_name(install_method, 'IIS-DigestAuthentication') do
install_method install_method
iis_install 'install IIS, DigestAuth' do
additional_components 'IIS-DigestAuthentication'
source node['iis']['source']
install_method node['iis']['windows_feature_install_method']
start_iis true
end

iis_section 'unlocks digest authentication control in web.config' do
Expand Down
9 changes: 5 additions & 4 deletions recipes/mod_auth_windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@

include_recipe 'iis'

install_method = node['iis']['windows_feature_install_method']&.to_sym

windows_feature transform_feature_name(install_method, 'IIS-WindowsAuthentication') do
install_method install_method
iis_install 'install IIS, WindowsAuth' do
additional_components 'IIS-WindowsAuthentication'
source node['iis']['source']
install_method node['iis']['windows_feature_install_method']
start_iis true
end

iis_section 'unlocks windows authentication control in web.config' do
Expand Down
11 changes: 5 additions & 6 deletions recipes/mod_cgi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
# limitations under the License.
#

include_recipe 'iis'

install_method = node['iis']['windows_feature_install_method']&.to_sym

windows_feature transform_feature_name(install_method, 'IIS-CGI') do
install_method install_method
iis_install 'install IIS, CGI' do
additional_components 'IIS-CGI'
source node['iis']['source']
install_method node['iis']['windows_feature_install_method']
start_iis true
end
11 changes: 5 additions & 6 deletions recipes/mod_compress_dynamic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
# limitations under the License.
#

include_recipe 'iis'

install_method = node['iis']['windows_feature_install_method']&.to_sym

windows_feature transform_feature_name(install_method, 'IIS-HttpCompressionDynamic') do
install_method install_method
iis_install 'install IIS, HttpCompressionDynamic' do
additional_components 'IIS-HttpCompressionDynamic'
source node['iis']['source']
install_method node['iis']['windows_feature_install_method']
start_iis true
end
11 changes: 5 additions & 6 deletions recipes/mod_compress_static.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
# limitations under the License.
#

include_recipe 'iis'

install_method = node['iis']['windows_feature_install_method']&.to_sym

windows_feature transform_feature_name(install_method, 'IIS-HttpCompressionStatic') do
install_method install_method
iis_install 'install IIS, HttpCompressionStatic' do
additional_components 'IIS-HttpCompressionStatic'
source node['iis']['source']
install_method node['iis']['windows_feature_install_method']
start_iis true
end
11 changes: 5 additions & 6 deletions recipes/mod_ftp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
# limitations under the License.
#

include_recipe 'iis'

install_method = node['iis']['windows_feature_install_method']&.to_sym

windows_feature transform_feature_name(install_method, %w(IIS-FTPServer IIS-FTPSvc IIS-FTPExtensibility)) do
install_method install_method
iis_install 'install IIS, FTP' do
additional_components %w(IIS-FTPServer IIS-FTPSvc IIS-FTPExtensibility)
source node['iis']['source']
install_method node['iis']['windows_feature_install_method']
start_iis true
end
11 changes: 5 additions & 6 deletions recipes/mod_iis6_metabase_compat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
# limitations under the License.
#

include_recipe 'iis'

install_method = node['iis']['windows_feature_install_method']&.to_sym

windows_feature transform_feature_name(install_method, %w(IIS-IIS6ManagementCompatibility IIS-Metabase)) do
install_method install_method
iis_install 'install IIS, Compatability, Metabase' do
additional_components %w(IIS-IIS6ManagementCompatibility IIS-Metabase)
source node['iis']['source']
install_method node['iis']['windows_feature_install_method']
start_iis true
end
11 changes: 5 additions & 6 deletions recipes/mod_isapi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
# limitations under the License.
#

include_recipe 'iis'

install_method = node['iis']['windows_feature_install_method']&.to_sym

windows_feature transform_feature_name(install_method, %w(IIS-ISAPIFilter IIS-ISAPIExtensions)) do
install_method install_method
iis_install 'install IIS, ISAPI' do
additional_components %w(IIS-ISAPIFilter IIS-ISAPIExtensions)
source node['iis']['source']
install_method node['iis']['windows_feature_install_method']
start_iis true
end
11 changes: 5 additions & 6 deletions recipes/mod_logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
# limitations under the License.
#

include_recipe 'iis'

install_method = node['iis']['windows_feature_install_method']&.to_sym

windows_feature transform_feature_name(install_method, 'IIS-CustomLogging') do
install_method install_method
iis_install 'install IIS, CustomLogging' do
additional_components 'IIS-CustomLogging'
source node['iis']['source']
install_method node['iis']['windows_feature_install_method']
start_iis true
end
13 changes: 5 additions & 8 deletions recipes/mod_management.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@
# limitations under the License.
#

include_recipe 'iis'

install_method = node['iis']['windows_feature_install_method']&.to_sym

windows_feature transform_feature_name(install_method, %w(IIS-ManagementConsole IIS-ManagementService)) do
action :install
all !IISCookbook::Helper.older_than_windows2012?
install_method install_method
iis_install 'install IIS, Management' do
additional_components %w(IIS-ManagementConsole IIS-ManagementService)
source node['iis']['source']
install_method node['iis']['windows_feature_install_method']
start_iis true
end
11 changes: 5 additions & 6 deletions recipes/mod_security.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
# limitations under the License.
#

include_recipe 'iis'

install_method = node['iis']['windows_feature_install_method']&.to_sym

windows_feature transform_feature_name(install_method, %w(IIS-URLAuthorization IIS-RequestFiltering IIS-IPSecurity)) do
install_method install_method
iis_install 'install IIS, Security' do
additional_components %w(IIS-URLAuthorization IIS-RequestFiltering IIS-IPSecurity)
source node['iis']['source']
install_method node['iis']['windows_feature_install_method']
start_iis true
end
11 changes: 5 additions & 6 deletions recipes/mod_tracing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
# limitations under the License.
#

include_recipe 'iis'

install_method = node['iis']['windows_feature_install_method']&.to_sym

windows_feature transform_feature_name(install_method, 'IIS-HttpTracing') do
install_method install_method
iis_install 'install IIS, Tracing' do
additional_components 'IIS-HttpTracing'
source node['iis']['source']
install_method node['iis']['windows_feature_install_method']
start_iis true
end
44 changes: 40 additions & 4 deletions resources/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,26 @@
#

include IISCookbook::Helper
include IISCookbook::WindowsFeatureHelper

property :source, String
property :additional_components, Array, default: []
property :install_method, Symbol, required: false, equal_to: [:windows_feature_dism, :windows_feature_powershell, :windows_feature_servermanagercmd], default: :windows_feature_dism
property :additional_components, [Array, String],
coerce: proc { |c| Array(c) },
default: []
property :install_method, [String, Symbol],
required: false,
coerce: proc { |i| i.to_sym },
equal_to: [:windows_feature_dism, :windows_feature_powershell, :windows_feature_servermanagercmd],
default: :windows_feature_dism
property :start_iis, [true, false], default: false

action :install do
features_to_install = transform_feature_name(new_resource.install_method, ['IIS-WebServerRole'].concat(new_resource.additional_components))
features = ['IIS-WebServerRole'].concat(new_resource.additional_components)

features_to_install = if new_resource.install_method == :windows_feature_powershell
powershell_feature_name(features)
else
features
end

windows_feature 'Install IIS and additional components' do
feature_name features_to_install
Expand All @@ -34,4 +46,28 @@
source new_resource.source unless new_resource.source.nil?
install_method new_resource.install_method
end

service 'iis' do
service_name 'W3SVC'
action [:enable, :start]
only_if { new_resource.start_iis }
end
end

action_class do
def powershell_feature_name(names)
Array(names).map do |name|
# This will search for the powershell format (Name) of the feature name, by the both the install name or Name, meaning
# that it doesnt care if you pass the powershell format or dism format, it will return the powershell format
cmd = "Get-WindowsFeature | Where-Object {$_.AdditionalInfo.InstallName -Eq '#{name}' -or $_.Name -eq '#{name}'} | Select -Expand Name"
result = powershell_out cmd
if result.stderr.to_s.empty?
next result.stdout.strip
else
Chef::Log.warn("Unable to translate feature #{name}")
Chef::Log.warn(result.stderr)
next name
end
end
end
end
1 change: 1 addition & 0 deletions resources/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
iis_install 'Web-Mgmt-Service' do
additional_components ['IIS-ManagementService']
install_method new_resource.install_method
start_iis false
end

# properties stored in the registry
Expand Down
Loading

0 comments on commit 33b0e6e

Please sign in to comment.