Skip to content

Commit

Permalink
[sous-chefsGH-476] Windows feature lookup works with dism name and po…
Browse files Browse the repository at this point in the history
…wershell name
  • Loading branch information
dave-q committed Apr 2, 2021
1 parent ae18bf3 commit 5e99d46
Show file tree
Hide file tree
Showing 20 changed files with 34 additions and 76 deletions.
2 changes: 1 addition & 1 deletion libraries/windowsfeature_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def transform_feature_name(install_method, *names)
if install_method.to_sym == :windows_feature_powershell
translated_features = []
names.each do |name|
cmd = "Get-WindowsFeature | Where-Object {$_.AdditionalInfo.InstallName -Eq '#{name}'} | Select -Expand Name"
cmd = "Get-WindowsFeature | Where-Object {$_.AdditionalInfo.InstallName -Eq '#{name}' -or $_.Name -eq '#{name}'} | Select -Expand Name"
result = powershell_out cmd
if result.stderr.empty?
translated_features.push(result.stdout.strip)
Expand Down
1 change: 0 additions & 1 deletion recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +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
Expand Down
4 changes: 1 addition & 3 deletions recipes/mod_application_initialization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@

include_recipe 'iis'

iis_windows_feature_wrapper 'IIS-ApplicationInit' do
install_method node['iis']['windows_feature_install_method']&.to_sym
end
iis_windows_feature_wrapper 'IIS-ApplicationInit'
4 changes: 1 addition & 3 deletions recipes/mod_aspnet45.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,4 @@
include_recipe 'iis'
include_recipe 'iis::mod_isapi'

iis_windows_feature_wrapper %w(NetFx4Extended-ASPNET45 IIS-NetFxExtensibility45 IIS-ASPNET45) do
install_method node['iis']['windows_feature_install_method']&.to_sym
end
iis_windows_feature_wrapper %w(NetFx4Extended-ASPNET45 IIS-NetFxExtensibility45 IIS-ASPNET45)
4 changes: 1 addition & 3 deletions recipes/mod_auth_basic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@

include_recipe 'iis'

iis_windows_feature_wrapper 'IIS-BasicAuthentication' do
install_method node['iis']['windows_feature_install_method']&.to_sym
end
iis_windows_feature_wrapper 'IIS-BasicAuthentication'

iis_section 'unlocks basic authentication control in web.config' do
section 'system.webServer/security/authentication/basicAuthentication'
Expand Down
4 changes: 1 addition & 3 deletions recipes/mod_auth_digest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@

include_recipe 'iis'

iis_windows_feature_wrapper 'IIS-DigestAuthentication' do
install_method node['iis']['windows_feature_install_method']&.to_sym
end
iis_windows_feature_wrapper 'IIS-DigestAuthentication'

iis_section 'unlocks digest authentication control in web.config' do
section 'system.webServer/security/authentication/digestAuthentication'
Expand Down
4 changes: 1 addition & 3 deletions recipes/mod_auth_windows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@

include_recipe 'iis'

iis_windows_feature_wrapper 'IIS-WindowsAuthentication' do
install_method node['iis']['windows_feature_install_method']&.to_sym
end
iis_windows_feature_wrapper 'IIS-WindowsAuthentication'

iis_section 'unlocks windows authentication control in web.config' do
section 'system.webServer/security/authentication/windowsAuthentication'
Expand Down
4 changes: 1 addition & 3 deletions recipes/mod_cgi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@

include_recipe 'iis'

iis_windows_feature_wrapper 'IIS-CGI' do
install_method node['iis']['windows_feature_install_method']&.to_sym
end
iis_windows_feature_wrapper 'IIS-CGI'
4 changes: 1 addition & 3 deletions recipes/mod_compress_dynamic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@

include_recipe 'iis'

iis_windows_feature_wrapper 'IIS-HttpCompressionDynamic' do
install_method node['iis']['windows_feature_install_method']&.to_sym
end
iis_windows_feature_wrapper 'IIS-HttpCompressionDynamic'
4 changes: 1 addition & 3 deletions recipes/mod_compress_static.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@

include_recipe 'iis'

iis_windows_feature_wrapper 'IIS-HttpCompressionStatic' do
install_method node['iis']['windows_feature_install_method']&.to_sym
end
iis_windows_feature_wrapper 'IIS-HttpCompressionStatic'
4 changes: 1 addition & 3 deletions recipes/mod_ftp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@

include_recipe 'iis'

iis_windows_feature_wrapper %w(IIS-FTPServer IIS-FTPSvc IIS-FTPExtensibility) do
install_method node['iis']['windows_feature_install_method']&.to_sym
end
iis_windows_feature_wrapper %w(IIS-FTPServer IIS-FTPSvc IIS-FTPExtensibility)
4 changes: 1 addition & 3 deletions recipes/mod_iis6_metabase_compat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@

include_recipe 'iis'

iis_windows_feature_wrapper %w(IIS-IIS6ManagementCompatibility IIS-Metabase) do
install_method node['iis']['windows_feature_install_method']&.to_sym
end
iis_windows_feature_wrapper %w(IIS-IIS6ManagementCompatibility IIS-Metabase)
4 changes: 1 addition & 3 deletions recipes/mod_isapi.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@

include_recipe 'iis'

iis_windows_feature_wrapper %w(IIS-ISAPIFilter IIS-ISAPIExtensions) do
install_method node['iis']['windows_feature_install_method']&.to_sym
end
iis_windows_feature_wrapper %w(IIS-ISAPIFilter IIS-ISAPIExtensions)
4 changes: 1 addition & 3 deletions recipes/mod_logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@

include_recipe 'iis'

iis_windows_feature_wrapper 'IIS-CustomLogging' do
install_method node['iis']['windows_feature_install_method']&.to_sym
end
iis_windows_feature_wrapper 'IIS-CustomLogging'
4 changes: 1 addition & 3 deletions recipes/mod_security.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@

include_recipe 'iis'

iis_windows_feature_wrapper %w(IIS-URLAuthorization IIS-RequestFiltering IIS-IPSecurity) do
install_method node['iis']['windows_feature_install_method']&.to_sym
end
iis_windows_feature_wrapper %w(IIS-URLAuthorization IIS-RequestFiltering IIS-IPSecurity)
4 changes: 1 addition & 3 deletions recipes/mod_tracing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,4 @@

include_recipe 'iis'

iis_windows_feature_wrapper 'IIS-HttpTracing' do
install_method node['iis']['windows_feature_install_method']&.to_sym
end
iis_windows_feature_wrapper 'IIS-HttpTracing'
2 changes: 0 additions & 2 deletions resources/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

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

action :install do
features_to_install = ['IIS-WebServerRole'].concat new_resource.additional_components
Expand All @@ -31,6 +30,5 @@
action :install
all !IISCookbook::Helper.older_than_windows2012?
source new_resource.source unless new_resource.source.nil?
install_method new_resource.install_method
end
end
1 change: 0 additions & 1 deletion resources/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
action :config do
iis_install 'Web-Mgmt-Service' do
additional_components ['IIS-ManagementService']
install_method new_resource.install_method
end

# properties stored in the registry
Expand Down
34 changes: 19 additions & 15 deletions resources/windows_feature_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,48 +34,52 @@
description: 'Install all applicable management tools for the roles, role services, or features (PowerShell-only).',
default: false

property :install_method, Symbol,
description: 'The underlying installation method to use for feature installation. Specify `:windows_feature_dism` for DISM or `:windows_feature_powershell` for PowerShell.',
equal_to: %i(windows_feature_dism windows_feature_powershell windows_feature_servermanagercmd),
default: :windows_feature_dism

property :timeout, Integer,
description: 'Specifies a timeout (in seconds) for the feature installation.',
default: 600,
desired_state: false

action :delete do
feature = transform_feature_name(new_resource.install_method, *new_resource.feature_name)
action :install do
install_method = get_install_mode
feature = transform_feature_name(install_method, *new_resource.feature_name)
windows_feature feature do
source new_resource.source
all new_resource.all
management_tools new_resource.management_tools
install_method new_resource.install_method
install_method install_method
timeout new_resource.timeout
action :delete
action :install
end
end

action :install do
feature = transform_feature_name(new_resource.install_method, *new_resource.feature_name)
action :delete do
install_method = get_install_mode
feature = transform_feature_name(install_method, *new_resource.feature_name)
windows_feature feature do
source new_resource.source
all new_resource.all
management_tools new_resource.management_tools
install_method new_resource.install_method
install_method install_method
timeout new_resource.timeout
action :install
action :delete
end
end

action :remove do
feature = transform_feature_name(new_resource.install_method, *new_resource.feature_name)
install_method = get_install_mode
feature = transform_feature_name(install_method, *new_resource.feature_name)
windows_feature feature do
source new_resource.source
all new_resource.all
management_tools new_resource.management_tools
install_method new_resource.install_method
install_method install_method
timeout new_resource.timeout
action :remove
end
end

action_class.class_eval do
def get_install_mode
node['iis']['windows_feature_install_method']&.to_sym
end
end
14 changes: 0 additions & 14 deletions spec/unit/recipes/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,4 @@
expect(chef_run).to start_service('iis').with(service_name: 'W3SVC')
end
end

[:windows_feature_dism, :windows_feature_powershell, :windows_feature_servermanagercmd].each do |method|
context "When iis windows feature install method is provided as #{method}, on a unspecified platform" do
let(:chef_run) do
ChefSpec::SoloRunner.new do |node|
node.override['iis']['windows_feature_install_method'] = method
end.converge(described_recipe)
end

it "installs windows features using #{method}" do
expect(chef_run).to install_iis_install('install IIS').with(install_method: method)
end
end
end
end

0 comments on commit 5e99d46

Please sign in to comment.