diff options
Diffstat (limited to 'lib/chef/util')
-rw-r--r-- | lib/chef/util/backup.rb | 4 | ||||
-rw-r--r-- | lib/chef/util/diff.rb | 10 | ||||
-rw-r--r-- | lib/chef/util/dsc/configuration_generator.rb | 12 | ||||
-rw-r--r-- | lib/chef/util/dsc/lcm_output_parser.rb | 8 | ||||
-rw-r--r-- | lib/chef/util/dsc/local_configuration_manager.rb | 14 | ||||
-rw-r--r-- | lib/chef/util/dsc/resource_store.rb | 14 | ||||
-rw-r--r-- | lib/chef/util/file_edit.rb | 6 | ||||
-rw-r--r-- | lib/chef/util/path_helper.rb | 2 | ||||
-rw-r--r-- | lib/chef/util/powershell/cmdlet.rb | 22 | ||||
-rw-r--r-- | lib/chef/util/powershell/cmdlet_result.rb | 2 | ||||
-rw-r--r-- | lib/chef/util/powershell/ps_credential.rb | 2 | ||||
-rw-r--r-- | lib/chef/util/selinux.rb | 4 | ||||
-rw-r--r-- | lib/chef/util/threaded_job_queue.rb | 2 | ||||
-rw-r--r-- | lib/chef/util/windows/net_group.rb | 170 | ||||
-rw-r--r-- | lib/chef/util/windows/net_use.rb | 6 | ||||
-rw-r--r-- | lib/chef/util/windows/net_user.rb | 8 | ||||
-rw-r--r-- | lib/chef/util/windows/volume.rb | 4 |
17 files changed, 145 insertions, 145 deletions
diff --git a/lib/chef/util/backup.rb b/lib/chef/util/backup.rb index 6c95cedad7..2142869e36 100644 --- a/lib/chef/util/backup.rb +++ b/lib/chef/util/backup.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'chef/util/path_helper' +require "chef/util/path_helper" class Chef class Util @@ -49,7 +49,7 @@ class Chef def backup_filename @backup_filename ||= begin time = Time.now - nanoseconds = sprintf("%6f", time.to_f).split('.')[1] + nanoseconds = sprintf("%6f", time.to_f).split(".")[1] savetime = time.strftime("%Y%m%d%H%M%S.#{nanoseconds}") backup_filename = "#{path}.chef-#{savetime}" backup_filename = backup_filename.sub(/^([A-Za-z]:)/, "") #strip drive letter on Windows diff --git a/lib/chef/util/diff.rb b/lib/chef/util/diff.rb index b8336b5135..3b42f576c0 100644 --- a/lib/chef/util/diff.rb +++ b/lib/chef/util/diff.rb @@ -40,8 +40,8 @@ # CONNECTION WITH THE SOFTWARE OR THE USE OF OTHER DEALINGS IN THE # SOFTWARE. -require 'diff/lcs' -require 'diff/lcs/hunk' +require "diff/lcs" +require "diff/lcs/hunk" class Chef class Util @@ -97,9 +97,9 @@ class Chef return "No differences encountered\n" if diff_data.empty? # write diff header (standard unified format) - ft = File.stat(old_file).mtime.localtime.strftime('%Y-%m-%d %H:%M:%S.%N %z') + ft = File.stat(old_file).mtime.localtime.strftime("%Y-%m-%d %H:%M:%S.%N %z") diff_str << "--- #{old_file}\t#{ft}\n" - ft = File.stat(new_file).mtime.localtime.strftime('%Y-%m-%d %H:%M:%S.%N %z') + ft = File.stat(new_file).mtime.localtime.strftime("%Y-%m-%d %H:%M:%S.%N %z") diff_str << "+++ #{new_file}\t#{ft}\n" # loop over diff hunks. if a hunk overlaps with the last hunk, @@ -176,7 +176,7 @@ class Chef end def encode_diff_for_json(diff_str) - diff_str.encode!('UTF-8', :invalid => :replace, :undef => :replace, :replace => '?') + diff_str.encode!("UTF-8", :invalid => :replace, :undef => :replace, :replace => "?") end end diff --git a/lib/chef/util/dsc/configuration_generator.rb b/lib/chef/util/dsc/configuration_generator.rb index 2041278e4a..e2c09aeea8 100644 --- a/lib/chef/util/dsc/configuration_generator.rb +++ b/lib/chef/util/dsc/configuration_generator.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'chef/util/powershell/cmdlet' +require "chef/util/powershell/cmdlet" class Chef::Util::DSC class ConfigurationGenerator @@ -27,9 +27,9 @@ class Chef::Util::DSC def configuration_document_from_script_code(code, configuration_flags, imports, shellout_flags) Chef::Log.debug("DSC: DSC code:\n '#{code}'") - generated_script_path = write_document_generation_script(code, 'chef_dsc', imports) + generated_script_path = write_document_generation_script(code, "chef_dsc", imports) begin - configuration_document_from_script_path(generated_script_path, 'chef_dsc', configuration_flags, shellout_flags) + configuration_document_from_script_path(generated_script_path, "chef_dsc", configuration_flags, shellout_flags) ensure ::FileUtils.rm(generated_script_path) end @@ -97,7 +97,7 @@ Configuration '#{configuration_name}' def generate_import_resource_statements(imports) if imports imports.map do |resource_module, resources| - if resources.length == 0 || resources.include?('*') + if resources.length == 0 || resources.include?("*") "Import-DscResource -ModuleName #{resource_module}" else "Import-DscResource -ModuleName #{resource_module} -Name #{resources.join(',')}" @@ -114,7 +114,7 @@ Configuration '#{configuration_name}' def write_document_generation_script(code, configuration_name, imports) script_path = "#{@config_directory}/chef_dsc_config.ps1" - ::File.open(script_path, 'wt') do | script | + ::File.open(script_path, "wt") do | script | script.write(configuration_code(code, configuration_name, imports)) end script_path @@ -131,7 +131,7 @@ Configuration '#{configuration_name}' end def get_configuration_document(document_path) - ::File.open(document_path, 'rb') do | file | + ::File.open(document_path, "rb") do | file | file.read end end diff --git a/lib/chef/util/dsc/lcm_output_parser.rb b/lib/chef/util/dsc/lcm_output_parser.rb index 754fde3e8b..ac847adffa 100644 --- a/lib/chef/util/dsc/lcm_output_parser.rb +++ b/lib/chef/util/dsc/lcm_output_parser.rb @@ -16,9 +16,9 @@ # limitations under the License. # -require 'chef/log' -require 'chef/util/dsc/resource_info' -require 'chef/exceptions' +require "chef/log" +require "chef/util/dsc/resource_info" +require "chef/exceptions" class Chef class Util @@ -109,7 +109,7 @@ class Chef # What If: [machinename]: LCM: [op_action op_type] message # extract op_action, op_type, and message operation, info = match.captures - op_action, op_type = operation.strip.split(' ').map {|m| m.downcase.to_sym} + op_action, op_type = operation.strip.split(" ").map {|m| m.downcase.to_sym} else op_action = op_type = :info if match = line.match(/^.*?:.*?: \s+(.*)/) diff --git a/lib/chef/util/dsc/local_configuration_manager.rb b/lib/chef/util/dsc/local_configuration_manager.rb index f8398341e5..deaa83ef09 100644 --- a/lib/chef/util/dsc/local_configuration_manager.rb +++ b/lib/chef/util/dsc/local_configuration_manager.rb @@ -16,8 +16,8 @@ # limitations under the License. # -require 'chef/util/powershell/cmdlet' -require 'chef/util/dsc/lcm_output_parser' +require "chef/util/powershell/cmdlet" +require "chef/util/dsc/lcm_output_parser" class Chef::Util::DSC class LocalConfigurationManager @@ -47,7 +47,7 @@ class Chef::Util::DSC def run_configuration_cmdlet(configuration_document, apply_configuration, shellout_flags) Chef::Log.debug("DSC: Calling DSC Local Config Manager to #{apply_configuration ? "set" : "test"} configuration document.") - test_only_parameters = ! apply_configuration ? '-whatif; if (! $?) { exit 1 }' : '' + test_only_parameters = ! apply_configuration ? "-whatif; if (! $?) { exit 1 }" : "" start_operation_timing command_code = lcm_command_code(@configuration_path, test_only_parameters) @@ -90,7 +90,7 @@ EOH end def whatif_not_supported?(what_if_exception_output) - !! (what_if_exception_output.gsub(/[\r\n]+/, '').gsub(/\s+/, ' ') =~ /A parameter cannot be found that matches parameter name 'Whatif'/i) + !! (what_if_exception_output.gsub(/[\r\n]+/, "").gsub(/\s+/, " ") =~ /A parameter cannot be found that matches parameter name 'Whatif'/i) end def dsc_module_import_failure?(what_if_output) @@ -105,13 +105,13 @@ EOH Parser::parse(what_if_output) rescue Chef::Exceptions::LCMParser => e Chef::Log::warn("Could not parse LCM output: #{e}") - [Chef::Util::DSC::ResourceInfo.new('Unknown DSC Resources', true, ['Unknown changes because LCM output was not parsable.'])] + [Chef::Util::DSC::ResourceInfo.new("Unknown DSC Resources", true, ["Unknown changes because LCM output was not parsable."])] end end def save_configuration_document(configuration_document) ::FileUtils.mkdir_p(@configuration_path) - ::File.open(configuration_document_path, 'wb') do | file | + ::File.open(configuration_document_path, "wb") do | file | file.write(configuration_document) end end @@ -121,7 +121,7 @@ EOH end def configuration_document_path - File.join(@configuration_path,'..mof') + File.join(@configuration_path,"..mof") end def clear_execution_time diff --git a/lib/chef/util/dsc/resource_store.rb b/lib/chef/util/dsc/resource_store.rb index fdcecc2b3c..761ade9989 100644 --- a/lib/chef/util/dsc/resource_store.rb +++ b/lib/chef/util/dsc/resource_store.rb @@ -16,9 +16,9 @@ # limitations under the License. # -require 'chef/util/powershell/cmdlet' -require 'chef/util/powershell/cmdlet_result' -require 'chef/exceptions' +require "chef/util/powershell/cmdlet" +require "chef/util/powershell/cmdlet_result" +require "chef/exceptions" class Chef class Util @@ -53,7 +53,7 @@ class DSC def add_resource(new_r) count = resources.count do |r| - r['ResourceType'].casecmp(new_r['ResourceType']) == 0 + r["ResourceType"].casecmp(new_r["ResourceType"]) == 0 end if count == 0 resources << new_r @@ -72,9 +72,9 @@ class DSC def find_resources(name, module_name, rs) found = rs.find_all do |r| - name_matches = r['Name'].casecmp(name) == 0 + name_matches = r["Name"].casecmp(name) == 0 if name_matches - module_name == nil || (r['Module'] and r['Module']['Name'].casecmp(module_name) == 0) + module_name == nil || (r["Module"] and r["Module"]["Name"].casecmp(module_name) == 0) else false end @@ -84,7 +84,7 @@ class DSC # Returns a list of dsc resources def query_resources - cmdlet = Chef::Util::Powershell::Cmdlet.new(nil, 'get-dscresource', + cmdlet = Chef::Util::Powershell::Cmdlet.new(nil, "get-dscresource", :object) result = cmdlet.run result.return_value diff --git a/lib/chef/util/file_edit.rb b/lib/chef/util/file_edit.rb index 4d2a9c03eb..d321764a0a 100644 --- a/lib/chef/util/file_edit.rb +++ b/lib/chef/util/file_edit.rb @@ -15,8 +15,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'chef/util/editor' -require 'fileutils' +require "chef/util/editor" +require "fileutils" class Chef class Util @@ -61,7 +61,7 @@ class Chef #search the file line by line and match each line with the given regex #if matched, delete the match (all occurrences) from the line def search_file_delete(regex) - search_file_replace(regex, '') + search_file_replace(regex, "") end #search the file line by line and match each line with the given regex diff --git a/lib/chef/util/path_helper.rb b/lib/chef/util/path_helper.rb index 9ebc9319b8..4a079d3419 100644 --- a/lib/chef/util/path_helper.rb +++ b/lib/chef/util/path_helper.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'chef-config/path_helper' +require "chef-config/path_helper" class Chef class Util diff --git a/lib/chef/util/powershell/cmdlet.rb b/lib/chef/util/powershell/cmdlet.rb index 7eab098c83..6d9bd67afa 100644 --- a/lib/chef/util/powershell/cmdlet.rb +++ b/lib/chef/util/powershell/cmdlet.rb @@ -16,9 +16,9 @@ # limitations under the License. # -require 'mixlib/shellout' -require 'chef/mixin/windows_architecture_helper' -require 'chef/util/powershell/cmdlet_result' +require "mixlib/shellout" +require "chef/mixin/windows_architecture_helper" +require "chef/util/powershell/cmdlet_result" class Chef class Util @@ -48,11 +48,11 @@ class Powershell attr_reader :output_format def run(switches={}, execution_options={}, *arguments) - streams = { :json => CmdletStream.new('json'), - :verbose => CmdletStream.new('verbose'), + streams = { :json => CmdletStream.new("json"), + :verbose => CmdletStream.new("verbose"), } - arguments_string = arguments.join(' ') + arguments_string = arguments.join(" ") switches_string = command_switches_string(switches) @@ -119,7 +119,7 @@ class Powershell validate_switch_name!(switch_name) - switch_argument = '' + switch_argument = "" switch_present = true case switch_value @@ -136,10 +136,10 @@ class Powershell raise ArgumentError, "Invalid argument type `#{switch_value.class}` specified for PowerShell switch `:#{switch_name}`. Arguments to PowerShell must be of type `String`, `Numeric`, `Float`, `FalseClass`, or `TrueClass`" end - switch_present ? ["-#{switch_name.to_s.downcase}", switch_argument].join(' ').strip : '' + switch_present ? ["-#{switch_name.to_s.downcase}", switch_argument].join(" ").strip : "" end - command_switches.join(' ') + command_switches.join(" ") end class CmdletStream @@ -154,8 +154,8 @@ class Powershell def read if File.exist? @filename - File.open(@filename, 'rb:bom|UTF-16LE') do |f| - f.read.encode('UTF-8') + File.open(@filename, "rb:bom|UTF-16LE") do |f| + f.read.encode("UTF-8") end end end diff --git a/lib/chef/util/powershell/cmdlet_result.rb b/lib/chef/util/powershell/cmdlet_result.rb index f1fdd968b1..531636a4ff 100644 --- a/lib/chef/util/powershell/cmdlet_result.rb +++ b/lib/chef/util/powershell/cmdlet_result.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'chef/json_compat' +require "chef/json_compat" class Chef class Util diff --git a/lib/chef/util/powershell/ps_credential.rb b/lib/chef/util/powershell/ps_credential.rb index 2fc0650e5f..660ef32472 100644 --- a/lib/chef/util/powershell/ps_credential.rb +++ b/lib/chef/util/powershell/ps_credential.rb @@ -16,7 +16,7 @@ # limitations under the License. # -require 'chef/win32/crypto' if Chef::Platform.windows? +require "chef/win32/crypto" if Chef::Platform.windows? class Chef::Util::Powershell class PSCredential diff --git a/lib/chef/util/selinux.rb b/lib/chef/util/selinux.rb index 778da042e3..f9fbe82922 100644 --- a/lib/chef/util/selinux.rb +++ b/lib/chef/util/selinux.rb @@ -20,8 +20,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'chef/mixin/shell_out' -require 'chef/mixin/which' +require "chef/mixin/shell_out" +require "chef/mixin/which" class Chef class Util diff --git a/lib/chef/util/threaded_job_queue.rb b/lib/chef/util/threaded_job_queue.rb index 824cd0a3c4..d01ecd81a6 100644 --- a/lib/chef/util/threaded_job_queue.rb +++ b/lib/chef/util/threaded_job_queue.rb @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -require 'thread' +require "thread" class Chef class Util diff --git a/lib/chef/util/windows/net_group.rb b/lib/chef/util/windows/net_group.rb index 2085747eb9..5f6bc6a03b 100644 --- a/lib/chef/util/windows/net_group.rb +++ b/lib/chef/util/windows/net_group.rb @@ -1,85 +1,85 @@ -#
-# Author:: Doug MacEachern (<dougm@vmware.com>)
-# Copyright:: Copyright (c) 2010 VMware, Inc.
-# License:: Apache License, Version 2.0
-#
-# 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/util/windows'
-require 'chef/win32/net'
-
-#wrapper around a subset of the NetGroup* APIs.
-class Chef::Util::Windows::NetGroup
-
- private
-
- def groupname
- @groupname
- end
-
- public
-
- def initialize(groupname)
- @groupname = groupname
- end
-
- def local_get_members
- begin
- Chef::ReservedNames::Win32::NetUser::net_local_group_get_members(nil, groupname)
- rescue Chef::Exceptions::Win32NetAPIError => e
- raise ArgumentError, e.msg
- end
- end
-
- def local_add
- begin
- Chef::ReservedNames::Win32::NetUser::net_local_group_add(nil, groupname)
- rescue Chef::Exceptions::Win32NetAPIError => e
- raise ArgumentError, e.msg
- end
- end
-
- def local_set_members(members)
- begin
- Chef::ReservedNames::Win32::NetUser::net_local_group_set_members(nil, groupname, members)
- rescue Chef::Exceptions::Win32NetAPIError => e
- raise ArgumentError, e.msg
- end
- end
-
- def local_add_members(members)
- begin
- Chef::ReservedNames::Win32::NetUser::net_local_group_add_members(nil, groupname, members)
- rescue Chef::Exceptions::Win32NetAPIError => e
- raise ArgumentError, e.msg
- end
- end
-
- def local_delete_members(members)
- begin
- Chef::ReservedNames::Win32::NetUser::net_local_group_del_members(nil, groupname, members)
- rescue Chef::Exceptions::Win32NetAPIError => e
- raise ArgumentError, e.msg
- end
-
- end
-
- def local_delete
- begin
- Chef::ReservedNames::Win32::NetUser::net_local_group_del(nil, groupname)
- rescue Chef::Exceptions::Win32NetAPIError => e
- raise ArgumentError, e.msg
- end
- end
-end
+# +# Author:: Doug MacEachern (<dougm@vmware.com>) +# Copyright:: Copyright (c) 2010 VMware, Inc. +# License:: Apache License, Version 2.0 +# +# 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/util/windows" +require "chef/win32/net" + +#wrapper around a subset of the NetGroup* APIs. +class Chef::Util::Windows::NetGroup + + private + + def groupname + @groupname + end + + public + + def initialize(groupname) + @groupname = groupname + end + + def local_get_members + begin + Chef::ReservedNames::Win32::NetUser::net_local_group_get_members(nil, groupname) + rescue Chef::Exceptions::Win32NetAPIError => e + raise ArgumentError, e.msg + end + end + + def local_add + begin + Chef::ReservedNames::Win32::NetUser::net_local_group_add(nil, groupname) + rescue Chef::Exceptions::Win32NetAPIError => e + raise ArgumentError, e.msg + end + end + + def local_set_members(members) + begin + Chef::ReservedNames::Win32::NetUser::net_local_group_set_members(nil, groupname, members) + rescue Chef::Exceptions::Win32NetAPIError => e + raise ArgumentError, e.msg + end + end + + def local_add_members(members) + begin + Chef::ReservedNames::Win32::NetUser::net_local_group_add_members(nil, groupname, members) + rescue Chef::Exceptions::Win32NetAPIError => e + raise ArgumentError, e.msg + end + end + + def local_delete_members(members) + begin + Chef::ReservedNames::Win32::NetUser::net_local_group_del_members(nil, groupname, members) + rescue Chef::Exceptions::Win32NetAPIError => e + raise ArgumentError, e.msg + end + + end + + def local_delete + begin + Chef::ReservedNames::Win32::NetUser::net_local_group_del(nil, groupname) + rescue Chef::Exceptions::Win32NetAPIError => e + raise ArgumentError, e.msg + end + end +end diff --git a/lib/chef/util/windows/net_use.rb b/lib/chef/util/windows/net_use.rb index b94576e702..e70df6e42b 100644 --- a/lib/chef/util/windows/net_use.rb +++ b/lib/chef/util/windows/net_use.rb @@ -20,8 +20,8 @@ #see also: WNetAddConnection2 and WNetAddConnection3 #see also cmd.exe: net use /? -require 'chef/util/windows' -require 'chef/win32/net' +require "chef/util/windows" +require "chef/win32/net" class Chef::Util::Windows::NetUse < Chef::Util::Windows def initialize(localname) @@ -53,7 +53,7 @@ class Chef::Util::Windows::NetUse < Chef::Util::Windows def from_use_info_struct(ui2_hash) ui2_hash.inject({}) do |memo, (k,v)| - memo[k.to_s.sub('ui2_', '').to_sym] = v + memo[k.to_s.sub("ui2_", "").to_sym] = v memo end end diff --git a/lib/chef/util/windows/net_user.rb b/lib/chef/util/windows/net_user.rb index 4ce051228a..b8e9b63571 100644 --- a/lib/chef/util/windows/net_user.rb +++ b/lib/chef/util/windows/net_user.rb @@ -16,10 +16,10 @@ # limitations under the License. # -require 'chef/util/windows' -require 'chef/exceptions' -require 'chef/win32/net' -require 'chef/win32/security' +require "chef/util/windows" +require "chef/exceptions" +require "chef/win32/net" +require "chef/win32/security" #wrapper around a subset of the NetUser* APIs. #nothing Chef specific, but not complete enough to be its own gem, so util for now. diff --git a/lib/chef/util/windows/volume.rb b/lib/chef/util/windows/volume.rb index 6e45594ba6..7b24ec37aa 100644 --- a/lib/chef/util/windows/volume.rb +++ b/lib/chef/util/windows/volume.rb @@ -18,8 +18,8 @@ #simple wrapper around Volume APIs. might be possible with WMI, but possibly more complex. -require 'chef/win32/api/file' -require 'chef/util/windows' +require "chef/win32/api/file" +require "chef/util/windows" class Chef::Util::Windows::Volume < Chef::Util::Windows attr_reader :mount_point |