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.
- `application_name`: name attribute. This is the name of the website or site + application you are adding it to.
- `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
12 changes: 6 additions & 6 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 :application_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).end_with?('/') ? application_cleanname(desired.name) : application_cleanname(desired.name) + '/'
application_name application_cleanname(desired.application_name).end_with?('/') ? application_cleanname(desired.application_name) : application_cleanname(desired.application_name) + '/'
path desired.path
cmd = shell_out("#{appcmd(node)} list vdir \"#{name.chomp('/') + path}\"")
cmd = shell_out("#{appcmd(node)} list vdir \"#{application_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(application_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 \"#{application_name.chomp('/') + path}\" /config:* /xml")
if cmd.stderr.empty?
xml = cmd.stdout
doc = Document.new(xml)
Expand Down Expand Up @@ -129,6 +129,6 @@ def application_identifier
end

def vdir_identifier
new_resource.name.end_with?('/') ? new_resource.name : new_resource.name + '/'
new_resource.application_name.end_with?('/') ? new_resource.application_name : new_resource.application_name + '/'
end
end
2 changes: 1 addition & 1 deletion test/cookbooks/test/recipes/vdir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
end

iis_vdir 'Creating vDir /foo for Sitename' do
name 'Default Web Site'
application_name 'Default Web Site'
path '/foo'
physical_path "#{node['iis']['docroot']}\\foo"
action [:add, :config]
Expand Down
4 changes: 2 additions & 2 deletions 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 @@ -20,7 +20,7 @@
it { should have_allow_sub_dir_config(false) }
end

describe iis_vdir('Default Web Site', '/foo') do
describe iis_vdir('/foo', 'Default Web Site') do
it { should exist }
it { should have_path('/foo') }
it { should have_physical_path('C:\\inetpub\\wwwroot\\foo') }
Expand Down
23 changes: 16 additions & 7 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, application_name)
@path = path
@application_name = application_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 application_name
iis_vdir[:application_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_application_name?(application_name)
iis_vdir[:application_name] == application_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 '#{@application_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(@path, @application_name) 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, application_name)
command = "Import-Module WebAdministration; Get-WebVirtualDirectory -Site \"#{application_name}\" -Name \"#{path}\" | Select-Object path, physicalPath, userName, password, logonMethod, allowSubDirConfig, PSPath, ItemXPath | ConvertTo-Json"
cmd = @inspec.command(command)

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

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