Skip to content

Commit

Permalink
v4.2
Browse files Browse the repository at this point in the history
- Resolves [iis_config resource not being idempotent](#276)
- Fixed issues with path in `iis_site`, `iis_app`, `iis_vdir` for physical path and path on windows
- Resolves [iis_pool is not idempotent when recycle_at_time is specified and is not changed](#279)
  • Loading branch information
EasyAsABC123 committed Jun 23, 2016
1 parent 9e38d63 commit 3587cec
Show file tree
Hide file tree
Showing 8 changed files with 145 additions and 71 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

This file is used to list changes made in each version of the iis cookbook.

## v4.2 (2016-06-23)

- Resolves [iis_config resource not being idempotent](https://github.com/chef-cookbooks/iis/issues/276)
- Fixed issues with path in `iis_site`, `iis_app`, `iis_vdir` for physical path and path on windows
- Resolves [iis_pool is not idempotent when recycle_at_time is specified and is not changed](https://github.com/chef-cookbooks/iis/issues/279)

## v4.1.8 (2016-04-15)

- Fixed smp_processor_affinity_mask throwing deprecation warnings
Expand Down
60 changes: 40 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,66 +209,86 @@ Runs a config command on your IIS instance.

- `:set` - Edit configuration section (appcmd set config)
- `:clear` - Clear the section configuration (appcmd clear config)
- `:config` - [ DEPRECATED ] use `:set` instead

#### Properties

- `cfg_cmd` - name attribute. What ever command you would pass in after "appcmd.exe set config"
- `section` - name attribute. This is the section the config change would happen in. Example `appcmd.exe set config /section:"THIS_GOES_HERE"`
- `commit` - This is the commit the config change would happen in. Example `appcmd.exe set config /commit:"THIS_GOES_HERE"`
- `property` - This is the property the config change would edit stored in a Hash. Example `appcmd.exe set config /commit:"some_commit" /section:"some_section"` /"THIS_GOES_HERE":"THIS_GOES_HERE_VALUE" /"ANOTHER":"ANOTHER_VALUE"` becomes `property "THIS_GOES_HERE" => "THIS_GOES_HERE_VALUE", "ANOTHER" => "ANOTHER_VALUE"

#### Example

```ruby
# Sets up logging
iis_config "/section:system.applicationHost/sites /siteDefaults.logfile.directory:\"D:\\logs\"" do
action :set
iis_config "Sets up logging" do
section "system.applicationHost/sites"
property "siteDefaults.logFile.directory" => "C:\\inetpub\\logs"
action :set
end
```

```ruby
# Increase file upload size for 'MySite'
iis_config "\"MySite\" /section:requestfiltering /requestlimits.maxallowedcontentlength:50000000" do
iis_config "Increase file upload size for 'MySite'" do
zone "poal_Testwebsite"
section "system.webServer/security/requestFiltering"
property "requestLimits.maxAllowedContentLength" => "50000000"
action :set
end
```

```ruby
# Set IUSR username and password authentication
iis_config "\"MyWebsite/aSite\" -section:system.webServer/security/authentication/anonymousAuthentication /enabled:\"True\" /userName:\"IUSR_foobar\" /password:\"p@assword\" /commit:apphost" do
iis_config "Set IUSR username and password authentication" do
zone "poal_Testwebsite"
commit "apphost"
section "system.webServer/security/authentication/anonymousAuthentication"
property "enabled" => "true", "userName" => "IIS_IUSRS", "password" => "p@assword"
action :set
end
```

```ruby
# Authenticate with application pool
iis_config "\"MyWebsite/aSite\" -section:system.webServer/security/authentication/anonymousAuthentication /enabled:\"True\" /userName:\"\" /commit:apphost" do
action :set
end
```

```ruby
# Loads an array of commands from the node
cfg_cmds = node['iis']['cfg_cmd']
cfg_cmds.each do |cmd|
iis_config "#{cmd}" do
action :set
end
iis_config "Authenticate with application pool" do
zone "Testfu Site"
commit "apphost"
section "system.webServer/security/authentication/anonymousAuthentication"
property "enabled" => "true", "userName" => ""
action :set
end
```

```ruby
# Add static machine key at site level
iis_config "MySite /commit:site /section:machineKey /validation:AES /validationKey:AAAAAA /decryptionKey:ZZZZZ" do
iis_config "Add static machine key at site level" do
zone "poal_Testwebsite"
commit "site"
section "machineKey"
property "validation" => "AES", "validationKey" => "AAAAAA", "decryptionKey" => "ZZZZZ"
action :set
end
```

```ruby
# Remove machine key
iis_config "MySite /commit:site /section:machineKey"
iis_config "Remove machine key" do
zone "poal_Testwebsite"
commit "site"
section "machineKey"
action :clear
end
```

```ruby
# Enable httpOnlyCookies
iis_config "Enable httpOnlyCookies" do
commit "WEBROOT"
section "system.web/httpCookies"
property "httpOnlyCookies" => "true"
action :set
end
```
### iis_pool

Creates an application pool in IIS.
Expand Down
2 changes: 1 addition & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
license 'Apache 2.0'
description 'Installs/Configures Microsoft Internet Information Services'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '4.1.8'
version '4.2'
supports 'windows'
depends 'windows', '>= 1.34.6'
source_url 'https://github.com/chef-cookbooks/iis' if respond_to?(:source_url)
Expand Down
8 changes: 4 additions & 4 deletions providers/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@
if cmd_current_values.stderr.empty?
xml = cmd_current_values.stdout
doc = Document.new(xml)
is_new_path = new_or_empty_value?(doc.root, 'APP/application/@path', new_resource.path.to_s)
is_new_path = new_or_empty_value?(doc.root, 'APP/application/@path', windows_cleanpath(new_resource.path).to_s)
is_new_application_pool = new_or_empty_value?(doc.root, 'APP/application/@applicationPool', new_resource.application_pool.to_s)
is_new_enabled_protocols = new_or_empty_value?(doc.root, 'APP/application/@enabledProtocols', new_resource.enabled_protocols.to_s)
is_new_physical_path = new_or_empty_value?(doc.root, 'APP/application/virtualDirectory/@physicalPath', new_resource.physical_path.to_s)
is_new_physical_path = new_or_empty_value?(doc.root, 'APP/application/virtualDirectory/@physicalPath', windows_cleanpath(new_resource.physical_path).to_s)

# only get the beginning of the command if there is something that changeds
cmd = "#{appcmd(node)} set app \"#{site_identifier}\"" if (new_resource.path && is_new_path) ||
Expand Down Expand Up @@ -115,7 +115,7 @@
def load_current_resource
@current_resource = Chef::Resource::IisApp.new(new_resource.name)
@current_resource.site_name(new_resource.site_name)
@current_resource.path(new_resource.path)
@current_resource.path(windows_cleanpath(new_resource.path))
@current_resource.application_pool(new_resource.application_pool)
cmd = shell_out("#{appcmd(node)} list app")
Chef::Log.debug("#{new_resource} list app command output: #{cmd.stdout}")
Expand All @@ -135,7 +135,7 @@ def load_current_resource
private

def site_identifier
"#{new_resource.site_name}#{new_resource.path}"
"#{new_resource.site_name}#{windows_cleanpath(new_resource.path)}"
end

# Ensure VDIR identifier has a trailing slash
Expand Down
107 changes: 82 additions & 25 deletions providers/config.rb
Original file line number Diff line number Diff line change
@@ -1,47 +1,104 @@
#
# Author:: Kendrick Martin (kendrick.martin@webtrends.com)
# Contributor:: David Dvorak (david.dvorak@webtrends.com)
# Author:: Justin Schuhmann (jmschu02@gmail.com)
# Cookbook Name:: iis
# Resource:: config
#
# Copyright:: 2011, Webtrends Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

require 'chef/mixin/shell_out'
require 'rexml/document'

include Chef::Mixin::ShellOut
include REXML
include Opscode::IIS::Helper
include Opscode::IIS::Processors

# :config deprecated, use :set instead
action :config do
new_resource.updated_by_last_action(true) if config
end

action :set do
new_resource.updated_by_last_action(true) if config
if @current_resource.is_new
config
else
Chef::Log.debug("#{new_resource} config value is the same - nothing to do")
end
end

action :clear do
new_resource.updated_by_last_action(true) if config(:clear)
if @current_resource.is_new
config(:clear)
else
Chef::Log.debug("#{new_resource} config value is already empty - nothing to do")
end
end

def config(action = :set)
cmd = "#{appcmd(node)} #{action} config #{new_resource.cfg_cmd}"
cmd = "#{appcmd(node)} #{action} config"
cmd << " \"#{new_resource.zone}\"" if new_resource.zone
cmd << " /commit:\"#{new_resource.commit}\"" if new_resource.commit
cmd << " /section:\"#{new_resource.section}\"" if new_resource.section
if action == :set
new_resource.property.each do |key, value|
cmd << " /\"#{key}\":\"#{value}\"" if key && value
end
end
Chef::Log.debug(cmd)
shell_out!(cmd, returns: new_resource.returns)
Chef::Log.info('IIS Config command run')
new_resource.updated_by_last_action(true)
end

def load_current_resource
@current_resource = Chef::Resource::IisConfig.new(new_resource.name)
@current_resource.section(new_resource.section)
@current_resource.commit(new_resource.commit)
@current_resource.property(new_resource.property)
@current_resource.is_new = false

cmd = "#{appcmd(node)} list config"
cmd << " \"#{new_resource.zone}\"" if new_resource.zone
cmd << " /commit:\"#{new_resource.commit}\"" if new_resource.commit
cmd << " /section:\"#{new_resource.section}\"" if new_resource.section
Chef::Log.debug(cmd)
cmd = shell_out(cmd)
if cmd.stderr.empty?
xml = cmd.stdout
Chef::Log.debug(xml)
doc = Document.new(xml)
if new_resource.action.include? :set
new_resource.property.each do |key, value|
Chef::Log.debug("key, value: #{key}, #{value}")
if key.include? '.'
key_xpath = key.split('.').join('/').insert(key.rindex('.') + 1, '@')
else
key_xpath = "@#{key}"
end
if new_resource.section.include? "/"
xpath = new_resource.section.split('/')
xpath.shift
if !xpath.is_a?(String)
xpath = xpath.join('/')
end
xpath = "#{xpath}/#{key_xpath}"
else
xpath = "#{new_resource.section}/#{key_xpath}"
end
Chef::Log.debug("xpath: #{xpath}")
@current_resource.is_new = @current_resource.is_new | new_value?(doc.root, xpath, value)
if @current_resource.is_new
break
end
end
elsif new_resource.action.include? :clear
xpath = new_resource.section
if xpath.include? "/"
xpath = new_resource.section.split('/')
xpath.shift
if !xpath.is_a?(String)
xpath = xpath.join('/')
end
end
xpath = "#{xpath}/@*"
@current_resource.is_new = XPath.match(doc.root, xpath).length != 0
end
else
log "Failed to run iis_config action :load_current_resource, #{cmd.stderr}" do
level :warn
end
end
end
2 changes: 1 addition & 1 deletion providers/site.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def configure
xml = cmd_current_values.stdout
doc = Document.new(xml)
is_new_bindings = new_value?(doc.root, 'SITE/@bindings', new_resource.bindings.to_s)
is_new_physical_path = new_or_empty_value?(doc.root, 'SITE/site/application/virtualDirectory/@physicalPath', new_resource.path.to_s)
is_new_physical_path = new_or_empty_value?(doc.root, 'SITE/site/application/virtualDirectory/@physicalPath', windows_cleanpath(new_resource.path).to_s)
is_new_port_host_provided = !"#{XPath.first(doc.root, 'SITE/@bindings')},".include?("#{new_resource.protocol}/*:#{new_resource.port}:#{new_resource.host_header},")
is_new_site_id = new_value?(doc.root, 'SITE/site/@id', new_resource.site_id.to_s)
is_new_log_directory = new_or_empty_value?(doc.root, 'SITE/site/logFile/@directory', new_resource.log_directory.to_s)
Expand Down
4 changes: 2 additions & 2 deletions providers/vdir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@
if cmd_current_values.stderr.empty?
xml = cmd_current_values.stdout
doc = Document.new(xml)
is_new_physical_path = new_or_empty_value?(doc.root, 'VDIR/@physicalPath', new_resource.physical_path.to_s)
is_new_physical_path = new_or_empty_value?(doc.root, 'VDIR/@physicalPath', windows_cleanpath(new_resource.physical_path).to_s)
is_new_user_name = new_or_empty_value?(doc.root, 'VDIR/virtualDirectory/@userName', new_resource.username.to_s)
is_new_password = new_or_empty_value?(doc.root, 'VDIR/virtualDirectory/@password', new_resource.password.to_s)
is_new_logon_method = new_or_empty_value?(doc.root, 'VDIR/virtualDirectory/@logonMethod', new_resource.logon_method.to_s)
is_new_allow_sub_dir_config = new_or_empty_value?(doc.root, 'VDIR/virtualDirectory/@allowSubDirConfig', new_resource.allow_sub_dir_config.to_s)

if new_resource.physical_path && is_new_physical_path
@was_updated = true
cmd = "#{appcmd(node)} set vdir \"#{application_identifier}\" /physicalPath:\"#{new_resource.physical_path}\""
cmd = "#{appcmd(node)} set vdir \"#{application_identifier}\" /physicalPath:\"#{windows_cleanpath(new_resource.physical_path)}\""
Chef::Log.debug(cmd)
shell_out!(cmd)
end
Expand Down
27 changes: 9 additions & 18 deletions resources/config.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
#
# Author:: Kendrick Martin (kendrick.martin@webtrends.com)
# Author:: Justin Schuhmann (jmschu02@gmail.com)
# Cookbook Name:: iis
# Resource:: config
#
# Copyright:: 2011, Webtrends Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

actions :config, :clear, :set
actions :clear, :set
default_action :set

attribute :cfg_cmd, kind_of: String, name_attribute: true
attribute :returns, kind_of: [Integer, Array], default: 0
attribute :section, kind_of: String, name_attribute: true
attribute :commit, kind_of: String, :required => false
attribute :zone, kind_of: String, :required => false
attribute :property, kind_of: Hash, default: {}, :required => false
attribute :returns, kind_of: [Integer, Array], default: 0, :required => false

attr_accessor :is_new

0 comments on commit 3587cec

Please sign in to comment.