-
-
Notifications
You must be signed in to change notification settings - Fork 178
/
helper.rb
98 lines (85 loc) · 2.68 KB
/
helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#
# Cookbook:: iis
# Library:: helper
#
# Copyright:: 2017-2019, Chef Software, 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.
#
module IISCookbook
# Contains functions that are used throughout this cookbook
module Helper
@iis_version = nil
if RUBY_PLATFORM =~ /mswin|mingw32|windows/
require 'chef/win32/version'
require 'win32/registry'
end
require 'rexml/document'
require 'chef/mixin/shell_out'
include Chef::Mixin::ShellOut
include REXML
def self.older_than_windows2012?
if RUBY_PLATFORM =~ /mswin|mingw32|windows/
win_version = Chef::ReservedNames::Win32::Version.new
win_version.windows_7? || win_version.windows_server_2008_r2?
end
end
def windows_cleanpath(path)
path = if defined?(Chef::Util::PathHelper.cleanpath).nil?
win_friendly_path(path)
else
Chef::Util::PathHelper.cleanpath(path)
end
# Remove any trailing slashes to prevent them from accidentally escaping any quotes.
path.tr('/', '\\')
end
def application_cleanname(application_name)
if application_name.count('/') == 0
"#{application_name}/"
elsif application_name.count('/') > 1
application_name.chomp('/')
else
application_name
end
end
def value(document, xpath)
Text.unnormalize(XPath.first(document, xpath).to_s)
end
def get_value(document, xpath)
XPath.match(document, xpath)
end
def bool(value)
value == 'true'
end
def appcmd(node)
@appcmd ||= "#{node['iis']['home']}\\appcmd.exe"
end
def iis_version
if @iis_version.nil?
version_string = Win32::Registry::HKEY_LOCAL_MACHINE.open('SOFTWARE\Microsoft\InetStp').read('VersionString')[1]
version_string.slice! 'Version '
@iis_version = version_string
end
@iis_version.to_f
end
def locate_sysnative_cmd(cmd)
if ::File.exist?("#{ENV['WINDIR']}\\sysnative\\#{cmd}")
"#{ENV['WINDIR']}\\sysnative\\#{cmd}"
elsif ::File.exist?("#{ENV['WINDIR']}\\system32\\#{cmd}")
"#{ENV['WINDIR']}\\system32\\#{cmd}"
else
cmd
end
end
end
end