Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor vdir name property to site_name #359

Merged
merged 15 commits into from
May 17, 2017
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ Allows easy management of IIS virtual directories (i.e. vdirs).

#### Attribute Parameters

- `name`: name attribute. Specifies the value of the name attribute. This is the name of the website or site + application you are adding it to.
- `site_name`: name attribute. This is the name of the website or site + application you are adding it to.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's use application_name this will add backwards compatibility back and not make this more confusing since app.name is the property used in appcmd

- `path`: The virtual directory path on the site.
- `physical_path`: The physical path of the virtual directory on the disk.
- `username`: (optional) The username required to logon to the physical_path. If set to "" will clear username and password.
Expand Down
2 changes: 1 addition & 1 deletion resources/pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@

load_current_value do |desired|
name desired.name
cmd = shell_out("#{appcmd(node)} list apppool #{desired.name}")
cmd = shell_out("#{appcmd(node)} list apppool \"#{desired.name}\"")
# APPPOOL "DefaultAppPool" (MgdVersion:v2.0,MgdMode:Integrated,state:Started)
Chef::Log.debug("#{desired} list apppool command output: #{cmd.stdout}")
unless cmd.stderr.empty?
Expand Down
14 changes: 7 additions & 7 deletions resources/vdir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
include Opscode::IIS::Helper
include Opscode::IIS::Processors

property :name, String, name_property: true
property :site_name, String, name_property: true
property :path, String
property :physical_path, String
property :username, String
Expand All @@ -34,17 +34,17 @@
default_action :add

load_current_value do |desired|
name application_cleanname(desired.name)
site_name application_cleanname(desired.site_name)
path desired.path
cmd = shell_out("#{appcmd(node)} list vdir \"#{name.chomp('/') + path}\"")
cmd = shell_out("#{appcmd(node)} list vdir \"#{site_name.chomp('/') + path}\"")
Chef::Log.debug("#{desired} list vdir command output: #{cmd.stdout}")

if cmd.stderr.empty?
# VDIR "Testfu Site/Content/Test"
result = cmd.stdout.match(/^VDIR\s\"#{Regexp.escape(name.chomp('/') + path)}\"/)
result = cmd.stdout.match(/^VDIR\s\"#{Regexp.escape(site_name.chomp('/') + path)}\"/)
Chef::Log.debug("#{desired} current_resource match output: #{result}")
unless result.nil?
cmd = shell_out("#{appcmd(node)} list vdir \"#{name.chomp('/') + path}\" /config:* /xml")
cmd = shell_out("#{appcmd(node)} list vdir \"#{site_name.chomp('/') + path}\" /config:* /xml")
if cmd.stderr.empty?
xml = cmd.stdout
doc = Document.new(xml)
Expand All @@ -63,7 +63,7 @@
action :add do
if !@current_resource.physical_path
converge_by "Created the VDIR - \"#{new_resource}\"" do
cmd = "#{appcmd(node)} add vdir /app.name:\"#{new_resource.name}\""
cmd = "#{appcmd(node)} add vdir /app.name:\"#{new_resource.site_name}\""
cmd << " /path:\"#{new_resource.path}\""
cmd << " /physicalPath:\"#{windows_cleanpath(new_resource.physical_path)}\""
cmd << " /userName:\"#{new_resource.username}\"" if new_resource.username
Expand Down Expand Up @@ -125,6 +125,6 @@

action_class.class_eval do
def application_identifier
new_resource.name.chomp('/') + new_resource.path
new_resource.site_name.chomp('/') + new_resource.path
end
end
2 changes: 1 addition & 1 deletion test/cookbooks/test/recipes/pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
action [:add, :config, :stop]
end

iis_pool 'testapppool' do
iis_pool 'test apppool' do
thirty_two_bit false
runtime_version '4.0'
pipeline_mode :Integrated
Expand Down
15 changes: 15 additions & 0 deletions test/cookbooks/test/recipes/vdir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
recursive true
end

directory "#{node['iis']['docroot']}\\vdir_test2" do
recursive true
end

iis_pool 'DefaultAppPool' do
pipeline_mode :Classic
action :add
Expand All @@ -47,3 +51,14 @@
allow_sub_dir_config false
action [:add, :config]
end

iis_vdir 'vdir_test2' do
site_name 'Default Web Site/'
path '/vdir_test2'
physical_path "#{node['iis']['docroot']}\\vdir_test2"
username 'vagrant'
password 'vagrant'
logon_method :ClearText
allow_sub_dir_config false
action [:add, :config]
end
14 changes: 13 additions & 1 deletion test/integration/vdir/controls/vdir_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
its ('startmode') { should eq 'Auto' }
end

describe iis_vdir('Default Web Site', '/vdir_test') do
describe iis_vdir('/vdir_test', 'Default Web Site') do
it { should exist }
it { should have_path('/vdir_test') }
it { should have_physical_path('C:\\inetpub\\wwwroot\\vdir_test') }
Expand All @@ -19,3 +19,15 @@
it { should have_logon_method('ClearText') }
it { should have_allow_sub_dir_config(false) }
end

describe iis_vdir('/vdir_test2', 'vdir_test2') do
it { should exist }
it { should have_site_name('Default Web Site') }
it { should have_path('/vdir_test2') }
it { should have_physical_path('C:\\inetpub\\wwwroot\\vdir_test2') }
it { should have_username('vagrant') }
it { should have_password('vagrant') }
it { should have_logon_method('ClearText') }
it { should have_allow_sub_dir_config(false) }
end

21 changes: 15 additions & 6 deletions test/integration/vdir/libraries/iis_vdir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ class IisVdir < Inspec.resource(1)
end
"

def initialize(name, path)
@name = name
def initialize(path, site_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no reason to invert these, just leave them as is...also change to application name if desired although no required

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I inverted them to be consistent with the app resource.

@path = path
@site_name = site_name
@cache = nil

@vdir_provider = VdirProvider.new(inspec)
Expand All @@ -40,6 +40,10 @@ def initialize(name, path)
skip_resource 'The `iis_vdir` resource is not supported on your OS.' unless inspec.os.windows?
end

def site_name
iis_vdir[:site_name]
end

def path
iis_vdir[:path]
end
Expand Down Expand Up @@ -68,6 +72,10 @@ def exists?
!iis_vdir[:path].empty?
end

def has_site_name?(site_name)
iis_vdir[:site_name] == site_name
end

def has_path?(path)
iis_vdir[:path] == path
end
Expand All @@ -93,12 +101,12 @@ def has_allow_sub_dir_config?(allow)
end

def to_s
"iis_vdir '#{@name}#{@path}'"
"iis_vdir '#{@site_name}#{@path}'"
end

def iis_vdir
return @cache unless @cache.nil?
@cache = @vdir_provider.iis_vdir(@name, @path) unless @vdir_provider.nil?
@cache = @vdir_provider.iis_vdir(@site_name, @path) unless @vdir_provider.nil?
end
end

Expand All @@ -110,8 +118,8 @@ def initialize(inspec)
end

# want to populate everything using one powershell command here and spit it out as json
def iis_vdir(name, path)
command = "Import-Module WebAdministration; Get-WebVirtualDirectory -Site \"#{name}\" -Name \"#{path}\" | Select-Object path, physicalPath, userName, password, logonMethod, allowSubDirConfig, PSPath, ItemXPath | ConvertTo-Json"
def iis_vdir(path, site_name)
command = "Import-Module WebAdministration; Get-WebVirtualDirectory -Site \"#{site_name}\" -Name \"#{path}\" | Select-Object path, physicalPath, userName, password, logonMethod, allowSubDirConfig, PSPath, ItemXPath | ConvertTo-Json"
cmd = @inspec.command(command)

begin
Expand All @@ -123,6 +131,7 @@ def iis_vdir(name, path)

# map our values to a hash table
{
site_name: site_name,
path: vdir['path'],
physical_path: vdir['physicalPath'],
username: vdir['userName'],
Expand Down